Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Please create the following program in c++. Define a class called fraction that will hold a numerator, denominator, and the decimal representation of the fraction.

Please create the following program in c++. image text in transcribed
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. rite overloaded fraction operators to add, subtract, multiple, and divide fractions. Write an overloaded cout operator that will print out the fraction as xly. 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: Enter 1 numerator denominator (space in between) 1 3 Enter 2 numerator denominator: 3 6 Result: S/6 Enter numerator denominator (space in between) 4 6 Result: 2/3 Class member variables: numerator . decimal equivalent Class member functions . Default constructor Constructor that will accept numerator and denominator Overloaded +,, Overloaded > Function that will calculate the decimal equivalent Function that will give the reduced fraction 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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions