Programming Assignment 2

Write a C program to calculate the parking fare for customers who park their cars in a parking lot when the following information is given:

a)A character showing the type of vehicle: C for car, B for bus and T for truck

b)An integer between 0 and 24 showing the hour the vehicle entered the lot

c)An integer between 0 and 60 showing the minute the vehicle entered the lot

d)An integer between 0 and 24 showing the hour the vehicle left the lot

e)An integer between 0 and 60 showing the minute the vehicle left the lot

This is a public lot. To encourage people to park for a short period of time, the management uses two different rates for each type of vehicle, as shown below:

Vehicle / First Rate / Second Rate
Car / $0.00/hr first 3 hours / $1.50/hr after 3 hours
Truck / $1.00/hr first 2 hours / $2.30/hr after 2 hours
Bus / $2.00/hr first 1 hour / $3.70/hr after 1 hour

You can assume that all vehicles will not be in the parking lot any later than midnight. Military time will be used for this program (00h-23h).

The data will be read from an input file.

The data in the input file will be in the following format:

C

14

23

18

8

where :

C is the type of vehicle,

14 is the hour vehicle entered the lot,

23 is the minute vehicle entered the lot,

18 is the hour the vehicle left the lot,

8 is the minute the vehicle left the lot.

The output will be written into an output file in the format shown below:

PARKING LOT CHARGES

Type of vehicle:

TIME-INXX : XX

TIME-OUTXX : XX

PARKING TIMEXX : XX

ROUNDED TOTAL XX

TOTAL CHARGES$XX.XX

This program must first calculate the actual time spent in the parking lot for each vehicle. This means using modulo arithmetic to handle time calculations. There are many ways to handle this and one way is shown below:

a)Compare the minute portion of the leaving and entering time

If the first one is smaller than the second

  • Add 60 to the minute portion of the leaving time
  • Subtract 1 from the hour portion of the leaving time

b)Subtract the hour portion

c)Subtract the minute portion

d)Since there are no factional hour charges, the program must also round the parking time up to the next hour before calculating the charge. The program should use the switch statement to distinguish between the different types of vehicles.

A well structured program design is required. A typical solution will use several functions besides the main function. Create a set of test data and run your program for the test data to make sure it works right.

How to submit your program:

Just like last time, a flow chart of the program needs to be submitted to me first, to make sure that you are on the right track.

Students should hand in a corrected flow chart of the program and a printout of the source code (make sure it is documented properly according to the UHCL guidelines), in class on the program due date.Please make sure that all this is in an envelope or folder.

A soft copy of the source code should be uploadedonto my website by following the links on the course schedule page.