Professional Documents
Culture Documents
College of Science
Department of Computer Science
Exercise 1: if/switch
Write a program planet.cpp that reads user weight (between 40 kg and 200 kg) and calculates
user weight on planets using the following formulas:
---------------------------------------
1- Mercury
2-Venus
3-Jupiter
---------------------------------------
Your selection is >
Exercise 2: Nested if/switch
Rewrite the above program so that it reads a single line input containing THREE pieces of
information separated by a space; the 1st input is a numerical value representing the user’s weight,
the 2nd input is a letter indicating the planet which you want to convert the weight from, and the 3 rd
input is a letter indicating the planet which you want to covert the weight to. The weight can be any
value grater than ZERO while the 2nd and 3rd inputs must be one of the following: E=Earth,
M=Mercury, or V=Venus. For the weight conversion between different planets, use the following
table where ‘weight’ is the weight entered by the user:
From
Earth Mercury Venus
To
Earth Not allowed
Submit your source file named lab5_xxxxx.cpp on Moodle before the end of the lab session
(replacing xxxxx with your student ID)