You are on page 1of 2

Rational Number Class

============================================
#include <iostream.h>

class rational{
public:

rational()
{
nurminator=0;
denominator=0;
}

rational(int n, int d)
{
nurminator=n;
denominator=d;
}

void setNurminator(int n)
{
nurminator=n;
}

void setDenominator(int d)
{
denominator=d;
}

int getNurminator()
{
return nurminator;
}

int getDenominator()
{
return denominator;
}

rational Multiplication(rational p)
{
p.setNurminator(nurminator*p.getNurminator());
p.setDenominator(denominator*p.getDenominator());
return p;
}

void Print()
{
int res1,res2;

res1=nurminator/nurminator;
res2=denominator/nurminator;

if(denominator>nurminator)

cout<<"("<<res1<<"/"<<res2<<")"<<endl<<endl;
else

cout<<"("<<res2<<"/"<<res1<<")"<<endl<<endl;

private:

int nurminator;
int denominator;
};

void main()
{
rational c1(2,4);
rational c2(1,6);
rational res;

res=c1.Multiplication(c2);
cout<<"Multiplication = ";
res.Print();

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