473,386 Members | 1,753 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Adding two fractions

Lets say I have the following class in order to add two fractions,

class Fraction{
public:
Fractions::Fraction(int numer = 0, int denom = 1)
{
valeurNumerateur = numer;
valeurDenominateur = denom;
}

Rationnel Addition(const Fraction&) const;

private:

int num; //numerator
int den; //denominator

};

Fraction Fraction::Addition(const Fraction &Frac) const
{

Frac temp;
temp.den = den * Frac.den
temp.num = Frac.num * num +
den * Ration.num;
return temp;

}

Fraction operator+(const Fraction &Frac1, const Fraction &Frac1)
{
Fraction Result;
return Result.Addition(Frac1) + Result.Addition(Frac1)
}

int main()
{

Fraction a(2,3);

Fraction b(4,5);

Fraction c;

c = a + b;
cout << c;

return 0;
};

Input/output overloading works great (that is why it was not included in
this code) however when I try to overload addition with this structure all I
get is segmentation fault without any other errors. I need to use Fraction
operator+(const Fraction &Frac1, const Fraction &Frac1) as some sort of
interface to the actual Rationnel Addition(const Fraction&) const; which
does the work within my class. Parameters or structure may not be modified,
I was able to do it with a single overloading function but with this
structure it simply wont run....any help/tips would be much appreciated.


Jul 22 '05 #1
2 9219
"karp" <ss**@fake.net> wrote in message news:3fbeec5e$1_2@aeinews....
I was able to do it with a single overloading function but with this
structure it simply wont run....any help/tips would be much appreciated.


"Won't run" tells us nothing.

Post the real code that fails.

-Mike
Jul 22 '05 #2
"karp" <ss**@fake.net> wrote in message news:3fbeec5e$1_2@aeinews....
Lets say I have the following class in order to add two fractions,

class Fraction{
public: <<snip>> Fraction Fraction::Addition(const Fraction &Frac) const
{

Frac temp;

Wrong type.

<<snip>>
--
Gary
Jul 22 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

10
by: sp0 | last post by:
Is there a reason why to make mix numbers improper when adding? It seems when subtracting and adding, adding a subtracting the whole numbers and fraction parts should be sufficient? what'ch think
5
by: surrealtrauma | last post by:
the requirement is : Create a class called Rational (rational.h) for performing arithmetic with fractions. Write a program to test your class. Use Integer variables to represent the private data...
33
by: selowitch | last post by:
I've been searching in vain for a way to present typographically correct fractions (not resorting to <sup> and <sub> tags) but have been frustrated by the fact that the glyphs for one-half,...
5
by: Steffen | last post by:
Hi, is it possible to have two fractions, which (mathematically) have the order a/b < c/d (a,b,c,d integers), but when (correctly) converted into floating point representation just have the...
2
by: Mori | last post by:
Hi, Can someone supply a code example of displaying a string with a fractional part, say 5 and 7 16ths. I cannot find an example of how to use the Encoding object (if that is what you use). ...
4
by: Bob | last post by:
Hi All, Was wondering if in C# there is an elegant way of displaying and or calculating fractions. The case: we have an app that measures/slices dices etc and all our internal measures and...
1
by: Semajthewise | last post by:
Here it is cleaned up a little more. Here's what this code does. It will take 2 fractions and add, subtract, multiply, or divide them. The user enters the fractions to be calculated into two...
0
by: Paddy | last post by:
(From: http://paddy3118.blogspot.com/2008/09/python-fractions-issue.html) There seems to be a problem/difference in calculating with the new fractions module when comparing Python 26rc2 and 30rc1...
1
by: 1337kamikaze | last post by:
I can't get the common denominator to work. Please help. import java.util.*; import java.lang.*; public class Fraction { /** * @param args
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.