CPSC 120 Lab 1
For the following programs, define the outline (purpose, input, processing, and
output), draw a hierarchy chart (at least one branch should go three levels deep), and
explain the program using pseudocode (both high-level and detailed-level). When you
are ready to turn-in the assignment, please convert it to PDF. The PDF file should follow
the naming convention -120-09-Lab1.pdf (as outlined in
1. The Earth’s ocean levels have risen an average of 1.8 millimeters per year over the
past century. Write a program that computes and displays the number of centimeters and
number of inches the oceans rose during this time. One millimeter is equivalent to 0.1
centimeters. One centimeter is equivalent to 0.3937 inches. The output of your program
should be of this form:
The ocean rose X centimeters or Y inches in the last 100 years.
where X and Y are the two numbers your program calculated.
2. Write a program that asks for five test scores. The program should calculate the
average test score and display it. The number displayed should be formatted in fixedpoint notation, with one decimal point of precision. Here is one sample run:
Enter five test scores: 84 75 90 88 96
Average = 86.6
Note: The bold portion is what the user would type in.
3. Write a program that calculates the average rainfall for three months. The program
should ask the user to enter the name of each month, such as June or July, and the
amount of rain (in inches) that fell each month. The program should display a message
similar to the following:
The average rainfall for June, July, and August is 6.72 inches.
4. Write a program that asks the user to enter a number within the range of 1 through 10,
and display the Roman numeral version of that number. You should make sure the input
is validated by not accepting a number less than 1 or greater than 10. Use the following
prompt for input:
Enter a number (1 - 10):
The output of the program should be of the form:
The Roman numeral version of A is R.
where A is the Arabic numeral entered (1,2,3,...) and R is the all-capitals form of a
Roman numeral, such as VII.
5. The speed of sound depends on the material the sound is passing through. Below is
the approximate speed of sound (in feet per second) for air, water and steel:
air: 1,100 feet per second
water: 4,900 feet per second
steel: 16,400 feet per second
Write a program that displays a menu allowing the user to select air, water, or steel.
After the user has made a selection, he or she should be asked to enter the distance a
sound wave will travel in the selected medium. The program will then display the
amount of time it will take. The menu should look exactly like this:
Select a medium:
Enter your choice:
After the user chooses the medium, prompt for distance simply with the string
Enter the distance:
After each calculation, your output should be of the form:
A sound wave takes T seconds to travel D feet in M.
where T is the time you calculated to 4 digits of precision, D is the distance entered and
M is the medium (air/water/steel) selected.
Purchase answer to see full