CS120
Lab #4
Due at the end of lab.
For this lab you will be modifying the Calculator program from
Chapter 4 of the text. For those of you who do not have the text
a version of the code will be posted on the course schedule. Note that
this calculator program is not the same as the one from
previous assignments - it uses a series of functions.
To complete the lab make the following
modifications:
- (Chapter 4, Exercise 2)
Fix the minor, but annoying, problem that when the user exits,
the program reprints the last
answer.
- (Chapter 4, Exercise 3)
Currently, the program just prints the answer to each of the user's
problems. Change the output so that the program prints the whole problem
as a mathematical expression. For example, if the user asks for the sum
of 4.5 and 1.3, the program currently prints:
answer = 5.8
change it to print something like:
4.5 + 1.3 = 5.8
- (Chapter 4, Exercise 4) Add a subtraction operation to the calculator.
- Add an operation that calculates the
surface area of a right circular cylinder.
This calculation
should be done in a separate function, not in the main() function.
- Add an operation that calculates the
volume of a right circular cylinder.
This calculation
should be done in a separate function, not in the main() function.
- Add an operation that calulates the
surface area of a right circular cone.
This calculation
should be done in a separate function, not in the main() function.
- As always add a comment block to the beginning of the program with your
name, section number, date, and the lab number.
Turn in: Use the script command to generate the output of the
program. You will need to run the program multiple times to show how
each of the operations work.
Print and turn in a copy of the code and a copy of the output of the code.