//Class Bölümü fractions.h
#ifndef FRACTIONS_H
#define FRACTIONS_H
class fractions
{
public:
fractions(int,int);
bool operator<( fractions &);//
bool operator>( fractions &);//
bool operator<=( fractions &);//
bool operator>=( fractions &);
bool operator==( fractions &);//
bool operator!=( fractions &);//
fractions &operator+( fractions &);
fractions &operator-( fractions &);
fractions &operator*( fractions &);
fractions &operator/( fractions &);
//void print();
private:
int pay;
int payda;
};
#endif
//Fonksiyonların tanımlanması
#include<iostream>
using namespace std;
#include"fractions.h"
fractions::fractions(int a,int b)
{
pay=a;
payda=b;
}
fractions &fractions::operator+( fractions &object)
{
pay=((pay*object.payda)+(object.pay*payda));
payda=payda*object.payda;
return *this;
}
fractions &fractions::operator -(fractions &object)
{
pay=((pay*object.payda)-(object.pay*payda));
payda=payda*object.payda;
return *this;
}
fractions &fractions::operator *(fractions &object)
{
pay=pay*object.pay;
payda=payda*object.payda;
return *this;
}
fractions &fractions::operator /(fractions &a)
{
pay=pay*a.payda;
payda=payda*a.payda;
return *this;
}
bool fractions::operator <(fractions &a)
{
if(pay*a.payda<payda*a.pay)
return true;
else
return false;
}
bool fractions::operator >(fractions &a)
{
if(pay*a.payda>payda*a.pay)
return true;
else
return false;
}
bool fractions::operator !=(fractions &a)
{
if(pay/payda!=a.pay/a.payda)
return true;
else
return false;
}
bool fractions::operator <=(fractions &a)
{
if(pay/payda<=a.pay/a.payda)
return true;
else
return false;
}
bool fractions::operator ==(fractions &a)
{
double b,c;
b=pay/payda;
c=a.pay/a.payda;
if(b==c)
return true;
else
return false;
}
bool fractions::operator >=(fractions &a)
{
if(pay/payda>=a.pay*a.payda)
return true;
else
return false;
}
//Main kısmı
#include<iostream>
using namespace std;
#include"fractions.h"
int main()
{
fractions a(1,4),b(3,4);
cout<<"a = 1/4 b = 3/4 "<<endl;
if(a<b)
cout<<"a<b"<<endl;
if (a>b)
cout<<"a>b"<<endl;
if(a<=b)
cout<<"a<=b"<<endl;
if(a>=b)
cout<<"a>=b"<<endl;
if(a==b)
cout<<"a=b"<<endl;
if(a!=b)
cout<<"a!=b"<<endl;
return 0;
}