Teemmy Ellorry · February 20, 2015 Design and code a class named Fraction that holds information about a rational number.  Place your class definition and implementation in a file named Fraction.h (so there is no file Fraction.cpp).You can include the Fraction class in the file main.cpp. You can see that it is not always necessary to include your application in separate files.  Upon instantiation, a Fraction may receive two integer values holding the numerator and denominator of the rational number.  If the object receives no values, it set numerator = 0 and denominator = 1.   Your class includes the following data members and member functions:  private:   int n,d; //numerator and the denominator   bool reduction(); // reduct the fraction and return true if real reduction appeared  public:   Fraction(int p=0, int q=1) {n=p;d=q;} //constructor   friend istream & operator>>(istream &is, Fraction &a); // Input fraction a   friend ostream & operator<<(ostream &os, const Fraction &a); // display fraction   double getValue(); //return value   void display(); // display fraction with reduction and value    Fraction operator+(Fraction b); // overload + operator   Fraction operator-(Fraction b);   Fraction operator*(Fraction b);   Fraction operator/(Fraction b);   bool operator==(Fraction b);   bool operator!=(Fraction b);   bool operator>(Fraction b);   bool operator>=(Fraction b);   bool operator<(Fraction b);   bool operator<=(Fraction b); The main program that tests the Fraction class is: //=========================================#include "Fraction.h"int main()  { Fraction a, b, c;    int choice;     while(true)       { system("CLS");         cout< b "<= b "<>choice;         if(choice==0)             {cout<<"Have a nice day!"<>a;break;              case  2: cout<<"a = ";a.display();break;              case  3: cin>>b;break;              case  4: c = a+b;                           cout< "<=b)                            cout<= "< "<

## Replies

 Teemmy Ellorry · February 20, 2015 #include using namespace std;class Fraction{ private:  int n, d, c;  bool reduction()  {   for(int k=1; k<=n && k <= d; k++) { if(n % k == 0 && d % k == 0)   //Finding the greatest common divisor    {    c = k;      } }   return true;  }  public:   int p, q,num;   Fraction(int p=0, int q=1)  {     n=p;d=q;                     //constructor  }        friend istream & operator>>(istream &is, Fraction &a) { cout<<"Enter Numerator: "; cin>>a.p; cout<<"Enter Denominator: "; cin>>a.q; return is>>a.num;                // Input fraction a }              friend ostream & operator<<(ostream &os, const Fraction &a) { return os<(Fraction b)        {        }        bool operator>=(Fraction b)        {        }        bool operator<(Fraction b)        {        }        bool operator<=(Fraction b)        {        }};int main(){ Fraction a, b, c;    int choice;     while(true)       { system("CLS");         cout< b "<= b "<>choice;         if(choice==0)             {   cout<<"Have a nice day!"<>a;  break;              case  2: cout<<"a = ";a.display();break;              case  3: cin>>b;break;              case  4: c = a+b;                           cout< "<=b)                            cout<= "< "<
• 1

## C++

124,678 followers