Question: Please write the test program(*/main.cpp), the headerfile (*/program.hpp), and the main C++ program (*/program.cpp) of the following with clear notes: The contents for each: 1)
Please write the test program(*/main.cpp), the headerfile (*/program.hpp), and the main C++ program (*/program.cpp) of the following with clear notes:
The contents for each:
1) program.hpp contains pseudo code and the class definition.
2) program.cpp contains the code for the class fraction.
3) main.cpp contains psuedo code for main and tests the fraction class.
Description: Define a class called fraction that will hold a numerator, denominator, and the decimal representation of the fraction. The class should define a default constructor that will set the numerator and the denominator to 1 and the correct decimal representation. There should be another constructor that will accept the numerator and denominator as parameters. To set the values for the constructors, use an initialization section. Write overloaded fraction operators to add, subtract, multiple, and divide fractions. Write an overloaded cout operator that will print out the fraction as x/y. Write an overloaded cin function that will ask for a numerator and denominator of a fraction. You will also write a function that will calculate the decimal equivalent of the fraction. You should also have a function that will reduce the fraction and return the result. The original fraction should still be saved. For example, if the fraction is 6/10, this function should return 3/5, but if the original fraction should still be stored as 6/10.
In the main function, you are going to write code that will display the following menu
1. Add fractions
2. Subtract fractions
3. Multiple fractions
4. Divide fractions
5. Reduce a fraction
6. Show the decimal equivalent of a fraction
7. Exit the program
For the first 4 cases, the program should ask for the 2 fractions. For 4 -6, the program should ask for 1 fraction.
Sample output:
1
Enter 1st numerator denominator (space in between) 1 3
Enter 2nd numerator denominator: 3 6
Result: 5/6
5
Enter numerator denominator (space in between) 4 6
Result: 2/3
Class member variables:
numerator
denominator
decimal equivalent Class member functions
Default constructor
Constructor that will accept numerator and denominator
Overloaded +, -, /, *
Overloaded << and >>
Function that will calculate the decimal equivalent
Function that will give the reduced fraction Requirements
Fraction must be implemented in a class with the above requirements.
No global variables are to be used
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
