Here's my code so far. I am having trouble with compilation errors. I need to separate this into a Fraction.h and a Fraction.cpp
class Fraction{
public:
Fraction()
: num(0), den(1) {};
: num(n), den(d) {};
int getNum() const {
return num;
}
int getDen() const {
return den;
}
void setNum(int n){
num = n;
}
void setDen(int d){
den = d;
}
//overload the stream insertion and extraction operators.
friend ostream& operator <<(ostream&, const Fraction &);
friend istream& operator >> (istream&, Fraction &);
// overload the arithmetic operators
Fraction operator+( const Fraction & );
Fraction operator-( const Fraction & );
private:
int num;
int den;
};
( const Fraction & rightFraction )
{
Fraction temp;
temp.den = den * rightFraction.den;
} // end function operator+
{
Fraction temp;
temp.den = den * rightFraction.den;
} // end function operator-
ostream& operator<<( ostream& osObject,
const Fraction & myFraction )
{
osObject << myFraction.num << "/" << myFraction.den;
return osObject;
} // end function operator<<
istream& operator>>( istream& isObject, Fraction & myFraction)
{
char ch;
cout<<"Enter numerator:";
isObject >> myFraction.num;
cout<<"Enter denomerator:";
isObject>> myFraction.den;
return isObject;
}
Fraction( int n, int d)
Fraction Fraction ::operator+
temp.num = ( num * rightFraction.den ) + ( den * rightFraction.num );
return temp;
Fraction Fraction ::operator-( const Fraction & rightFraction )
temp.num = ( num * rightFraction.den ) - ( den * rightFraction.num );
return temp;
// Overlod the stream extraction operator <<
// Overload the stream extraction operator >>
Get Free Quote!
369 Experts Online