Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Overload the stream extraction operator >> for the class Module: class Module {

ID: 3628572 • Letter: O

Question

Overload the stream extraction operator >> for the class Module:
class Module
{
private:
string moduleName;
string moduleCode;
string lecturer;
int nrStudents;
public:

Module()
{
moduleName=lecturer=" ";
moduleCode="0000000";
nrStudents=0;
}

Module(string N ,string C,string L,int num)
{
moduleName=N;
moduleCode=C;
lecturer=L;
nrStudents=num;
}

void setmoduleName(string N)
{
moduleName=N;
}

void setmoduleCode(string N)
{
moduleCode=N;
}

void setlecturer(string N)
{
lecturer=N;
}

void setnrStudents(int N)
{
nrStudents=N;
}


string printmoduleName()
{
return moduleName;
}

string printmoduleCode()
{
return moduleCode;
}

string printlecturer()
{
return lecturer;
}

int printnrStudents()
{
return nrStudents;
}


};

to input values for an object of class Module either from the keyboard or from a file. Also overload the stream insertion operator << to output the data for a module either on the screen or to a file. Use separate compilation and write a program that inputs the name of a lecturer. The program should then find all the modules taught by that lecturer in a file named Modules.dat, and put those objects into an array. Assume that the file will never contain data for more than 20 modules. Use the array to determine the total number of students taught by the lecturer, as well as the average number of students per module taught by the lecturer. Display the names
of the modules, the total number of students taught by the lecturer, and the average number of students per module taught by the lecturer on the screen. Use the overloaded stream extraction operator >> to extract objects from file
Modules.dat. Use the following data for Modules.dat:
Introduction to Programming I
COS1511
Mrs Schoeman
534
Introduction to Programming I
COS1511
Mrs du Plessis
2534
Introduction to Programming II
COS1512
Mrs Schoeman
534
Introduction to Programming II
COS1512
Mrs du Plessis
2534

Explanation / Answer

friend istream& operator>>(istream& in, Module& mod) // input
{
string mn;
string mc;
string le;
int ns;

    in >> mn >> mc >> le >> ns;

setmoduleName(string mn);
setmoduleCode(string mc);
setlecturer(string le);
setnrStudents(int ns);
return in;
}