Structure Student should have its own methods of saving and restoring from a file.
In this case it will be easy to write general methods of saving and restoring an object of class Course.
You will delegate saving and restoring of an object of type Student to it itself.
You should design a format of storing one object of Student. For example I would suggest to store one Student
in a line separating its members by semicolon. So each record of a file will contain information about one Student.
The corresponding methods could look the following way
ostream & Student::saveStudent( ostream &os ) const
return ( os << studentID << ';' << studentName << ';' << studentMark << '\n' );
istream & Student::readStudent( istream &is )
getline( is, record );
istringstream ss( record );
getline( ss, studentID, ';' );
getline( ss, studentName, ';' );
ss >> studentMark;
return ( is );
It is better to use a delimiter as for example a semicolon because member studentName may consist of two or more words.
These were methods of structure Student.
Class Course will have its own methods for saving and restoring records. But when it will need to store students of the course
it delegates the task to each element of dynamically allocated array od Students.
As I wrote above try to test the modified structure Student. And if tests will be successfully passed the structure
will be incorporated into class Course.
It is a good idea to design elements of a compound class separately. After you will be sure that Student can be written and
restored from a file then you will incorporate it into Course. Course will have a dynamically allocated array of Student.
You can use the same design of storing an object of type Course as for Student that is to save its members separated by a semicolon
in a line.
So a record of stored object of type Cource will look as
If the field numOfStudent of the record is not equal to zero then you in a loop will call method readStudent for each element of the
dynamically allocated array.
So the design of the method for restoring information about a course will look the following way
std::istream & readInfo( std::istream &is ) // I prefer to name the method as readInfo. You may use any other name
// Here is the stuff for reading one record describing the course in whole.
if ( numOfStudent != 0 )
theStudents = new Student[numOfStudent];
for ( int i = 0; i < numOfStudent; i++ ) theStudents.readStudent( is );
return ( is );
After the structure Student will have been tested you can switch to design methods of Course. I think you will need at least
two overload subscript operators to access an object of type Student to remoce it or modify according to your menu.