// e74.cpp // Example of an Heterogeneous linked list #include #include using namespace std; class Teacher{ friend class HetList; string name; int age,numOfStudents; Teacher * next; // Pointer to next object of Teacher public: Teacher(const string &, int, int); // Constructor void print() const; }; Teacher::Teacher(const string &new_name,int a,int nos) { name = new_name; age=a; numOfStudents=nos; } void Teacher::print() const // Print method of Teacher class { cout <<"Name: "<< name<<" Age: "<< age<< endl; cout << "Number of Students: " <next=head; else // if the list is empty t->next=0; // insert 1st element head=t; } // print the elements of the list void HetList::print() { Teacher *tempPtr; if (head) { tempPtr=head; while(tempPtr) { tempPtr->print(); tempPtr=tempPtr->next; } } else cout << "The list is empty" << endl; } // ----- Main Function ----- int main() { HetList theHetList; Teacher *t1=new Teacher("Teacher1",30,50); Principal *p1=new Principal("Principla1",60,40,"School1"); Teacher *t2=new Teacher("Teacher2",40,65); theHetList.insert(t1); theHetList.insert(p1); theHetList.insert(t2); theHetList.print(); return 0; }