Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Data Mining Concepts And Techniques

Authors: Jiawei Han, Micheline Kamber, Jian Pei

3rd Edition

0123814790, 9780123814791

More Books

Students also viewed these Databases questions

Question

1. What is employment? 2. What is the rewards for employment?

Answered: 1 week ago

Question

1. What is meant by Landslide? 2.The highest peak in Land?

Answered: 1 week ago

Question

What are the impact of sand mining in rivers ?

Answered: 1 week ago

Question

What are the important Land forms in Lithosphere ?

Answered: 1 week ago

Question

How well do we currently work together?

Answered: 1 week ago