Ask Question

Name:
Title:
Your Question:

Answer Question

Name:
Your Answer:
User Submitted Source Code!


Description:
  rational.cpp
Language: C/C++
Code:
#include<iostream.h>
class rational
{
private: int num,den;
public:
void get();
rational operator +(rational);
void operator =(int);
rational() { num=0; den=0; }
};
void rational::get()
{
cout<<"Enter num &den:";
cin>>num>>den;
}
rational::rational operator +(rational r2)
{
rational r3;
r3.num= (this->num*r2.den)+(this->den*r2.num);
r3.den= this->den*r2.den;
cout<<r3.num<<"/"<<r3.den;
return r3;
}
main()
{
rational r1,r2,r3;
r1.get();
r2.get();
r3=r1.operator+(r2);
}
Comments: