1 Introduction Consider the following C++ class declaration: class Fraction { pr
ID: 3611587 • Letter: 1
Question
1 IntroductionConsider the following C++ class declaration:
class Fraction
{ private :
int num; // the fraction’s numerator .
int den ; // the fraction’s denominator .
public :
void pr int ( ) ; // prints num/den .
void read ( ) ; // enter num/den from standard input .
Fraction ( ) ; // default ctor , ”empty” fraction .
Fraction ( int n , int d ) ; //a function to build a
// fraction n/d .
};
2 Problem
Create a class Fraction using the above declaration. Store thedeclaration in a file
called fraction.h. Create an implementation file calledfraction.cc. Implement all the
member functions listed above and store your definitions infractions.cc. In addition, add
(design and implement) to class Fraction member functions thatperform the following
operations on Fractions:
1. Convert a Fraction to a decimal.
2. Convert an integer to a Fraction.
3. Add two Fractions together.
1
Explanation / Answer
please rate - thanks should get you started #include #include #include #include class Rational {public: void Inputc(); void Outputc(); Rational operator+(Rational x); Rational operator-(Rational x); Rational operator*(Rational x); Rational operator/(Rational x); int Rational:: gcd(Rational x); void Rational::reduce(Rational& x); private: int num,den; }; Rational Rational::operator + (Rational x) {Rational temp; temp.num=num+x.num; temp.den=x.den; //coutRelated Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.