Question: Please complete in C++. Define a class called Rational. The class will represent objects that are rational numbers or what we think of as fractions.

 Please complete in C++. Define a class called Rational. The class

Please complete in C++.

Define a class called Rational. The class will represent objects that are rational numbers or what we think of as fractions. Your class should have two integer member variables, one that represents the numerator of a rational number and one that represents the denominator. Write three constructors for your class: a default constructor that constructs the fraction 0/1, a single argument constructor that constructs a given integer value into a rational number by placing it as the numerator/1 and finally a two argument constructor that allows the user to select both a numerator and denominator for your rational number. The last constructor can be a bit tricky because it allows the user to give you values that are not in simplest form for example they could ask you to construct the fraction 4/2 which should be stored internally as 2/1. How can this be done? Take a look at the Euclidean algorithm for computing the greatest common divisor of two numbers (search the web). Implement this function as a helper function (private function) that your class can use when simplifying fractions. Lastly, for this assignment, overload the

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!