Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

For this assignment you will be creating a new program to perform very simple calculations for a user. The general format will be very similar

For this assignment you will be creating a new program to perform very simple calculations for a user. The general format will be very similar to that of the Fortune Teller program, so feel free to reference that program for ideas. Be sure to test your program on the course server.
The calculator program should work as follows:
First the program should print a brief message explaining to the user what the program does.
Then the program allows the user to enter two values whose types are double. Each of these two values needs to be stored in its own variable.
Next the user enters a third value that corresponds to the operation that the user wants to have the program perform. For example, the user enters a 1 for addition; a 2 for subtraction; etc.
As the developer of the program, you get to choose which numbers correspond to which operation is to be performed. The mapping between numbers and the corresponding operations should be specified in the brief message that explains what your program does.
Then the program should perform the correct calculation based on the three values the user entered.
The program should be able to perform at least addition, subtraction, multiplication, and division.
Try performing division by 0. You should get some sort of error. To fix this problem, include a check in the division portion of the code to test whether the user entered a 0 as the denominator. If the user did enter a 0, have the program print a warning message instead of performing the division operation.
If you can't complete the entire assignment, be sure to describe what you've completed in the comments at the beginning of the program. On the other hand, if you did extra work on the assignment (and sometimes you will want to) also describe the extra work in the comment at the beginning of the program.
Include a block of comments at the beginning of the program (or add to the existing block) that lists your name, section number, date, and the assignment number. Also include comments on any parts of the assignment you didn't finish or on any extra work you did. Include this comment block at the beginning of every assignment and lab.
For now we are going to assume that the user enters the right type of data (e.g. a number for the values). Later we will start to look at detecting and correcting user input errors. This is called input validation and is a big topic. You could try entering a letter instead of a number if you want - typing control+C will stop the program.
To produce the program output do the following:
1) Type script output1.txt
2) Run the pwd command.
3) Run the program.
3a) Rerun the program several times with different inputs, testing different operations (addition, subtraction, etc).
4) When you feel you have tested the program sufficiently type exit to halt the script command.

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

Advances In Databases And Information Systems Second East European Symposium Adbis 98 Poznan Poland September 1998 Proceedings Lncs 1475

Authors: Witold Litwin ,Tadeusz Morzy ,Gottfried Vossen

1st Edition

3540649247, 978-3540649243

More Books

Students also viewed these Databases questions