void readRecord( Course *theCourse , int &sizeCourse , int &sizeStudent ){
string filename;
ifstream inFile;
cout << "Enter filename to be read : ";
getline( cin , filename );
inFile.open( filename.c_str());
if( inFile.fail() ){
cout << "Unable to open file ! Re-check !" << endl;
getch();
exit(1);
}
if ( inFile.is_open() ){
inFile >> sizeCourse;
inFile.ignore();
for( int i = 0 ; i < sizeCourse ; i++ ){
getline( inFile , theCourse[i].setCourseCode() );
getline( inFile , theCourse[i].getCourseName() );
inFile >> theCourse[i].getCredit();
inFile >> sizeStudent;
for ( int z = 0 ; z < sizeStudent ; z++ ){
getline( inFile , theCourse[z].getStudentName());
inFile >> theCourse[z].getStudentMarks();
}
}
}
}
i'm not really sure when i read the file name is using accessor or mutator.
can someone give an advise and teach me? and
sizeStudent problem , should i using theCourse[i].sizeStudent or just pass by ampersand?
Your question is not very clear. Since readRecord is not a member of a class it's neither a mutator nor an accessor. If it were a member of a class it would be a mutator.
But, somehow I suspect that's not what you wanted to know.
All of those theCourse[i].get..() functions look suspicious in a 'read from file' operation.
Should i using theCourse[i].sizeStudent or just pass by ampersand?
It's "pass by reference" not "pass by ampersand." You would only pass it in by reference if you needed to modify it in the function and have the change reflected in the calling code. Honestly, it looks like it should be a local variable in this code.