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

You are to write a program that helps elementary school children study fractions

ID: 3621193 • Letter: Y

Question

You are to write a program that helps elementary school children study fractions. Your program will prompt for an arithmetic operator, which must be one of +, -, *, /. It will then prompt for and input the first argument. The user must enter an integer, the / character, then another integer. The user is then prompted for the second fraction argument. The program then displays the results. The definitions of several functions, including main, are supplied in the incomplete file FractionsHelper.c You are to provide the definitions for the other functions whose prototypes are given above the definition of main.

/* Begin DO_NOT_MODIFY_REGION */

#include <stdio.h>
#include <stdlib.h> /* Provides the abs function */
#include <string.h>

typedef struct fraction {
int numerator;
int denominator;
} Fraction;

int gcd(int x, int y);
/* Precondition: a and b must be positive */

Fraction ReduceFraction(Fraction R);

Fraction inputFraction();
/* Prompts for, inputs and returns a single fraction */


Fraction AddFractions(Fraction R1, Fraction R2);
/* Returns R1+R2 in reduced form */
Fraction SubtractFractions(Fraction R1, Fraction R2);
/* Returns R1-R2 in reduced form */
Fraction MultiplyFractions(Fraction R1, Fraction R2);
/* Returns R1*R2 in reduced form */
Fraction DivideFractions(Fraction R1, Fraction R2);
/* Precondition: in reduced form R2 must be nonzero
Returns R1/R2 */

void PrintResult(Fraction R1, Fraction R2,char op);
/* Carries out the operation indicated by op and prints
a string showing the two operand, the operator and the result */

void GetAndDoFractionOp(char op);
/* Prompts for two fractions
then carries out the specified operation and prints
the result. In the case of division, checks to see
if the second fraction is zero; if so, continues
prompting for and inputing fractions until a nonzero
fraction is input */

int main()
{
char response, theOp;

do {
printf(" -----------------------------------------");
printf(" Enter the operator you want to apply (+,-,*,/) ");
scanf(" %c",&theOp);
while(getchar() != ' ');
while( theOp != '+' && theOp != '-' && theOp != '*' && theOp != '/')
{
printf("%c is not a valid operator; try again ",theOp);
scanf(" %c",&theOp);
while(getchar() != ' ');
}
GetAndDoFractionOp(theOp);
printf("Do you wish to do another (Y/N)?");
scanf(" %c",&response);
} while(toupper(response) == 'Y');

printf("Normal termination ");
return 0;
}

int gcd(int x, int y)
{
if (x%y == 0)
return y;
return gcd(y,x%y);
}

Fraction ReduceFraction(Fraction R)
{
int d;
if (R.numerator == 0)
{
R.denominator = 1;
return;
}
d = gcd(abs(R.numerator),abs(R.denominator));
R.numerator /= d;
R.denominator /= d;

if (R.denominator < 0)
{
R.numerator *= -1;
R.denominator *= -1;
}
return R;
}

/* End DO_NOT_MODIFY_REGION */

/* You supply the definitions for the remaining functions */

Fraction InputFraction()
/* No prompts; just input the fraction */
{

}

Fraction AddFractions(Fraction R1, Fraction R2)
{

}

Fraction SubtractFractions(Fraction R1, Fraction R2)
{

}

Fraction MultiplyFractions(Fraction R1, Fraction R2)
{

}

Fraction DivideFractions(Fraction R1, Fraction R2)
{

}

void PrintResult(Fraction R1, Fraction R2, char op)
{

}

void GetAndDoFractionOp(char op)
{

}

Explanation / Answer

#include void add(int ,int ); void sub(int ,int ); void multi(int ,int ); void div(int ,int ); void main() { int a,b; char op; couta; coutb; coutop; while(1) { if(op=='+') { void add(a,b); } else if(op=='-') { void sub(a,b); } else if(op=='*') { void mul(a,b); } else if(op=='/') { void div(a,b); } else { cout
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote