Question: Create a class called Rational for performing arithmetic with fractions. Write a program to test your class. Use integer variables to represent the private data

Create a class called Rational for performing arithmetic with fractions. Write a program to test your class. Use integer variables to represent the private data of the class - the numerator and the denominator. Provide a constructor that enables an object of this class to be initialized when its declared. the constructor should contain default values in case no initialzers are provided and should store the function in reduced form. for example the fraction 2/4 would be stored in the object as 1 in the numerator and two in the denominator. provide public member functions and perform each of the following tasks: Add:adds two rational numbers. the results should be stored in reduced form. Subtract: subtracts two rational numbers. store the results in reduced form. Multiply: Multiplies two rational numbers. store the results in reduced form. Divide: Divides two rational numbers. Stores the results in reduced form. toRationalString: returns a string representation of a rational number in the form a/b, where a is the numerator and b is the denominator. todouble: returns the rational number as a double.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!