Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

(please write this program in C++) (only use the library) (do not use the goto statement) (use the switch statement) Write an interactive program that

(please write this program in C++)

(only use the library)

(do not use the goto statement)

(use the switch statement)

Write an interactive program that implements a simple calculator. The program should allow the user to choose a binary arithmetic operation and enter two terms to which to apply the operation. The program should then compute the result and display it to the user. Your calculator will have two modes: double-precision mode and integer mode.

Double-precision mode will do calculations and output using variables of type double. Integer mode will do calculations and output using variables of type int. Your program should start in double precision mode.

At the beginning, the program should output the following:

This program implements a calculator.

At every iteration, your program should ask the user for an option as follows:

Options:

1addition

2subtraction

3multiplication

4division

5toggle calculator type

6exit program

Please enter your option:

Below is a description of what the program should do for each of the above options (items underlined are to be entered by the user):

1.

Perform addition. For this option, the program should ask the user to enter two terms to be added, as

follows:

In double-precision mode:

Enter first term:1

Enter second term:1

The sum is: 2.000000000000000

In integer mode:

Enter first term:1

Enter second term:1

The sum is: 2

2.

Perform subtraction. For this operation, the program should ask the user to enter two terms to be

subtracted, as follows:

In double-precision mode:

Enter first term:4

Enter second term:2

The difference is: 2.000000000000000

In integer mode:

Enter first term:4

Enter second term:2

The difference is: 2

3.

Perform multiplication. For this operation, the program

should ask the user to enter two terms to be

multiplied, as follows:

In double-precision mode:

Enter first term: 2

Enter second term:3

The product is: 6.000000000000000

In integer mode:

Enter first term:2

Enter second term:3

The product is: 6

Perform division. For this operation, the program should ask the user to enter two terms to be divided, as

follows:

In double-precision mode:

Enter first term:5

Enter second term:2

The quotient is: 2.500000000000000

In integer mode:

Enter first term:5

Enter second term:2

The quotient is: 2

If the second term entered by the user is 0, the program should print:

Cannot divide by zero!

5.

Toggle the type of calculator. By default, the program should perform its calculations using double-precision. However, if the user chooses this option, the program should change the type of calculator: either from double to int or vis versa.

When switching from double-precision to integers the program should print the follow message:

Calculator now works with integers.

When switching from integers to double-precision the program should print the following message:

Calculator now works with doubles.

6.

Exit. The program should end

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

Step: 3

blur-text-image

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

Modern Database Management

Authors: Jeff Hoffer, Ramesh Venkataraman, Heikki Topi

12th edition

133544613, 978-0133544619

More Books

Students also viewed these Databases questions