INSTRUCTOR.H #ifndef INSTRUCTOR #define INSTRUCTOR #include #include using namespace std; // Constants for array sizes const int NAME_SIZE = 51; const int OFFICE_NUM_SIZE = 21; // Instructor class class Instructor { private: char lastName[NAME_SIZE]; // Last name char firstName[NAME_SIZE]; // First name char officeNumber[OFFICE_NUM_SIZE]; // Office number public: // The default constructor stores empty strings // in the char arrays. Instructor() { set("", "", ""); } // Constructor Instructor(char *lname, char *fname, char *office) { set(lname, fname, office); } // set function void set(const char *lname, const char *fname, const char *office) { strncpy(lastName, lname, NAME_SIZE); lastName[NAME_SIZE - 1] = '\0'; strncpy(firstName, fname, NAME_SIZE); firstName[NAME_SIZE - 1] = '\0'; strncpy(officeNumber, office, OFFICE_NUM_SIZE); officeNumber[OFFICE_NUM_SIZE - 1] = '\0'; } // print function void print() const { cout << "Last name: " << lastName << endl; cout << "First name: " << firstName << endl; cout << "Office number: " << officeNumber << endl; } }; #endif TEXTBOOK.H #ifndef TEXTBOOK #define TEXTBOOK #include #include using namespace std; // Constant for array sizes const int PUB_SIZE = 51; // TextBook class class TextBook { private: char title[PUB_SIZE]; // Book title char author[PUB_SIZE]; // Author name char publisher[PUB_SIZE]; // Publisher name public: // The default constructor stores empty strings // in the char arrays. TextBook() { set("", "", ""); } // Constructor TextBook(char *textTitle, char *auth, char *pub) { set(textTitle, auth, pub); } // set function void set(const char *textTitle, const char *auth, const char *pub) { strncpy(title, textTitle, PUB_SIZE); title[NAME_SIZE - 1] = '\0'; strncpy(author, auth, PUB_SIZE); author[NAME_SIZE - 1] = '\0'; strncpy(publisher, pub, PUB_SIZE); publisher[OFFICE_NUM_SIZE - 1] = '\0'; } // print function void print() const { cout << "Title: " << title << endl; cout << "Author: " << author << endl; cout << "Publisher: " << publisher << endl; } }; #endif COURSE.H #ifndef COURSE #define COURSE #include #include #include "Instructor.h" #include "TextBook.h" using namespace std; // Constant for course name const int COURSE_SIZE = 51; class Course { private: char courseName[COURSE_SIZE]; // Course name Instructor instructor; // Instructor TextBook textbook; // Textbook public: // Constructor Course(const char *course, const char *instrLastName, const char *instrFirstName, const char *instrOffice, const char *textTitle, const char *author, const char *publisher) { // Assign the course name. strncpy(courseName, course, COURSE_SIZE); courseName[COURSE_SIZE - 1] = '\0'; // Assign the instructor. instructor.set(instrLastName, instrFirstName, instrOffice); // Assign the textbook. textbook.set(textTitle, author, publisher); } // print function void print() const { cout << "Course name: " << courseName << endl << endl; cout << "Instructor Information:\n"; instructor.print(); cout << "\nTextbook Information:\n"; textbook.print(); cout << endl; } }; #endif MAIN.CPP // This program demonstrates the Course class. #include "Course.h" int main() { // Create a Course object. Course myCourse("Intro to Computer Science", // Course name "Kramer", "Shawn", "RH3010", // Instructor info "Starting Out with C++", "Gaddis", // Textbook title and author "Addison-Wesley"); // Textbook publisher // Display the course info. myCourse.print(); return 0; }