Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I need help with writing the following program for my C++ class. Program must al

ID: 3635661 • Letter: I

Question

I need help with writing the following program for my C++ class. Program must also contain the use of functions. Help will be greatly appreciated!

You are developing a Fraction structure for Teacher’s Pet Software. The structure contains three public data fields for whole number, numerator, and denominator. Using the same structure, write the functions described below:
» An enterFractionValue()function that declares a local Fraction object and prompts the user to enter values for the Fraction. Do not allow the user to enter a value of 0 for the denominator of any Fraction; continue to prompt the user for a denominator value until a valid one is entered. The function returns a data-filled Fraction object to the calling function.
» A reduceFraction()function that accepts a Fraction object and reduces it to proper form, returning the reduced Fraction. For example, a Fraction entering the function as 0 2/6 would be reduced to 0 1/3, and a Fraction entered as 4 18/4 would be reduced to 8 1/2.
» A displayFraction()function that displays any Fraction object passed to it. This function displays a fraction with a slash between the numerator and denominator.
» A main()function that declares a Fraction object and continues to get Fraction values from the user until the user enters a Fraction with value 0 (both the whole number and the numerator are 0). For each Fraction entered, display the Fraction, reduce the Fraction, and display the Fraction again.

Explanation / Answer

#include struct Fraction { int wholeNumber; int numerator; int denominator; }; struct Fraction enterFractionValue(){ struct Fraction fraction; do { printf("Enter the numerator / the denominator of the fraction. Example: 1/2 "); scanf("%d/%d", &fraction.numerator, &fraction.denominator); if (fraction.denominator < 0) printf("Enter a postive demoninator, if you want the fraction to be negetive make the numerator positive "); } while (fraction.denominator < 0); if (fraction.denominator !=0) fraction.wholeNumber= fraction.numerator/fraction.denominator; return fraction; } struct Fraction reduceFraction(struct Fraction fraction) { for (int i = 1; i < 10; i++) { if (fraction.numerator%i==0 && fraction.denominator%i ==0){ fraction.numerator/=i; fraction.denominator/=i; } } return fraction; } void displayFraction(struct Fraction fraction) { printf("%d/%d ", fraction.numerator, fraction.denominator); } int main (){ struct Fraction fraction; do{ fraction = enterFractionValue(); displayFraction(fraction); printf("Now trying to reduce the fraction "); fraction = reduceFraction(fraction); displayFraction(fraction); }while(fraction.denominator !=0); return 0; }