C help Modify the Rational class to include the following op


C++ help

Modify the Rational class to include the following operators: >> read in num and denom values for an object

Solution

#include<stdio.h>
#include<iostream.h>
#include<conio.h>
class rational
{
int numer;
int denom;
public:
//method to enter the numbers
void getdata()
{
   cout<<\"\ enter the numerator of the rational no.\";
   cin>>numer;
   cout<<\"\ enter the denominator of the rational no.\";
   cin>>denom;
}
//method to display the rational numbers
         void dispaly()
        {
          cout<<\"the numerator =\"<<num<<\"and denomenator =\"<<den;
        
          }
//method to multiply the rational numbers
         rational multiply(rational c2)
          {
            rational temp;
            temp.numer=c1.numer*c2.numer;
            temp.denom=c1.denom*c2.denom;
            return temp;
           }
//method to add the rational number by 1
rational add()
          {
           rational temp;
    temp.numer=(1*c1.denom)+(c1.numer*denom);
    temp.denom=c1.denom;
           return temp;
          }

};

void main()
{
clrscr();
rational c1, c2,c3,c4;
int n;

    cout<<endl<<\"\ enter the data for first rational no.\";
    c1.getdata();
      c1.display();
    cout<<endl<<\"\ enter the data for second rational no. \";
    c2.getdata ();
    c2.display();
                  
    c3=c1.multiply(c2);
    c4=c1.multiply();
                         cout<<endl<<\"\ product of numbers is\"<<c3.numer<<\"/\"<<c3.denom;
                         cout<<endl<<\"\ product of numbers is\"<<c4.numer<<\"/\"<<c4.denom
getch();
}

 C++ help Modify the Rational class to include the following operators: >> read in num and denom values for an object Solution#include<stdio.h> #inc
 C++ help Modify the Rational class to include the following operators: >> read in num and denom values for an object Solution#include<stdio.h> #inc

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site