This is what I have to do:
A bus line called the World's Longest Street Bus Line, wants you to write a program that produces a billing report based on passenger trips and cost of trips. The company has a large fleet of buses that run between towns, on different parts of Yonge Street from Toronto to Barrie. Yonge Street is over 700 miles long and is the longest street in the world. The buses can stop at many towns between Toronto and Barrie.
These buses are equipped with the latest satellite technology that can tell where all buses are located. In order for a passenger to use the bus they need a credit card. When the passenger gets on the bus they slide their credit card into a machine. The machine reads the credit card number and sends a message containing the credit card number and the location where the passenger got onto the bus to the satellite. The satellite then sends the message to the head office of the bus line. When the passenger gets off the bus, they insert their credit card again and the same process occurs.
The program will read two files: prices.dat containing data about prices and cities, and trips.dat containing all the trips taken in a single day. The program will process these files and produce a file, billing.rpt containing billing information, and also will print summary information on the screen.
The prices.dat file contains one record (line) for each town with a town ID and a town price. The towns are listed, starting at Toronto. An example of 5 towns is:
7 0.00
15 5.00
22 10.00
3 15.50
40 25.00
The first town (Toronto) has an ID of 7 and a price of $0.00. The second town has an ID of 15 with a price of $5.00, etc. The cost of a trip from the 2nd town to the 4th town is $15.50 - $5.00 = $10.50.
The cost of a trip from the 5th town to the 2nd town is $25.00 - $5.00 = $20.00.
The trips.dat file contains one record for each passenger trip on a single day with an entry town ID, exit town ID and credit card number. A credit card number consists of 11 characters. An example of 6 trips is:
7 15 MC123456789
3 15 AE111222333
3 99 AB432344655
40 40 VZ333222111
40 7 VI010101010
7 40 VI010101010
Your program must write one record to the billing.rpt file for each trip containing the credit card number, entry town ID, exit town ID and trip cost. If either the entry or exit town ID is not found in the prices file, or if the entry town equals the exit town, then the record must indicate an error and show the town IDs. The data must be neatly aligned. An example, based on the above files is:
--- BILLING REPORT ---
MC123456789 7 15 $ 5.00
AE111222333 3 15 $10.50
** INVALID TOWN DATA: 3 99 *
** INVALID TOWN DATA: 40 40 *
VI010101010 40 7 $25.00
VI010101010 7 40 $25.00
--- END OF BILLING REPORT ---
Summary lines are to be printed on the screen showing the number of valid and invalid trips, and the total cost of all trips. For example:
Number of valid trips processed: 4
Number of invalid trips processed: 2
Total trip revenue: $65.50
Because your program must search the price data for each trip, it is efficient to first load the town and price data into arrays. However, because of the possible size of the trip file you should not load the trip data into an array.
For each trip your program must search for the trip’s entry town and exit town, so you must code and use this function:
int search( int data[ ], double value[ ], int size, int key, double *pkeyValue)
that will sequentially search the ‘data’ array (containing ‘size’ number of items) for the value of the parameter ‘key’. If the ‘key is found then set the last parameter to the value of the corresponding item from the ‘value’ array, and return 1 (true). Return 0 (false) if the value is not found.
If someone could help me out that would be great.