Skip to content

CS 1415 - Lab #9

Objectives:

Overload Operators for a Class

Preparation:

Review Chapter 14 from Starting Out with C++ by Gaddis 

Assignment:
  1. Name your source files LlllFfffRational.h, LlllFfffRational.cpp, and LlllFfffLab09.cpp where Llll is the first four letters of your last name and Ffff is the first four letters of your first name.
  2. Create an updated Rational class that uses overloaded operators. Include a private reduce member function to be used by other member functions whenever a non-reduced Rational might exist. Overload the input and output operators and the conversion operator to type double. The input operator should reduce the input rational number if it is not already in reduced form. The addition, subtraction, multiplication, and division operators should be overloaded. They should return a result that is reduced. All six relational operators should be overloaded. Use integer variables to represent the numerator and the denominator. Provide a default constructor and an explicit value constructor to initialize the object to specific values.  The definition of the class needs to be in a header file and the implementations of the member functions and friend functions need to be in an implementation file.
  3. Provide a driver program that demonstrates the class.  It should allow the user to enter two rational numbers. It should then calculate and display the sum, difference, product, and quotient of the two rationals showing the results in complete equations. It should also compare the two rationals with all six relational operators reporting the result in complete expressions. Finally it needs to display a real number equivalent to each of the two rational numbers. 
  4. Verify your program works correctly.
  5. Submit your source code file to ude.wons@nosneros.htrag. Due at 8:00 am on 3 March.