Write a c program that using the rational class performs


Question: Rational fractions are of the form a/b , where a and b are integers and b ? 0. Suppose a / b and c / d are fractions.

Arithmetic operations on fractions are defined by the subsequent rules:

a / b + c / d = (ad + bc) / bd

a / b - c / d = (ad - bc) / bd

a / b * c / d =  ac / bd

(a / b)  / (c / d) = ad / bc, where c/d ? 0.

Fractions are compared as follows:

a / b   op   c/d   if   ad   op  bc, where op is any relational operator. For example,  a/b  <  c/d if  ad < bc.

Part 1: Create a class, called Rational, for performing arithmetic and relational operations on fractions.

Use integer variables to represent the private instance variables of the class - the numerator and the denominator.

Provide a constructor method that allows an object of this class to be initialized when it is declared. The constructor should store the fraction in reduced form (i.e. the fraction 2/4 would be stored as 1 in the numerator and 2 in the denominator). Provide a no-argument constructor in case no initializers are provided.

a. Overload the arithmetic operators ( +, -, *, / ) , so that the suitable symbol can be used to perform these operations. The result of each operation should be in reduced form.

b. Overload the relational operators ( <, <=, >, >=, ==, != ) , so that the appropriate symbol can be used to perform these operations.

c. Overload the stream insertion and stream extraction operators for input and output.

Part 2: Write a C++ program that, using the rational class performs operations on fractions. Test your class thoroughly.

Show the constructor method and overload the stream insertion and stream extraction operators

Request for Solution File

Ask an Expert for Answer!!
C/C++ Programming: Write a c program that using the rational class performs
Reference No:- TGS0954062

Expected delivery within 24 Hours