#include<iostream>
using namespace std;
class Rational{
private:
double numerator;
double denominator;
public:
Rational(int num,int den){
numerator = num;
denominator = den;
}
double getNumber(){
return numerator / denominator;
}
friend double addRational(Rational r1, Rational r2);
friend double mulRational(Rational r1, Rational r2);
};
double addRational(Rational r1, Rational r2){
return r1.getNumber() + r2.getNumber();
}
double mulRational(Rational r1, Rational r2){
return r1.getNumber()* r2.getNumber();
}
int main(){
Rational r4(8,6);
cout<<r4.getNumber()<<endl;
double first_numerator, first_denominator, second_numerator,second_denominator;
cout<<"Enter the first rational number\n";
cout<<"Enter the numerator\t"<<endl;
cin>>first_numerator;
cout<<"Enter the denominator\t"<<endl;
cin>>first_denominator;
cout<<"Enter the second rational number\n";
cout<<"Enter the numerator\t"<<endl;
cin>>second_numerator;
cout<<"Enter the denominator\t"<<endl;
cin>>second_denominator;
Rational r1(first_numerator,first_denominator);
Rational r2(second_numerator,second_denominator);
cout<<"The addition of the rational numbers are \t"<<addRational(r1, r2)<<endl;
cout<<"The multiplication of the rational numbers are \t"<<mulRational(r1, r2)<<endl;
}
Comments
Leave a comment