C++ Program 3

rational.cpp

Build an ADT for rational numbers.

A rational number consists of two integer pieces a numerator, say a, and a denominator, say b, representing a fraction a / b.

The rational number is said to be in proper form if the greatest common divisor of both the numerator and denominator is 1 and the denominator is positive.

The result of operations between two rational numbers  a / b  and  c / d  follows.

You should name the class Rational. You should have "four" constructors (perhaps by overloading, or perhaps by default values, or perhaps by both as appropriate): default (initial value zero, 0 / 1), input using a single integer (representing the integer using 1 for the denominator), input using two integers (representing the numerator and denominator respectively), and a copy constructor.

You should have two accessor functions, getNum() for the numerator and getDenom() for the denominator.

You should overload the assignment operators (which should be member functions): =, +=, -=, *=, /=

You should overload binary operators (which should be member functions): +, -, *, /

You should overload the unary operator (which should be a member function): -

You should overload the output operator (which should be a non-member function, but may be a friend): <<

You should overload the comparison operators (which should be member functions): <, <=, >, >=, ==, !=

You should overload the absolute value function (which should be a non-member function, but may be a friend): abs()

In addition to your *.cpp and *.h files turn in a main program that exercises the class Rational. That is, a main program that runs through a selection of arithmetic and logical operations and uses rational input and output.
 


What to turn in


Grading Criteria