Use C only Please include comments and pre post conditions I

Use C++ only
Please include comments and pre/ post conditions
I am also using a new editor called code lite
15 object in the class should have two integer values that define the rational number: the numerator and the denominator. For example, the fraction, 5/6 would have a denominator of 5 and a nu- merator of 6. Include a constructor with two argu- ments that can be used to set the numerator and

Solution

#include<stdio.h>   
#include<iostream>
using namespace std;
class rational
{
   int numer;
   int denom;
   public:
   void getdata()
   {
       cout<<\"\ Enter the numerator part of the rational no.\";
       cin>>numer;
       cout<<\"\ Enter the denominator part of the rational no.\";
       cin>>denom;
   }
   void operator+(rational);
   void operator-(rational);
   void operator *(rational);
   void operator /(rational);
};
void rational ::operator+(rational c1)
{
   rational temp;
   temp.numer=(numer*c1.denom)+(c1.numer*denom);
   temp.denom=denom*c1.denom;
   cout<<\"\ rational no. after addition\";
   cout<<\"\ numerator=\"<<temp.numer<<\"\ denominator =\"<<temp.denom;
}
void rational ::operator -(rational c1)
{
   rational temp;
   temp.numer=(numer*c1.denom)-(c1.numer*denom);
   temp.denom=denom*c1.denom;
   cout<<\"\ rational no. after subtraction\";
   cout<<\"\ numerator=\"<<temp.numer<<\"\ denominator =\"<<temp.denom;
}
void rational ::operator *(rational c1)
{
   rational temp;
   temp.numer=numer*c1.numer;
   temp.denom=denom*c1.denom;
   cout<<\"\ rational no. after multiplication\";
   cout <<\"\ numerator=\"<<temp.numer<<\"\ denominator =\"<< temp.denom;
}
void rational :: operator /(rational c1)
{
   rational temp;
   temp.numer= numer*c1.denom;
   temp.denom=c1.numer*denom;
   cout<<\"\ rational no. after dividation\";
   cout <<\"\ numerator=\"<<temp.numer<<\"\ denominator =\"<<temp.denom;
}
int main()
{
   rational c1, c2;
   int n;
   do
   {
       cout<<\"\ 1. Enter data for rational no. \";
       cout<<\"\ 2. Addition\";
       cout<<\"\ 3. Subtraction\";
       cout<<\"\ 4. Multiplication\";
       cout<<\"\ 5. Division\";
       cout<<\"\ 6. Quit\";
       cout<<\"\ Enter your choice\";
       cin>>n;
       switch(n)
       {
           case 1:
           cout<<endl<<\"\ Enter the data for first rational no.\";
           c1.getdata();
           cout<<endl<<\"\ Enter the data for second rational no. \";
           c2.getdata ();
           break;
           case 2:
           c1+c2;
           break;
           case 3:
           c1-c2;
           case 4:
           c1*c2;
           break;
           case 5:
           c1/c2;
           break;
           case 6:
           break;
       }
   } while (n!=6);
}

Use C++ only Please include comments and pre/ post conditions I am also using a new editor called code lite 15 object in the class should have two integer value
Use C++ only Please include comments and pre/ post conditions I am also using a new editor called code lite 15 object in the class should have two integer value

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site