A couple of things I'd like to understand. I see you put the array
std::string courses[5] = { "Mathematics","Swedish","English","History","Physics" };
inside the Student class.
Now I know that in the real world, each student may be studying different subjects, so that might make some sense. But for this particular question, storing the same array many times doesn't necessarily seem like quite the right approach. I'm not clear on what the original question had to say on this. Do all the students study the same five subjects?
One other comment. There are at least two completely different things with the value
5
here.
There is the number of courses. There is the number of students. There is no reason why there should be exactly five students each studying five subjects. Again, I'm not sure what the original question has to say on this.
But when I look at the code and see something like
for (int i = 0; i < 5; i++)
there's no way to tell whether the 5 is the number of students or the number of courses. It means even if the code is correct, it might be correct for the wrong reason.
A usual way to avoid this sort of ambiguity is to avoid having numbers such as 5 scattered throughout the program. Instead, we would use a defined constant, like this:
1 2
|
const int numCourses = 3;
const int numStudents = 20;
|
I deliberately made them different just to illustrate that there could easily be such a situation.
Then in a loop, you would put something like
|
for (int i = 0; i < numStudents; i++)
|
or
|
for (int i = 0; i < numCourses; i++)
|
as appropriate. You would also use these constants in the array declarations such as
Student students[numStudents]
and so on.
Hope this helps to clarify things a little. Though I also hope you can put me right if I've misunderstood the question, I keep feeling I don't have enough information to work with.