Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

In this lab you will code a simple calculator. It need not be anything overly fancy, but it is up to you to take it

In this lab you will code a simple calculator. It need not be anything overly fancy, but it is up to you to take it as far as you want. You will be creating this program in three small sections. You have the menu, the performance of the basic arithmetic operations (Addition, Subtraction, Multiplication, and Division), and the looping. You may want to get the switch menu working first, and then fill in the code for these four arithmetic operations. Your program will keep a running total. It should print the subtotal out after each and every calculation. In addition, the total should be printed before the program quits. So with that being said, the program needs to define a data field, named total at the beginning of main and set it to zero. Part A: Designing the menu system Menu systems in C++ (and other languages) are often represented as a switch statement. Design a switch statement that handles five cases and a default case. case 0 Exit case 1 Addition case 2 Subtraction case 3 Multiplication case 4 Division default Error message Make sure to print out a list of options explaining to the user what each case does, like Enter 1 to add a number to total or Enter 2 to subtract a number from total. This menu should appear before the switch statements. It is also vital to allow the user to input their choice of 0-4. Part B: Filling in the Cases At this point, you should have a working menu that does nothing. It is time to add code to each of the cases so that they will do the function you displayed to the user. Start by writing code inside of case 1 that will prompt the user to enter a single number. Since this case is for addition, you will want to make sure to add the number you entered to the running total. Once this works, you should do the same for the other mathematical functions. Only substituting in the other three operation (Subtraction, Multiplication, and Division) Part C: Repetition Allowing the user to select which function then input data is nice. But how often do you open the calculator and do just a single calculation? It would be a good idea to wrap your entire menu into some sort of structure that allows it to repeat more than a single time. If you were to use such a thing, how would you stop it? Part C is to surround your entire program thus far with a loop that allows it to be run more than once. It would also be a good idea to allow for exiting this loop. Be sure to print out a sub total each time the loop runs. Run: You will do two runs of this program. Run One: Add 10, multiply by 5.5, divide by 3, add 20.5, subtract 5 and exit. The final total should be 33.83. Run Two: Enter in numbers of your choosing. Please choose at least 1 addition, 1 subtraction, 1 multiplication, and 1 division. Remember to double check your answer. Submission: Turn in the source program and your two outputs to D2L. See Lab 1s instruction sheet for details on how to document your code and submit your work.

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

Professional IPhone And IPad Database Application Programming

Authors: Patrick Alessi

1st Edition

0470636173, 978-0470636176

More Books

Students also viewed these Databases questions