CyberSlug Rules! Beginner Programming CMPS060 Prof. Paulo Franca

Sample Problems for Final Exam

Problem 1:

In order to automate operation of a parking lot, your computer program has to read two time stamps whenever a vehicle is about to leave the parking. You should then compute the time the vehicle was parked and display the appropriate charge.

• Time stamps consist of Hour, Minute and AM or PM
• Parking rates are:
• up to one hour: \$.50
• each hour after the first: \$1.00
• Parking opens at 6 AM and closes at 11 PM

Write a program that continuously requests the "arrival time" and "departure time" for vehicles and displays the appropriate charge.

Problem 2:

Write a function that receives a time stamp (hour,minute,ampm) and transforms the time stamp to minutes (i.e. minutes since 12 midnight).

Problem 3:

You are requested to write a program to compute the final score for students in the written exams. There is a file on disk (scores.txt) containing:

• Student Name
• Score for midterm 1
• Score for midterm 2
• Score for final exam

... for all students in the class.

The final score in written exams is computed by taking the average of the two best grades (i.e. discard the lower grade of the three and then compute the average).

Your program should then write another file to disk containing:

• Student Name
• Final written exam score

... for all students in the class

You may divide this problem into three subproblems as follows:

Problem 3 A

Write a function that inputs data from a file in the hard drive and loads the information in one array for name, one array for midterm 1, one array for midterm 2 and one array for final exam.

Problem 3 B

Write a function that takes three values as arguments and computes the average of the two highest values. This average should be returned as a result.

Problem 3 C

Write a function that receives three arguments: An array of names, an array of scores and an integer expressing the size of the arrays. This function should output (to a disk file)  a list contaning a name and a score for each student

Problem 3 D

Write a main program for Problem 3

Problem 4

You were hired by the IRS to write a program to compute the income tax due for individuals. For this particular problem, the income tax depends on the individuals Yearly Net Income as follows:

• Yearly Net Income up and including 20,000  -  No income tax is due
• Yearly Net Income between 20,000 and 30,000 - 10% of the amount exceeding 20,000
• Yearly Net Income between 30,000 and 50,000 - 20% of the amount exceeding 50,000 PLUS \$1,000
• Yearly Net Income above 50,000 - 30% of the amount exceeding 50,000 PLUS \$5,000

Your program should request the clerk to type the Yearly Net Income and then compute the appropriate tax and display the result

Problem 5

Rewrite problem 4, but now, instead of asking the clerk to type values, input your values from a disk file that contains the name and yearly income of each tax payer. Instead of displaying results, you should write another file to disk containing the name and the tax due for each tax payer.