Question: PLEASE C++ ONLY Redo programming exercise 8 of chapter 4 so that your program handles exceptions such as division by zero and invalid input. Write

PLEASE C++ ONLY

Redo programming exercise 8 of chapter 4 so that your program handles exceptions such as division by zero and invalid input. Write a program that mimics a calculator. The program should take as input two integers and the operation to be performed. It should then output the numbers, the operator, and the result. (For division, if the denominator is zero, output an appropriate message). Some sample outputs follow:

3 + 4 = 7

13 * 5 = 65

REFERENCE CODE

using namespace std;

int main()

{

inta, b;

char ch;

try

{

cout << "Enter two numbers: ";

cin >> a >> b;

cout <

if (b==0)

throw b;

cout << " 1. Addition 2.Substraction 3. Multiply 4. Division 5.Modulus" <

cout << " Enter your choice (+ or - or * or %): ";

cin >> ch;

switch (ch)

{

case'1': cout << " Add="<

break;

case'2': cout << " Sub="<

break;

case'3': cout << " Mul="<

break;

case'4': cout << " Div="<

break;

case'5': cout << " Mod="<

break;

default: throw ch;

}

}

catch(int b)

{

cout<"<

}

catch(char ch)

{

cout<"<

}

system("pause")

}

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!