Mar 3, 2013 at 4:15pm UTC
I am having trouble initialize an array of objects. This is what I have;
this are the constructors in the Student Class
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
Student()
{
info.firstName = "Mike" ;
info.lastName = "Jones" ;
info.id = "A0001121" ;
info.creditHours = 24;
info.GPA = 3.2;
}
Student(string first, string last, string ids, int credit, double gpa)
{
info.firstName = first;
info.lastName = last;
info.id = ids;
info.creditHours = credit;
info.GPA = gpa;
}
This is the array
1 2 3
Student student[NUM_STUDENTS] = {Student (Mark, Smith, A00356, 56, 3.8),
Student (John, Armstrong, A00054, 54, 4.0),
Student (Steven, Stewart, A00784, 86, 2.1)};
As of right now all the names of students, id and gpa give out an error message sayig that they are undefined
Last edited on Mar 3, 2013 at 4:17pm UTC
Mar 3, 2013 at 4:28pm UTC
Those names need to be strings:
1 2 3
Student student[NUM_STUDENTS] = {Student ("Mark" , "Smith" , "A00356" , 56, 3.8),
Student ("John" , "Armstrong" , "A00054" , 54, 4.0),
Student ("Steven" , "Stewart" , "A00784" , 86, 2.1)};
Wazzak
Last edited on Mar 3, 2013 at 4:29pm UTC
Mar 3, 2013 at 4:52pm UTC
I need to see the implementation of "Student " before I can diagnose the problem.
Wazzak
Last edited on Mar 3, 2013 at 4:53pm UTC
Mar 3, 2013 at 5:14pm UTC
A little more information,when trying to display; if I take out the in argument for the displayall function it does display the array of objects, but since the array is of 10 objects it displays the first three that I initialized and from 4 to 10 it displays what I put in the Student constructor repeatedly, I only want it to display the three objects that i initialized.
Mar 3, 2013 at 5:22pm UTC
What are you passing to displayall in the second argument?
You should be passing a 3. Sounds line you're passing 10.
Mar 3, 2013 at 5:25pm UTC
//I'm a beginner but:
I think you should do something like that:
int size=3;
displayall(student[NUM_STUDENTS],size);