Script started on Sun Dec 05 17:06:49 1999 pluto[5:06pm] [~/c++/]> cat stu-teach.h // stu-teach.h // Student and Teacher class // delcarations #include // prevent multiple inclusions of header file #ifndef stu_teach_h #define stu_teach_h class Student { public: Student(char * = ""); void setName(char *); void setYear(int); void print(); private: char name[25]; int year; }; class Teacher { public: Teacher(char * = ""); void setName(char *); int addCourse(); // add a course void print(); private: char name[25]; int numcourses; // number of courses teaching static int MaxCourses; // max numer of courses // any Teacher could teach }; #endif pluto[5:06pm] [~/c++/]> cat stu-teach.cc // stu-teach.cc // Student and Teacher class // implementation #include #include #include "stu-teach.h" Student::Student(char *newname) { setName(newname); } void Student::setName(char *inname) { strcpy(name, inname); } void Student::setYear(int inyear) { year = (inyear > 0 && inyear < 7) ? inyear : 1; } void Student::print() { cout << "Student: " << name << endl; } // Implementation of the Teacher class // initialize static data member at file scope int Teacher::MaxCourses = 3; Teacher::Teacher(char * newname) { setName(newname); } void Teacher::setName(char * inname) { strcpy(name, inname); } int Teacher::addCourse() { if (numcourses < MaxCourses) { numcourses++; return 1; // indicates success } else return 0; } void Teacher::print() { cout << name << endl; } pluto[5:07pm] [~/c++/]> cat stu-teach-drive.cc // Simple driver for // Student and Teacher class #include #include "stu-teach.h" main() { Teacher t1("Jane Doe"); Student s1("Fred Smith"); Student s2("Amanda Franks"); cout << "The class has the following teacher: "; t1.print(); s1.print(); s2.print(); } pluto[5:07pm] [~/c++/]> CC -compat stu-teach-drive.cc stu-teach.cc stu-teach-drive.cc: stu-teach.cc: pluto[5:07pm] [~/c++/]> a.out The class has the following teacher: Jane Doe Student: Fred Smith Student: Amanda Franks pluto[5:07pm] [~/c++/]> exit exit script done on Sun Dec 05 17:08:07 1999