Site hosted by Angelfire.com: Build your free website today!

Program #15                                       

C++ Dzwonkiewicz

 

 This will be a program with FIVE functions.

 

The user will enter 2 ratio fractions, in a Get_frac function.

 Enter 4 numbers to appear like fractions(use reference parameters)

Then a MENU will appear that looks like this…

 

                        Fraction calculation

1)      Calculate Sum(+) of two fractions

2)      Calculate Difference(-) of two fractions

3)      Calculate Product(x) of two fractions

4)      Calculate Quotient(‘/’) of two fractions

 “I hate it when good eggs go bad.”

Each of the options will call a different function (Get_Sum, Get_diff, Get_prod, and Get_quo). In the function ( a void function) the calculation will print out the appearance of fractions. Remember C++ will try to divide if you use the slash. The answers will not be simplified fractions.

 

Sample output…

Please enter first numerator followed by first denominator: 3 / 4

Please enter the second numerator followed by the second denominator: 5 / 8

Select type of operation;(the menu will pop up)

                                            Fraction calculation

1) Calculate Sum(+) of two fractions

2) Calculate Difference(-) of two fractions

3) Calculate Product(x) of two fractions

4)Calculate Quotient(‘/’) of two fractions       

The product : 3 / 4 x 5 / 8 = 15 / 32

 

The program can get negatives for subtraction. You need to calculate a denominator for sum and diff.

 

Hint: after cin’ s of num1, denom1, num2 and denom2, the result for product will be this…

     Top=num1xnum2;

      Bottom=denom1xdenom2;

Cout<< “The product :” <<num1<<’/’<<denom1<<<<’x’<<num2<<’/’<<denom2<<’=’<<top<<’/’<<bottom<<flush;