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.
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.
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)....