CENG 111 Labwork 7

advertisement
CENG 111 Labwork 7
1. Write a program that, given the type of vehicle (c for car, b for bus, t for truck) and the hours
a vehicle spent in the parking lot, calculate the parking charge based on the rates shown below
Car $2 per hour
Bus $3 per hour
Truck $4 per hour
2. Write a menu-driven program that allows a user to enter three numbers and then choose
between finding smallest, largest, sum or avarage.The menu and all choices are tobe in switch
statement. Use a switch statement to determine what action to take. Provide an error message
if an invalid choice is entered.
Run the program five times, once with each option and once with an invalid option. Each run
is to use the following set of data:
18,21,7
3. In a computerized driving system, your maximum speed of your car as defined by the
condition of the road.
In a rainy condition it is 50 km/h,
in a sunny day 90 km/h,
in a storm 30 km/h and
in normal conditions it is 70 km/h
Write a program that user inputs the amount of distance that s/he wants to go and the weather
condition as a number (rainy = 0, sunny = 1, storm = 2 and normal = 3). Then, you should
calculate the time value according to above statements.
Sample Run:
Enter the distance: 400
Enter the weather condition: 0
You will go in 8 hours.
4. Write a program that test the value of an integer num1. If the value is 10, square num1. If it is
15, multiply by 8 num1. If it is 2 or 3, multiply num1 by 99 and print out the result.
Implement your code using switch statement.
5. Write a program that prompt the user an integer 100 times.
6. Write a program that use while loop to print a line of 60 asterisks.
7. Write a program that creates the following pattern using with while loop
******
******
******
******
Download