CIS 2520 ASSIGNMENT 2

Due: October 20, 2009

(1)(40%) An expression is in postfix form if the operators appear after their operands; for example. "1 2 +" means  "1 + 2". More generally, "1 2 + 5 3 - *" is probably more familiar as "(1 + 2) * ( 5 - 3)" and "6 7 4 2 / + *" as "6 * ( 7 + ( 4/2))". Write a program that evaluates a postfix expression composed of single digits and operators.

Note that the final (or intermediate) results may exceed a single digit. Your program should detect any reasonable error conditions (such as invalid input; attempt to pop form an empty stack, etc.) and print an appropriate error message.

Hint

Define a stack to hold operands as well as intermediate results.

(2) (60%) Write a program that uses linked lists to maintain a data structure for the CIS Car Rental Company. Several types of transactions will be applied to the data structure in order to keep the lists up-to-date.

You will need to maintain three linked lists for the status of the cars:

 

The cars on the available list should be ordered according to mileage, with the car having the least kilometres at the front of the list. The cars on the rented list will be sorted according to expected return date; the first car on this list will have the earliest expected return date.

The program should prompt the user for a transaction code (integer) as follows:

For the new car addition and the return transactions (codes 1-3), the program should also prompt for a license number (string) and a mileage (integer). For the transfer transaction (code 4), the program should also prompt for a license number (string). For the rent transaction (code 5), the program should also prompt for an expected return date (integer: yyyymmdd). For the print transaction (code 6), there is no additional information. The program quits when the user selects code 7 in the prompter.

Whenever a transaction is processed, a message should be printed indicating what action was taken. In the case of a car being returned, the charge should also be printed.

When a customer returns a rented car, the amount charged is computed as follows:

When the transaction file has been completely processed, print the total income from all the rented cars.

Your program should detect any reasonable error conditions (such as invalid transaction code; attempt to return a non-existent car) and print an appropriate error message.

Hint

Define a structure to represent a rental car including the license number, mileage and date. Since these instances will be the nodes on the car lists, also include the link field (next) in this structure. Also define a car list structure, which represents a list of such car nodes and provides the appropriate operations for insertion, removal and printing.