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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started