Define a class for rational numbers a rational number is a


Rational NUMBER

Define a class for rational numbers. A rational number is a number that can be represented as the quotient of two integers. For example, 1/2, 3/4, 64/2, and so forth are all rational numbers. (By ½, etc we mean the everyday meaning of the fraction, not the integer division this expression would produce in a C++ program).

Represent rational numbers as two values of type int, one for the numerator and one for the denominator. Call the class rationalNum

Include a constructor with two arguments that can be used to set the member variables of an object to any legitimate value. Also include a constructor that has only a single parameter of type int; call this single parameter whole_number and define the constructor so that the object will be initialized to the rational number whole_number/1. Also include a default constructor that initializes an object to 0 (that is, to 0/1).

Overload the input and output operators >> and <<. Numbers are to be input and output in the form 1/2, 15/32, 300/401, and so forth. Note that the numerator, the denominator, or both may contain a minus sign, so -1/2, 15/32, -300/-400 are all possible input. The input operator, >>, reads the string 15/32 as

Overload all of the following operators so that they correctly apply to the type rationalNum: ==, <, >, +, -, *, and /.

Write a test program to test your class.

Request for Solution File

Ask an Expert for Answer!!
C/C++ Programming: Define a class for rational numbers a rational number is a
Reference No:- TGS01566620

Expected delivery within 24 Hours