Question: Using the codes below. in C++ Use three files ( .cpp, .h and main ) a) Implement a main program that prompts the user and

Using the codes below. in C++

Use three files ( .cpp, .h and main )

a) Implement a main program that prompts the user and prints the classes you are taking this trimester. Use a dynamic array and functions with arguments of the Course class.

b) Modify the Course, Instructor, and TextBook classes by adding attributes and member functions, described last.

c) Add the >>, << operators in each class. (ostream and istream)

//Contents of Instructor.h

#ifndef INSTRUCTOR

#define INSTRUCTOR

#include

#include

using namespace std;

// Instructor class

class Instructor

{

private: string lastName;

string firstName;

string office number;

public: // The default constructor stores empty strings

// in the string objects. Instructor()

{ set("", "", ""); }

// Constructor Instructor(string lname, string fname, string office)

{ set(lname, fname, office); }

// set function void set(string lname, string fname, string office)

{ lastName = lname;

firstName = fname;

officeNumber = office; }

// print function void print() const

{ cout << "Last name: " << lastName << endl; cout << "First name: " << firstName << endl; cout << "Office number: " << officeNumber << endl; }

}; #endif

//Contents of TextBook.h

#ifndef TEXTBOOK

#define TEXTBOOK

#include

#include

using namespace std;

// TextBook class

class TextBook

{

private: string title; 

string author;

string publisher;

public:

// The default constructor stores empty strings

// in the string objects.

TextBook()

{ set("", "", ""); }

// Constructor TextBook(string textTitle, string auth, string pub)

{ set(textTitle, auth, pub); }

// set function void set(string textTitle, string auth, string pub)

{ title = textTitle; author = auth; publisher = pub; }

// print function void print() const

{ cout << "Title: " << title << endl; cout << "Author: " << author << endl; cout << "Publisher: " << publisher << endl; }

}; #endif

//Contents of Course.h

#ifndef COURSE

#define COURSE

#include

#include

#include "Instructor.h"

#include "TextBook.h"

using namespace std;

class Course

{

private:

string courseName; // Course name

Instructor instructor; // Instructor

TextBook textbook; // Textbook

public:

// Constructor

Course(string course, string instrLastName,

string instrFirstName, string instrOffice,

string textTitle, string author,

string publisher)

{

// Assign the course name.

courseName = course;

// 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: ";

instructor.print();

cout << " Textbook Information: ";

textbook.print();

cout<< endl;

} }; #endif

// 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;

}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!