Adding two fractions



 DEVELOP > c-Plus-Plus > Adding two fractions

LINK TO THIS PAGE  


rating :  0   |  0


  Page 1 of 1

1

 
Topic: DEVELOP > c-Plus-Plus
User: "karp"
Date: 21 Nov 2003 10:54:36 PM
Object: 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.
.

User: "Mike Wahler"

Title: Re: Adding two fractions 21 Nov 2003 10:58:50 PM
"karp" <ssss@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
.

User: "Gary Labowitz"

Title: Re: Adding two fractions 22 Nov 2003 12:47:18 AM
"karp" <ssss@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
.


  Page 1 of 1

1

 


Related Articles
 

NEWER

pg.1232     pg.940     pg.716     pg.544     pg.412     pg.311     pg.234     pg.175     pg.130     pg.96     pg.70     pg.50     pg.35     pg.24     pg.16     pg.10     pg.6     pg.3     pg.1

OLDER