a.) Adding two Rational numbers. The result should be stored in reduced form.
b.) Subtracting two Rational numbers. The result should be stored in reduced form.
c.) Multiplying two Rational numbers. The result should be stored in reduced form.
d.) Dividing two Rational numbers. The result should be stored in reduced form.
e.) Printing Rational numbers in form a/b, where a is the numerator and b is the denominator.
P.S. :
Note :
This problem involves three files.
main.cpp
#include <iostream>
#include "function.h" // include definition of class Rational
using namespace std;
int main()
{
char s1;
int s2, s3, s4, s5;
Rational x;
while(cin >>s1>>s2>>s3>>s4>>s5)
{
if(cin.eof())
{
break;
}
Rational c(s2, s3), d(s4, s5);
if(s1 == '+')
{
x = c.addition( d ); // adds object c and d; sets the value to x
x.printRational(); // prints rational object x
cout << '\n';
}
else if(s1 == '-')
{
x = c.subtraction( d ); // subtracts object c and d
x.printRational(); // prints rational object x
cout << '\n';
}
else if(s1 == '*')
{
x = c.multiplication( d ); // multiplies object c and d
x.printRational(); // prints rational object x
cout << '\n';
}
else if(s1 == '/')
{
x = c.division( d ); // divides object c and d
x.printRational(); // prints rational object x
cout << '\n';
}
}
} // end main
function.h
There are five strings in each line: S1 S2 S3 S4 S5
Input terminated by EOF.
For every given operation, your program should print the corresponding result followed by a new line character.