Must be done in C++. The following can use loops, strings, arrays, functions, an
ID: 668917 • Letter: M
Question
Must be done in C++. The following can use loops, strings, arrays, functions, and constructors/destructors. The code (as is stated in the description) must be able to accept and perform calculations on whole number portions of mixed numbers (like the '2' in 2 1'2):
You have been developing a Fraction class for Teacher’s Pet Software that contains
several fields and functions.
Add two constructors to the class. The first accepts two integer values representing the
numerator and denominator. If a single integer is passed to the constructor, use it as the
numerator, and use a default value of 1 for the denominator. If no values are passed to
the constructor, use a default value of 0 for the numerator and 1 for the denominator.
When any Fraction is constructed with a 0 argument for the denominator, force the
denominator value to 1.
The second constructor requires three arguments: a whole number portion for a Fraction,
a numerator, and a denominator. This constructor executes when any Fraction object
is instantiated using three integer arguments. As with the other constructor, when any
Fraction is constructed with a 0 argument for the denominator, force the denominator
value to 1.
Whenever a Fraction object is constructed, automatically reduce the Fraction to the
proper format. For example, a Fraction created using 0, 2, and 4 as arguments should
be reduced to 1/2, and a Fraction created as 3 10/2 should be reduced to 8 0/1.
Write a main()function that declares several Fraction objects, and confirm that the
class works correctly.
Save the file as Fraction.cpp.
Explanation / Answer
fraction.cpp
//header files
main.cpp
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.