/*Gönderen Mustafa Başaran */
#include
#include
#include
using std::cout;
using std::cin;
using std::endl;
class rasyonel
{
private:
int pay;
int payda;
public:
rasyonel(int a,int b)
{
pay=a;
payda=b;
}
rasyonel()
{
pay=1;
payda=1;
}
void yaz()
{
cout< }
int payoku() { return pay;}
int paydaoku() { return payda;}
void kesiryaz(int a,int b) { pay=a;payda=b;}
};
///////////////////////////////////////////////////
int obeb(int a,int b)
{
int k,ob=1;
if(a k=a;
else
k=b;
for(int i=2;i<=k;i++)
{
if(a%i==0 && b%i==0)
ob=i;
}
return ob;
}
//////////////////////////////////////////////////////////
void sadelestir(rasyonel& x)
{
int a=x.payoku(),b=x.paydaoku(),ob;
ob=obeb(a,b);
a=a/ob;
b=b/ob;
x.kesiryaz(a,b);
}
//////////////////////////////////////////////////////////
void kesiral(rasyonel& x)
{
int a,b;
cin>>a;
cout<<"--\n";
cin>>b;
x.kesiryaz(a,b);
sadelestir(x);
}
/////////////////////////////////////////////////////////////
void paydaesitle(rasyonel& x,rasyonel& y)
{
int a,b;
int okek,k1,k2;
okek=(x.paydaoku()*y.paydaoku())/obeb(x.paydaoku(),y.paydaoku());
k1=okek/x.paydaoku();
k2=okek/y.paydaoku();
a=x.payoku() * k1;
b=y.payoku() * k2;
x.kesiryaz(a,okek);
y.kesiryaz(b,okek);
}
///////////////////////////////////////////////////////////////////////
void topla(rasyonel& x,rasyonel& y,rasyonel& s)
{
int a;
paydaesitle(x,y);
a=x.payoku()+y.payoku();
s.kesiryaz(a,x.paydaoku());
sadelestir(s);
cout<<"toplam=";
s.yaz();
}
///////////////////////////////////////////////////////////////////////
void cikar(rasyonel& x,rasyonel& y,rasyonel& s)
{
int a;
paydaesitle(x,y);
a=x.payoku()-y.payoku();
s.kesiryaz(a,x.paydaoku());
sadelestir(s);
cout<<"fark=";
s.yaz();
}
///////////////////////////////////////////////////////////////////////
void carp(rasyonel& x,rasyonel& y,rasyonel& s)
{
s.kesiryaz(x.payoku()*y.payoku() , x.paydaoku()*y.paydaoku());
sadelestir(s);
cout<<"carpim=";
s.yaz();
}
///////////////////////////////////////////////////////////////////////
void bol(rasyonel& x,rasyonel& y,rasyonel& s)
{
s.kesiryaz(x.payoku()*y.paydaoku() , x.paydaoku()*y.payoku());
sadelestir(s);
cout<<"bolum=";
s.yaz();
}
///////////////////////////////////////////////////////////////////////
int main()
{
int sec;
rasyonel x,y,s;
cout<<"1.kesri girin\n";
kesiral(x);
cout<<"2.kesri girin\n";
kesiral(y);
while(1)
{
cout<<"\n\n\n";
cout<<"[1] toplama\n";
cout<<"[2] cikarma\n";
cout<<"[3] carpma\n";
cout<<"[4] bolme\n";
cout<<"[5] cikis\n";
cout<<"seciminiz";
cin>>sec;
switch(sec)
{
case 1: topla(x,y,s);break;
case 2: cikar(x,y,s);break;
case 3: carp(x,y,s);break;
case 4: bol(x,y,s);break;
case 5: return 0;
}
}
}