Question: Hello can someone help me with this? Create a class named Fraction. The class should consist of only two private data members : numerator and
Hello can someone help me with this?
Create a class named Fraction. The class should consist of only two private data members : numerator and denominator. Both data members must be of type int.
Make sure all your member functions and constructors are defined in the implementation section of the class. Do not use any inline class member functions.
Create the following class member functions: setNumerator, getNumerator, setDenominator, getDenominator. Each of these member functions should be public.
The setNumerator function should accept 1 integer argument and use this value to update the numerator data member.
The getNumerator function should return back the value of the numerator data member.
The setDenominator function should accept 1 integer argument and use this value to update the denominator data member. Do not allow the denominator data member to be assigned a value of zero. If the argument is zero then update the denominator data member to a default value of 1.
The getDenominator should return back the value of the denominator data member.
Create a default constructor for the Fraction class. This constructor will accept no arguments. Use the default constructor to initialize the numerator and the denominator to the value 1.
Overload the constructor to accept two integer arguments. One of the arguments will be used to assign a value to the numerator and the other argument will be used to assign a value to the denominator. Do not allow the denominator data member to be assigned a value of zero. If the argument for the denominator is zero then update the denominator data member to a default value of 1.
Steps 7 through 9 below all apply to the main function.
Create a main function. In the main function create two Fraction objects. The first Fraction object should be created using the default constructor. The second Fraction object should be created using the overloaded constructor.
Use the appropriate get functions to print the values for the data members for the first and second Fraction objects.
For one of the Fraction objects, use the set methods to change the value of both the numerator and the denominator. Again use the appropriate get functions to print the values for the data members for this Fraction object.
Do not print from within the Fraction class. Instead you will retrieve the data in the main() function and print from main.
You do not have to reduce fractions for your assignment. If the value of a Fraction object is 4/8 it does not have to be reduced to 1/2.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
