2/
a. That line I was trying to figured it out a way to printing out the name of the student Record after I read the data from text file to private member variable inside studentRecord
b. I was under assumption after looking through my note that it will print out the data of the private member of studentRecord.
|
Okay to print a non-array member variable from a class member function all you need to do is print the variable, you don't need any qualifiers.
cout << name << endl;
A class member function has direct access to all class member variables.
c. Name variable is string. |
No, name is an array of string not a string.
The purpose of the array to make sure the number of name the code should be read to private member should only be 10. |
This doesn't make any sense. If you want 10 student names you should have an array of studentRecord not one studentRecord with 10 different student names. Every studentRecord only needs one name.
1 2 3 4
|
int main() // In C++ main() must be defined to return an int!
{
// If you want 10 studentRecords this is where you need the array.
studentRecord student[a_row];
|
So your class definition should look more like:
1 2 3 4 5 6 7
|
...
class studentRecord
{
private:
string name; // No array needed here.
int grade[a_col]; // Only need to know the number of grades so only a single dimension is required.
|
Your print function should look more like:
1 2 3 4 5 6 7 8 9
|
void studentRecord::printStudentData(void)
{
cout << name << endl;
for (int c = 0; c < a_col; c++)
{ // Print out each grade.
cout << grade[c] << " ";
}
cout << endl;
}
|
Your "read" function should only read one student at a time (this function will need a major overhaul).
You should be opening your data files in main() (or some other non-member function) and then, in a loop, read each individual student's information.