Basic C++ Programms .

profileBALB123
asisgnment_5-2.pdf

CPSC120- Assignment 5 Due Date: 03/20/2014

1. The Speed of Sound 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. Menu. The menu should look exactly like this: Select a medium: 1. Air 2. Water 3. Steel Enter your choice:

Prompts And Output Labels. 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.

Input Validation. The program should validate both the menu choice and the distance entered. If the

menu choice is not 1 or 2 or 3 then the program prints "The valid choices are 1 through 3. Run the

program again and select one of those." and terminates. The distance must not be negative--

otherwise the program prints out the message "Distance must be greater than zero." and terminates. _________________________________________________________________________________ 2. Geometry Calculator Write a program that displays the following menu: Geometry Calculator 1. Calculate the Area of a Circle 2. Calculate the Area of a Rectangle 3. Calculate the Area of a Triangle 4. Quit Enter your choice (1-4):

If the user enters 1, the program should ask for the radius of the circle and then display its area. Use

the following formula: area = π(the square of r) Use 3.14159 for π and the radius of the circle for r.

If the user enters 2, the program should ask for the length and width of the rectangle and then display

the rectangle’s area. Use the following formula: area = length * width

If the user enters 3, the program should ask for the length of the triangle’s base and its height, and

then display its area. Use the following formula: area = base * height * .5

If the user enters 4, the program should end. Input Validation: Display an error message if the user enters a number outside the range of 1 through

4 when selecting an item from the menu. Do not accept negative values for the circle’s radius, the

rectangle’s length or width, or the triangle’s base or height. Prompts, Output Labels, and Messages : Besides the output specified above, issue the following

messages under the indicated situations: After calculating an area, the program prints "The area is " followed by the calculated area. If the user enters an improper menu choice (1-4), the program prints "The valid choices are 1

through 4. Run the program again and select one of those." If the user enters a negative radius, the program prints "The radius can not be less than zero."

If the user enters a negative value for height or base , the program prints "Only enter positive

values for base and height." _________________________________________________________________________________

3.

Write a program to read today’s date from the user and display it in the following format. Use switch

statement.

Sample I/O

Enter the day: 15

Enter the month: 10

Enter the year : 2014

Today is Oct 15th, 2014.