Question: Ratio Data Type Part I:Using C++ Class Structure Create a class called Ratio for performing arithmetic with fractions. Write a program to test your class.

Ratio Data Type Part I:Using C++ Class Structure Create a class called Ratio for performing arithmetic with fractions. Write a program to test your class. Use integer variables to represent the instance variables - the numerator and the denominator. The data members should be private. Provide appropriate accessor and mutator functions. Provide a constructor that enables an object of this class to be initialized when it is declared. Provide a no-argument constructor with default values of 1 in case no initial values are provided. getDoubleValue is a public function that returns a double with the same value as the underlying Ratio number. This function should not accept any parameters. Store the numerator and denominator as separate data members of the class. The numerator and denominator should be stored so that the ratio is always in reduced form. Fractions are said to be in reduced form if the greatest common divisor of the numerator and the denominator is 1. (For example, 3/6 is equivalent to 1/2 and would be stored by the class as 1 in the numerator and 2 in the denominator.) It will be necessary to reduce the ratio when an object is created (from the constructor) and whenever the numerator or denominator change in value (from the mutator functions). It is probably most efficient to make a function whose purpose is to reduce the current ratio by considering the numerator and denominator instance variables. Then the reduce function can be performed whenever its needed.

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!