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

Write a program that lets the user perform arithmetic operations on fractions. F

ID: 3762023 • Letter: W

Question

Write a program that lets the user perform arithmetic operations on fractions. Fractions are of the form a/b, in which a and b are integers and b != 0. Your program must be menu driven, allowing the user to select the operation (+, -, *, or /) and input the numerator and denominator of each fraction. Furthermore, your program must consist of at least the following functions: Function menu: This function informs the user about the program’s purpose, explains how to enter data, and allows the user to select the operation.

Function addFractions: This function takes as input four integers representing the numerators and denominators of two fractions, adds the fractions, and returns the numerator and denominator of the result. (Notice that this function has a total of six parameters.)

Function subtractFractions: This function takes as input four integers representing the numerators and denominators of two fractions, subtracts the fractions, and returns the numerator and denominator of the result. (Notice that this function has a total of six parameters.)

Function multiplyFractions: This function takes as input four integers representing the numerators and denominators of two fractions, multiplies the fractions, and returns the numerators and denominators of the result. (Notice that this function has a total of six parameters.)

Function divideFractions: This function takes as input four integers representing the numerators and denominators of two fractions, divides the fractions, and returns the numerator and denominator of the result. (Notice that this function has a total of six parameters.)

Explanation / Answer

#include "stdafx.h"

#include <iostream>

using namespace std;

void choice(int &a,int &b,int &c,int &d,char ch,int &upper,int &lower);

int addFractions(int a,int b,int c,int d,int &upper,int &lower);

int subtractFractions(int a,int b,int c,int d,int &upper,int &lower);

int multiplyFractions(int a,int b,int c,int d,int &upper,int &lower);

int divideFractions(int a,int b,int c,int d,int &upper,int &lower);

int a,b,c,d,nom,den;

char operation;

int main()

{

            choice(a,b,c,d,operation,nom,den);

            cout<<"answer is "<<nom<<"/"<<den<<endl;

            system("pause");

            return 0;

}

void choice(int &a,int &b,int &c,int &d,char ch,int &nom,int &den)

{

            cout<<"enter a,b,c,d"<<endl;

            cin>>a>>b>>c>>d;

            cout<<"enter opperation "<<endl;

            cin>>ch;

            switch(ch)

            {

            case '+':

                        addFractions(a,b,c,d,nom,den);

                        break;

            case '*':

                       multiplyFractions(a,b,c,d,nom,den);

                        break;

            case '/':

                        divideFractions(a,b,c,d,nom,den);

                        break;

            case '-':

                        subtractFractions(a,b,c,d,nom,den);

                        break;

            }

}

int addFractions(int a,int b,int c,int d,int &nom,int &den) // for sum

{

            nom=a*d+b*c;

            den=b*d;

            return nom;

            return den;

}

int muliplyFractions(int a,int b,int c,int d,int &nom,int &den) // for multiplication

{

            nom=a*c;

            den=b*d;

            return nom;

            return den;

}

int subractFractions(int a,int b,int c,int d,int &nom,int &den) // for subtraction

{

            nom=a*d-b*c;

            den=b*d;

                        return nom;

            return den;

}

int divideFractions(int a,int b,int c,int d,int &nom,int &den) // for division

{

            nom=a*d;

            den=b*c;

                        return nom;

            return den;


}

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