#include<iostream>
using namespace std;
class a
{
int i,n,d,sn,sd,cond;
public:
void getdata()
{
cout<<"Enter the numerator"<<endl;
cin>>n;
cout<<"Enter the denominator"<<endl;
cin>>d;
}
void operator+(a a1)
{
if(a1.d!=d)
{
sn=(a1.n*d)+(n*a1.d);
sd=(a1.d)*(d);
}
else
{
sn=a1.n+n;
sd=a1.d;
}
if(sn>sd)
{
cond=sd;
}
else if(sd>sn)
{
cond=sn;
}
}
void sum()
{
for(i=2;i<=cond;i++)
{
if(sn%i==0 && sd%i==0)
{
sn=sn/i;
sd=sd/i;
}
}
cout<<"Sum is "<<sn<<"/"<<sd<<endl;
}
a operator-(a a1)
{
a a3;
if(a1.d!=d)
{
a3.sn=(a1.n*d)-(n*a1.d);
a3.sd=(a1.d)*(d);
}
else
{
a3.sn=a1.n-n;
a3.sd=a1.d;
}
return a3;
}
void sub()
{
if(sn>sd)
{
cond=sd;
}
else if(sd>sn)
{
cond=sn;
}
for(i=2;i<=cond;i++)
{
if(sn%i==0 && sd%i==0)
{
sn=sn/i;
sd=sd/i;
}
}
cout<<"Subtraction is "<<sn<<"/"<<sd<<endl;
}
a operator /(a a1)
{
a a4;
a4.sn=a1.n*d;
a4.sd=a1.d*n;
return a4;
}
void div()
{
if(sn>sd)
{
cond=sd;
}
else if(sd>sn)
{
cond=sn;
}
else if(sn==sd)
{
sn=1;
sd=1;
}
for(i=2;i<=cond;i++)
{
if(sn%i==0 && sd%i==0)
{
sn=sn/i;
sd=sd/i;
}
}
cout<<"Division is "<<sn<<"/"<<sd<<endl;
}
a operator*(a a1)
{
a a5;
a5.sn=a1.n*n;
a5.sd=a1.d*d;
return a5;
}
void mul()
{
if(sn>sd)
{
cond=sd;
}
else if(sd>sn)
{
cond=sn;
}
for(i=2;i<=cond;i++)
{
if(sn%i==0 && sd%i==0)
{
sn=sn/i;
sd=sd/i;
}
}
cout<<"Multiplication - "<<sn<<"/"<<sd<<endl;
}
};
int main()
{
a a1,a2,a3,a4,a5,a6;
a1.getdata();
a2.getdata();
a2+(a1);
a2.sum();
a3=a2-(a1);
a3.sub();
a4=a2/(a1);
a4.div();
a5=a2*(a1);
a5.mul();
return 0;
}
using namespace std;
class a
{
int i,n,d,sn,sd,cond;
public:
void getdata()
{
cout<<"Enter the numerator"<<endl;
cin>>n;
cout<<"Enter the denominator"<<endl;
cin>>d;
}
void operator+(a a1)
{
if(a1.d!=d)
{
sn=(a1.n*d)+(n*a1.d);
sd=(a1.d)*(d);
}
else
{
sn=a1.n+n;
sd=a1.d;
}
if(sn>sd)
{
cond=sd;
}
else if(sd>sn)
{
cond=sn;
}
}
void sum()
{
for(i=2;i<=cond;i++)
{
if(sn%i==0 && sd%i==0)
{
sn=sn/i;
sd=sd/i;
}
}
cout<<"Sum is "<<sn<<"/"<<sd<<endl;
}
a operator-(a a1)
{
a a3;
if(a1.d!=d)
{
a3.sn=(a1.n*d)-(n*a1.d);
a3.sd=(a1.d)*(d);
}
else
{
a3.sn=a1.n-n;
a3.sd=a1.d;
}
return a3;
}
void sub()
{
if(sn>sd)
{
cond=sd;
}
else if(sd>sn)
{
cond=sn;
}
for(i=2;i<=cond;i++)
{
if(sn%i==0 && sd%i==0)
{
sn=sn/i;
sd=sd/i;
}
}
cout<<"Subtraction is "<<sn<<"/"<<sd<<endl;
}
a operator /(a a1)
{
a a4;
a4.sn=a1.n*d;
a4.sd=a1.d*n;
return a4;
}
void div()
{
if(sn>sd)
{
cond=sd;
}
else if(sd>sn)
{
cond=sn;
}
else if(sn==sd)
{
sn=1;
sd=1;
}
for(i=2;i<=cond;i++)
{
if(sn%i==0 && sd%i==0)
{
sn=sn/i;
sd=sd/i;
}
}
cout<<"Division is "<<sn<<"/"<<sd<<endl;
}
a operator*(a a1)
{
a a5;
a5.sn=a1.n*n;
a5.sd=a1.d*d;
return a5;
}
void mul()
{
if(sn>sd)
{
cond=sd;
}
else if(sd>sn)
{
cond=sn;
}
for(i=2;i<=cond;i++)
{
if(sn%i==0 && sd%i==0)
{
sn=sn/i;
sd=sd/i;
}
}
cout<<"Multiplication - "<<sn<<"/"<<sd<<endl;
}
};
int main()
{
a a1,a2,a3,a4,a5,a6;
a1.getdata();
a2.getdata();
a2+(a1);
a2.sum();
a3=a2-(a1);
a3.sub();
a4=a2/(a1);
a4.div();
a5=a2*(a1);
a5.mul();
return 0;
}
#include
ReplyDeleteusing namespace std;
class Ral
{
int den,num;
public:
void set(int d, int n)
{
den = d;
num= n;
}
Ral operator+(Ral R) {
Ral temp;
temp.den = den + R.den;
temp.num = num+ R.num;
return temp;
}
Ral operator*(Ral R) {
Ral temp;
temp.den = den* R.den;
temp.num = num * R.num;
return temp;
}
Ral operator-(Ral C) {
Ral temp;
temp.den = den - C.den;
temp.num = num - C.num;
return temp;
}
void show() {
cout << "a=" << num << endl;
cout<<"b=" << den << endl;
}
void Exit() {
cout << "BYE"<> choice;
switch (choice)
{
case 1:
if (choice == 1)
{
c3 = c1 + c2;
cout << "for addition:" << endl;
c3.show();
break;
}
case 2:
if (choice == 2)
{
c4 = c1 * c2;
cout << "for multiplication:" << endl;
c4.show();
break;
}
case 3:
if (choice == 3)
{
c5 = c1 - c2;
cout << "for subtraction" << endl;
c5.show();
break;
}
case 4:
if (choice == 4)
{
c1.Exit();
break;
}
}
system("pause");
return 0;
}