I want to Modify the four-function fraction calculator of this code

to use a fraction class rather than a structure. there should be member functions for input and output, as well as for the four arithmetical operations.while you 're at it,you might as well install the capability to reduce fractions to lowest terms.here's a member function that will reduce the fraction object of which it is a member to lowest terms. it finds the greatest common divisor (gcd) of the fraction's numerator and denominator, and uses this gcd to divide both numbers.Code:# include<iostream> using namespace std; struct fraction { int a; int b; int e; int f; }; fraction fadd (fraction,fraction); fraction fsub (fraction,fraction); fraction fmul (fraction,fraction); fraction fdiv (fraction,fraction); int main() { fraction g1,g2; fraction total; char op,slash,val; do { cout<<"Enter First Fraction:"; cin>>g1.a>>slash>>g1.b; cout<<"\nEnter an operator:"; cin>>op; cout<<"\nEnter Second fraction:"; cin>>g2.a>>slash>>g2.b; switch (op) { case '+': total= fadd(g1,g2); break; case '-': total= fsub(g1,g2); break; case '*': total= fmul(g1,g2); break; case '/': total= fdiv(g1,g2); break; default: cout<<"invalid operator."; } cout<<"Answer="<<total.e<<"/"<<total.f<<endl; cout<<"\nwould you like to continue(Enter'y'or'n')?"; cin>>val; } while(val!='n'); return 0; } fraction fadd (fraction g1,fraction g2) {fraction total; total.e =(g1.a*g2.b+g1.b*g2.a); total.f=(g1.b*g2.b); return total;} fraction fsub (fraction g1,fraction g2) { fraction total; total.e=(g1.a*g2.b-g1.b*g2.a); total.f=(g1.b*g2.b); return total;} fraction fmul (fraction g1,fraction g2) {fraction total; total.e=(g1.a*g2.a); total.f=(g1.b*g2.b); return total;} fraction fdiv (fraction g1,fraction g2) {fraction total; total.e=(g1.a*g2.a); total.f=(g1.b*g2.b); return total;}

I can call this function at the end of each arithmetic function,or just before you perfprm output. I 'll also need the usual member functions:four arithmetic operations, input,and display .I also need to find a two-argument constructor useful.Code:void fraction::lowterms() //change ourself to lowest terms { long tnum ,tden, temp, gcd; tnum = labs(num); //use non-negative copies tden = labs(den); //(needs cmath) if (tden==0) //check for n/0 {cout<<"illegal fraction:division by 0";exit(1);} else if ( tnum==0) //check for 0/n {num=0;den=1;return;} // this 'while' loop finds the gcd of tnum and tden while(tnum !=0) { if(tnum<tden) //ensure numerator larger { temp=tnum;tnum=tden;tfen=temp;} //swap them tnum = tnum-tden; // subtract them } gcd=tden; // this is grestest common divisor num=num/gcd; //divide both num and den by gcd den=den/gcd; //to reduce frac to lowest terms }

thank you

( this is the right one !!)