passing arrays as function

Instructions
Note: Some data input to this program and some program output depends on your name. If you do not use your name as required, points will be deducted for this assignment.
(Your full name)’s Tour Bus Company has a file that called BusInput.txt which contains the following information:
• Bus number (an int)
• Fuel Cost (a double)
• Equipment Insurance (a double)
• Miscellaneous Expense (a double)
The company also gets a 10% discount of the fuel cost due to its good reputation. Assume the company has up to 200 busses.
Write a C++ program that does the following:
• Create two parallel arrays (one for the bus numbers, the other for the final bus costs.)
• Read in the data from the file.
• Calculate the final cost per bus.
• Display all information to the console including new fuel cost and final bus cost.
• Store the bus number and calculated final bus cost in the arrays.
• Create an output file called BusCost.txt that contains the contents of the arrays in reverse order.
Example Input and Output
BusInput.txt should look like this:
111 100.00 200.00 50.00
222 200.00 300.00 100.00
333 400.00 500.00 75.00
Note that each line contains the bus number, fuel cost, equipment cost, and miscellaneous cost in that order.
The display should look like this:
Welcome to Nicholas Coleman’s Tour bus Company
Bus No Fuel Equipment Misc Discount Fuel Final Cost
111 100.00 200.00 50.00 90.00 340.00
222 200.00 300.00 100.00 180.00 580.00
333 400.00 500.00 75.00 360.00 935.00

Totals 700.00 1000.00 225.00 630.00 1855.00
Note the discount fuel cost is calculated by multiplying the fuel cost by 0.9, and the final cost is the sum of the equipment cost, miscellaneous cost, and discount fuel cost.
BusCost.txt should look like this:
333 935.00
222 580.00
111 340.00
Note that the records are in reverse order. This is why we need the arrays for the bus numbers and final costs.


i'm not asking for the answers, but I am looking for some direction on this assignment
Write a C++ program
That would be a good start, writing some code. The instructions are quite detailed, something most assignments lack.
i'm not asking
Asking us a question about a specific issue you're having, once you actually tried to write code, would be the direction I would take.

http://www.cplusplus.com/doc/tutorial/ (tutorial)
Last edited on
you can pass an array to a function as a pointer or you can use hard coded constants. If you want to reuse the code and not hard code the constant, you have to pass the size as well.

int foo(int x[10])
or
int foo(int *x, int size)

be aware: changing the data inside x in the function changes it outside the function too. The data inside arrays isn't protected by a hidden copy.
Topic archived. No new replies allowed.