You are on page 1of 1

Q. Create a class Rational to represent rational numbers (of form p/q).

The class should have


two data members (integers) to represent the numerator and denominator of a rational
number. Provide the following features in your class.

• Appropriate constructors (default/parameterized)


• Get and Set methods for each data member
• A display function to display the rational number
• Overload the following operators: +, - , * to allow addition, subtraction and multiplication
of rational numbers. (You do not need to simplify the number).
• Provide an operator ~ to invert the rational number, i.e. p/q should become q/p;
• Overload the prefix increment (++) and decrement (--) operators. These operators
should increment (decrement) the numerator of the rational number.
• Your program should allow statements like:
Rational a, b, c(2,3), d(5,8);
c = a + b;
d=~c;
a = ++ c;
b = -- d;

In main print your complete name, Reg #, Class section


Test All the overloaded operators

You might also like