| sabi20 (22) | |||
|
Dynamically create an array of Student structures as declared below to store the student data from the file. There are 10 students and each student has five grades. What do these instructions mean. Do I have to make 10 different structures like the one below or is it asking me to do something else. Can somebody please explain this to me?
| |||
|
Last edited on
|
|||
| kbw (5522) | ||
| ||
|
|
||
| ajh32 (163) | |||||
If I were to create an array to contain 10 int's I would write:
If I wanted an array to contain 10 Foo's I would write:
Then you can add up to 10 of the type you have declared the array of, i.e. 10 int's or Foo's at index [1..9] HTH | |||||
|
|
|||||
| MikeyBoy (235) | |
By "dynamically", the instructions are saying that you need to dynamically allocate memory to store the structures. As kbw says, you need to use new.If you don't understand the meaning of what I've just written, you need to hit your textbooks. | |
|
|
|
| ajh32 (163) | |
| @MikeyBoy - I know what it means, I am trying to help him by starting with how to declare an array of a certain type and size. | |
|
|
|
| ajh32 (163) | |||||
In case you haven't worked it out yet:
But the struct would be better defined with a default constructor, as follows so that each member of the struct is initialised:
HTH | |||||
|
|
|||||
| kbw (5522) | |
|
ajh32 Please do not do peoples homework on the forum. It doesn't help anyone. | |
|
|
|
| sabi20 (22) | |||
|
yea i understand that but what im really confused about is, how would i access each of the 5 grades for 10 students. This is how the file looks like, with 10 sets of different students: 1020526770 Elizabeth Anderson 68 78 70 66 60 so for example if i wanted to print the 2nd students 4th grade, would it be something like this?
| |||
|
Last edited on
|
|||
| MikeyBoy (235) | |
Yes, that's exactly right. studentInfo[1] will give you the second student in the array, the .grades will give you the grades array for that student, and then the [3] will give you the 4th grade in that array.Of course, somewhere between those two lines, you'll have to put the values into the Student objects, but I'm sure you've worked that out already! | |
|
Last edited on
|
|