Calculate the third fraction to be the sum of the two


In Chapter 1 you developed a Fraction structure for Teacher's Pet Software. The structure contains two public data fields for numerator and denominator. Using the same structure, write a main()function in which you create three Fraction objects. Prompt the user for values for each field of two of the Fractions. Add statements to the main()function to do the following:

» Display the floating-point equivalent of each Fraction object. For example, the floatingpoint equivalent of 1/4 is 0.25.

» Calculate the third Fraction to be the sum of the two entered Fractions. To sum fractions, you must find a common denominator.

You can do this by multiplying each operand Fraction's numerator and denominator by the denominator of the other Fraction, using the common denominators, and adding the numerators. For example, to create a Fraction that is the sum of 2/5 plus 1/6, you do the following:

1. Multiply the numerator and denominator of 2/5 by the denominator of the second Fraction, 6, giving 12/30.

2. Multiply the numerator and denominator of 1/6 by the denominator of the first Fraction, 5, giving 5/30.

3. Add the numerators and use the common denominator, giving 17/30.

Display the result. You do not need to reduce an improper Fraction result. For example, when you add 1/2 and 1/4, the result can be displayed as 6/8 instead of being reduced to 3/4.

Request for Solution File

Ask an Expert for Answer!!
Basic Computer Science: Calculate the third fraction to be the sum of the two
Reference No:- TGS02192899

Expected delivery within 24 Hours