You are on page 1of 4

#include<iostream.

h>
#include<conio.h>
#include<math.h>
class fraction
{
private:
int num;
/*
int n_1;
int d_1;
*/
public:
int make_rat(int n,int d);
int numer();
int denom();
};
fraction add_rat(fraction a, fraction b)
{
int n1,n2,d1,d2;
n1=a.numer();
n2=b.numer();
d1=a.denom();
d2=b.denom();
fraction c;
c.make_rat((n1*d2+n2*d1),(d1*d2));
return c;
}
fraction sub_rat(fraction a, fraction b)
{
int n1,n2,d1,d2;
n1=a.numer();
n2=b.numer();
d1=a.denom();
d2=b.denom();
fraction c;
c.make_rat((n1*d2-n2*d1),(d1*d2));
return c;
}
fraction mul_rat(fraction a, fraction b)
{
int n1,n2,d1,d2;
n1=a.numer();
n2=b.numer();
d1=a.denom();
d2=b.denom();
fraction c;
c.make_rat((n1*n2),(d1*d2));
return c;
}
fraction div_rat(fraction a, fraction b)
{
int n1,n2,d1,d2;
n1=a.numer();
n2=b.numer();
d1=a.denom();
d2=b.denom();
fraction c;
c.make_rat((n1*d2),(d1*n2));
return c;
}
void eq_solver()
{
int A[6][2];
cout<<"Give values for first equation"<<endl;
cout<<"\nGive numerator and denomenator respectively of 'a' "<<endl;
cin>>A[0][0]>>A[0][1];
cout<<"\nGive numerator and denomenator respectively of 'b' "<<endl;
cin>>A[1][0]>>A[1][1];
cout<<"\nGive numerator and denomenator respectively of 'c' "<<endl;
cin>>A[2][0]>>A[2][1];
cout<<"\nGive values for second equation"<<endl;
cout<<"\nGive numerator and denomenator respectively of 'd' "<<endl;
cin>>A[3][0]>>A[3][1];
cout<<"\nGive numerator and denomenator respectively of 'e' "<<endl;
cin>>A[4][0]>>A[4][1];
cout<<"\nGive numerator and denomenator respectively of 'f' "<<endl;
cin>>A[5][0]>>A[5][1];
fraction a,b,c,d,e,f;
fraction x,y;
a.make_rat(A[0][0],A[0][1]);
b.make_rat(A[1][0],A[1][1]);
c.make_rat(A[2][0],A[2][1]);
d.make_rat(A[3][0],A[3][1]);
e.make_rat(A[4][0],A[4][1]);
f.make_rat(A[5][0],A[5][1]);
x=div_rat(sub_rat(mul_rat(e,b), mul_rat(b,f)), sub_rat(mul_rat(a,d),mul_rat(b,c)
));
y=div_rat(sub_rat(mul_rat(a,f), mul_rat(e,c)), sub_rat(mul_rat(a,d),mul_rat(b,c)
));
cout<<endl;
cout<<"x = "<<x.numer()<<"/"<<x.denom()<<endl;
cout<<"y = "<<y.numer()<<"/"<<y.denom()<<endl;
}
main()
{
clrscr();

/*fraction a,b;
int x,y;
cout<<"Give values of num and denom of first fraction"<<endl;
cin>>x>>y;
a.make_rat(x,y);
cout<<"Give values of num and denom of second fraction"<<endl;
cin>>x>>y;
b.make_rat(x,y);
cout<<endl;
cout<<"add_rat give result"<<endl;
cout<<add_rat(a,b).numer()<<"/"<<add_rat(a,b).denom();
cout<<endl;
cout<<"sub_rat give result"<<endl;
cout<<sub_rat(a,b).numer()<<"/"<<sub_rat(a,b).denom();
cout<<endl;
cout<<"mul_rat give result"<<endl;
cout<<mul_rat(a,b).numer()<<"/"<<mul_rat(a,b).denom();
cout<<endl;
cout<<"div_rat give result"<<endl;
cout<<div_rat(a,b).numer()<<"/"<<div_rat(a,b).denom();
cout<<endl;
*/
cout<<"EQUATOIN SOLVER: -"<<endl;
eq_solver();
getch();
return 0;
}
int fraction::make_rat(int n, int d)
{
num=pow(2,n)*pow(3,d);
return num;
/*
n_1=n;
d_1=d;
return 0;
*/
}
int fraction::numer()
{
int i=0;
int x;
x=num;
while(x%3==0)
{
x=x/3;
}
while(x!=1)
{
x=x/2;
i++;
}
return i;
/*
return n_1;
*/
}
int fraction::denom()
{
int i=0;
int x;
x=num;
while(x%2==0)
{
x=x/2;
}
while(x!=1)
{
x=x/3;
i++;
}
return i;
/*
return d_1;
*/
}