Question: Can someone help me write a menu driven fraction calculator in c++ it needs to be with manipulator of string and use the string strVar

Can someone help me write a menu driven fraction calculator in c++ it needs to be with manipulator of string and use the string strVar

The excersise on Chapter 7, Problem 7PE of book c++ programming from problem analysis to program desing D.S.Malik

//header file

//declare 5 functions menu()

// start main

// declare var

//take user input

// den !=0

//switch case for operations

//define all functions

#include

using namespace std;

//Function's prototype

char menu();

void addFractions(int a1, int b1, int a2, int b2, int& num, int& den);

void subtractFractions(int a1, int b1, int a2, int b2, int& num, int& den);

void multiplyFractions(int a1, int b1, int a2, int b2, int& num, int& den);

void divideFractions(int a1, int b1, int a2, int b2, int& num, int& den);

//Begin main function

int main ()

{

int a1, b1, a2, b2, num, den;

char ch=menu();

//Prumpt/read user's input

cout << " \t Enter the numer for fraction1:";

cin >> a1;

do

{

cout << "\t Enter the denominator for fraction1 :";

cin >> b1;

// denominator != 0

if (b1==0)

cout << "\t Denominator cannot be zero. ";

} while (b1==0);

cout << " \t Enter the number for fraction2:";

cin >> a2;

do

{

//Prompt and read the user's input

cout << "\t Enter the denominator for fraction2:";

cin >> b2;

if (b2==0)

cout << "\t Denominator cannot de zero ";

}while (b2==0);

switch (ch)

{

case '+':

{

addFractions(a1,b1,a2,b2,num,den);

cout <<"\t"<

cout << " ";

system("pause");

break;

}

case '-':

{

subtractFractions(a1,b1,a2,b2,num,den);

cout << "\t"<

cout << " ";

system("pause");

break;

}

case '*':

{

multiplyFractions(a1,b1,a2,b2,num,den);

cout << "\t"<

cout << " ";

system("pause");

break;

}

case '/':

if (a1!=0 &&a2!=0)

{

divideFractions(a1,b1,a2,b2,num,den);

cout << "\t"<

cout << " ";

cout << " ";

system("pause");

break;

}

else

{

cout <<" |t Denominator fraction of" << "the result" <<"cannot de zero";

cout <<" ";

system("pause");

break;

}

}

return 0;

}

char menu()

{

//OUTPUT for the user

char operationType;

cout << " \t MENU";

cout <<" \tAddition:+ , Subtraction :-, "

<<" \t Multiplication : *, division : /";

cout << " \t Enter the operation to perform: ";

cin >>operationType;

return operationType;

}

void addFractions(int a1, int b1, int a2, int b2, int& num, int& den)

{

num= (a1 * b2)+(b1 * a2);

den= b1 * b2;

}

void subrtractFractions(int a1, int a2, int b1, int b2, int& num, int& den)

{

num= ( a1 * b2) - ( b1 * a2);

den = b1 * b2 ;

}

void multiplyFractions ( int a1 , int b1 , int a2, int b2, int& num, int& den )

{

num = a1 * a2;

den = b1 * b2;

}

void divideFractions ( int a1, int b1, int a2, int b2, int& num, int& den)

{

num = a1 * b2;

den = b1 * a2;

}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!