Homework help? :-)

Hey everyone. I'm taking Data Structures right now. Just got an assignment back that I thought I understood and I got an F....owch. So I was hoping maybe someone/or multiple someones would be willing/want to help me with my new assignment for this week? :-)

My new assignment that I'll be starting on tonight (when I'm not on a work computer) is:

1. Read in a file of vehicle type and registration cost.
2. Sort that into an array. 1 for Autos and 1 for Motorcycles,
3. Calculate the highest registration cost, the lowest, and the average for each array.
4. Array size of 500 - produce an error if more than 500 lines.
5. Output to screen number of vehicles registered, high, low and average for each array.

So I'm thinking that I need to use getline() so that it reads a line at a time. Then have a loop to read the next line. Test something like, if (char == '\n'). Would that work?

Then for the array, I should just be able to make one of size 499 (to store 500 vehicles) and then I'm not sure how but search it for the high and low.

Am I even in the right direction?? o_O
Last edited on
Just a word of advice, most of us are not going to read this massive wall of text you just posted.

Narrow it down to what you're actually having a problem with, then we'll be more than happy to help.
Better? :-)
Would you consider this assignment to be harder than the one you got an F on? If so, I'm a little worried for you.

Try your best at an attempt and post here when you get stuck ;)
Then for the array, I should just be able to make one of size 499 (to store 500 vehicles) and then I'm not sure how but search it for the high and low.

Huh? If I had a basket that was sized to 4 apples, how could I expect it to hold 5?
Anyhow looping over an array is not difficult to find max, min, and average.
You could use a for loop to traverse a basic array.
More info on for loops (and other kinds of loops) here:
http://www.cplusplus.com/doc/tutorial/control/

I agree with L B, you should show us some attempt at writing the code yourself so we can help you with parts you get stuck on.
Last edited on
Well this is only my second programming class so it's not like I'm well experienced in this subject. I came to this website because it said for beginners and I was looking for some help since I obviously didn't understand the last assignment.

I thought arrays stored 1 value in the 0 slot. Therefore to hold 500 values, it would need 499 slots (plus the 0 makes 500)....
An array of size 1 holds one element at slot 0. An array of size 0 holds no elements, and it's not even allowed to dereference the pointer.
Okay so it would be array size 500 but the 500th value would be at location arrray[499] right?
Yes.
Topic archived. No new replies allowed.