#include "university.h" #include "professor.h" #include "student.h" #include #include #include using namespace std; //------------------------------------------------------- ostream &operator<< (ostream &output, const Professor &p) { output << "Professor: " << p.first_name << " " << p.last_name << " is teaching " << p.num_classes << " classes."; return output; } //------------------------------------------------------- istream &operator>> (istream &input, Professor &p) { input >> p.first_name >> p.last_name >> p.num_classes; return input; } //------------------------------------------------------- ostream &operator<< (ostream &output, const Student &s) { output << "Student: " << s.first_name << " " << s.last_name << " (id=" << s.id << ") has a " << s.gpa << " gpa."; return output; } //------------------------------------------------------- istream &operator>> (istream &input, Student &s) { input >> s.id >> s.first_name >> s.last_name >> s.gpa; return input; } //------------------------------------------------------- ostream &operator<< (ostream &output, const University &u) { output << "University has " << u.num_professors << " professors" << endl; output << " and " << u.num_students << " students" << endl << endl; output << "It is currently " << SEMESTERS[u.current_semester] << " semester" << endl; u.PrintProfessors(); u.PrintStudents(); return output; } //------------------------------------------------------- istream &operator>> (istream &input, University &u) { input >> u.num_professors; input >> u.num_students; input >> u.current_semester; int i; cout << "PROFS" << endl; u.professors = new Professor[u.num_professors]; cout << "STUS" << endl; u.students = new Student[u.num_students]; for (i=0; i < u.num_professors; i++) input >> u.professors[i]; for (i=0; i < u.num_students; i++) input >> u.students[i]; return input; } //------------------------------------------------------- //------------------------------------------------------- void main (void) { University u(0,0); cout << u; ifstream ifp; ifp.open("university.txt", ios::in); if (!ifp) { cerr << "Error - file could not be opened" << endl; exit(1); } ifp >> u; ifp.close(); cout << u << endl; u.RunSemester(); }