Question: C++ Object Oriented Programming Overload the following 12 operators: + - * / < > = = ! = = >> < < In order
C++ Object Oriented Programming
Overload the following 12 operators:
+ - * / < > = = ! = <= >= >> <<
In order to test your class in your main function, prompt the user for a numerator and a denominator for your first object. Repeat the prompt for the second object. Perform all mathematical operations and comparisons using your overloaded operators. Print the two Rational numbers using your new overloaded operator <<. Then print the result of all the calculations using your overloaded operators. Make sure you label your output, for instance:
Your first rational number is: 3/2. Your second number is 5/2. 5/2 + 3/2 = 4/1 (using + operator) ................................................
5/2 > 3/2 is true. (using > operator) 5/2 < 3/2 is false. (using < operator) ................................................
Output the rest of the results the same way. You should have 12 lines displaying the results; 2 to output the numbers and 10 to display the results of using the overloaded operators.
Note that in the above example 3/2 + 5/2 = 8/2. Your class stores the fraction in the reduced form, 4/1.
All the work must be done inside the class. The client (main function) should only use the member or the friend functions of the objects. Do not perform any calculation or comparison in the main function.
Create two friend functions for overloading insertion and extraction operators. The rest of the functions must be member functions. Use the following example to create the member functions.
Function definition: passing a Rational object to the member function of another.
Rational Rational :: operator* (const Rational &num) const {
Rational temp; temp.numerator = numerator*num.numerator; temp.denominator = denominator*num.denominator; //call the helper function to reduce the fraction temp.simplify( ); return temp;
}
In your main function:
Rational num1, num2, result;
//get values from the user for num1
cin>>num1;
//more codes here
result = num1 + num2 ;
//label all your outputs properly
cout< As usual, add all necessary comments. Run your program with several test data. Capture the screen image and save it. Test, and test, and test! Make sure you test all possible cases, including a zero as the denominator.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
