/* People.cpp - example code for namespaces and Class arrays muh, CSE 374, 20sp */ #include "People.h" using namespace std; namespace student374 { void Student::getName() { getline( cin, name ); } void Student::getMarks() { cin >> marks; cin.ignore(); // clear buffer } void Student::displayInfo() { cout << "Name : " << name << endl; cout << "Marks : " << marks << endl; } void displayGreeting() { cout << "Welcome to the great student organizer!" << endl; } } namespace teacher374 { Teacher::Teacher () { title = "Professor"; } Teacher::Teacher (string name) { title = name; } Teacher::Teacher (const Teacher &origt) { title = origt.title; } void Teacher::getTitle() { getline( cin, title ); } void Teacher::displayInfo() { cout << "Title : " << title << endl; } ostream& operator<<(ostream& os, const Teacher& t1) { os << t1.title; return os; } void displayGreeting() { cout << "Welcome to the great teacher namer!" << endl; } } using namespace student374; using namespace teacher374; int main() { Student st[3]; //teacher374::Teacher dalmuti; Teacher dalmuti; //displayGreeting (); student374::displayGreeting (); for( int i=0; i<3; i++ ) { cout << "Initial Student " << i + 1 << endl; st[i].displayInfo(); } for( int i=0; i<3; i++ ) { cout << "Student " << i + 1 << endl; cout << "Enter name" << endl; st[i].getName(); cout << "Enter marks" << endl; st[i].getMarks(); } for( int i=0; i<3; i++ ) { cout << "Student " << i + 1 << endl; st[i].displayInfo(); } cout << "Enter teacher info:" << endl; dalmuti.getTitle(); cout << "Your teacher is: " << endl; dalmuti.displayInfo(); // looking at constructors string name="Karel"; Teacher head_ta(name); // copy Teacher lead_grader(head_ta); Teacher tas[2]; // initialization: cout << "Head TA: "; head_ta.displayInfo(); cout << "Lead grader is a copy of head TA: "; lead_grader.displayInfo(); cout << "Initialized array element 0: "; tas[0].displayInfo(); cout << "Initialized array element 1: "; tas[1].displayInfo(); cout << "Dalmuti is: " << dalmuti << endl; return 0; }