Question: Create a class called Mixed . Objects of type Mixed will store and manage rational numbers in a mixed number format (integer part and a
Create a class called Mixed. Objects of type Mixed will store and manage rational numbers in a mixed number format (integer part and a fraction part). The class, along with the required operator overloads, should be written in the files "mixed.h" and "mixed.cpp".
Details and Requirements
Your class must allow for storage of rational numbers in a mixed number format. Remember that a mixed number consists of an integer part and a fraction part (like 3 1/2 -- "three and one-half"). The Mixed class must allow for both positive and negative mixed number values. A zero in the denominator of the fraction part constitutes an illegal number and should not be allowed. You should create appropriate member data in your class. All member data must be private.
There should be two constructors. One constructor should take in three parameters, representing the integer part, the numerator, and the denominator (in that order), used to initialize the object. If the mixed number is to be a negative number, the negative should be passed on the first non-zero parameter, but on no others. If the data passed in is invalid (negatives not fitting the rule, or 0 denominator), then simply set the object to represent the value 0. Examples of declarations of objects:
Mixed m1(3, 4, 5); // sets object to 3 4/5 Mixed m2(-4, 1, 2); // sets object to -4 1/2 Mixed m3(0, -3, 5); // sets object to -3/5 (integer part is 0). Mixed m4(-1, -2, 4); // bad parameter combination. Set object to 0.
The other constructor should expect a single int parameter with a default value of 0 (so that it also acts as a default constructor). This constructor allows an integer to be passed in and represented as a Mixed object. This means that there is no fractional part. Example declarations:
Mixed m5(4); // sets object to 4 (i.e. 4 and no fractional part). Mixed m6; // sets object to 0 (default)
Note that this last constructor will act as a "conversion constructor", allowing automatic type conversions from type int to type Mixed. The Mixed class should have public member functions Evaluate(), ToFraction(), and Simplify(). The Evaluate() function should return a double, the others don't return anything. These functions have no parameters. The names must match the ones here exactly. They should do the following:
The Evaluate function should return the decimal equivalent of the mixed number.
The Simplify function should simplify the mixed number representation to lowest terms. This means that the fraction part should be reduced to lowest terms, and the fraction part should not be an improper fraction (i.e. disregarding any negative signs, the numerator is smaller than the denominator).
The ToFraction function should convert the mixed number into fraction form. (This means that the integer part is zero, and the fraction portion may be an improper fraction).
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
