You are on page 1of 2

Rational Number 2

============================================

#include <iostream.h>

class Rational{
public:
Rational(){}
Rational(int nom, int dom)
{
this->nom=nom;
this->dom=dom;
}
void setNom(int nom){this->nom=nom;}
int getNom(){return nom;}

void setDom(int dom){this->dom=dom;}


int getDom(){return dom;}

Rational operator+(Rational p)
{
nom=(nom*p.dom)+(p.nom*dom);
dom=dom*p.dom;
return *this;
}

bool operator==(Rational p){


if(nom && dom == p.nom && p.dom)
return true;
else
return false;
}

void printReduced()
{
int small=nom;
if(dom<small)
small=dom;
int i;
for(i=small;i>=1;i--){
if(nom%i==0 && dom%i==0)
break;
}
cout<<"Result = ("<<nom/i<<"/"<<dom/i<<")";
}

private:
int nom;
int dom;
};

void main(){

Rational a(1,1),b(1,1),c;
c=a+b;
c.printReduced();
if(a==b)
cout<<"\nEqual";
else
cout<<"\nNot Equal";

cout<<endl<<endl;
}

http://www.ravianeducation.blogspot.com
FARHAN: 03008855006