Question: Write a C++ program that includes the following: Define a class Course in the header file Course.h. #ifndef COURSE_H #define COURSE_H #include using namespace std;

Write a C++ program that includes the following:

Define a class Course in the header file Course.h.

#ifndef COURSE_H #define COURSE_H #include  using namespace std; class Course { public: // Creates a Course with the specified name and maximum number of students allowed. Course(const string& course_name, int capacity); // Destructor, destory the dynamic array ~Course(); // Returns the course name. string get_course_name() const; // Adds a new student to the course. void add_student(const string& name); // Returns the array of students for the course. string* get_students() const; // Returns the number of students for the course. int get_number_of_students() const; // Prints the course information. void print() const; private: // The name of the course string course_name; //An array of students who take the course. students is a pointer for the array. string* students; // The number of students (default: 0). int number_of_students; // The maximum number of students allowed for the course. int capacity; }; #endif

Course.cpp

#include #include "Course.h"

using namespace std;

Course::Course(const string& course_name, int capacity) { number_of_students = 0; this->course_name = course_name; this->capacity = capacity; students = new string[capacity]; } Course::~Course() { delete[] students; } string Course::get_course_name() const { return course_name; } void Course::add_student(const string& name) { students[number_of_students] = name; number_ofstudents++; } string Course::get_students() const { return students; } int Course::get_number_of_students() const; { return number_of_students; }

void Course::print() const { cout << "The course information" << course_name() << students() << endl;

The main function is contained in the file lab06.cpp. The main function,

Prompts the user to enter the course name and course capacity.

Creates the object course1 with the course name and course capacity.

Prompts the user to enter a student name and adds the student in course1, until the entered student name is "exit".

Displays the information of course1, that is, print out the course name and the added student names.

The expected result:

Enter the course name: CSE202 Enter the course capacity: 20 Enter the student name: Taylor The student is added Enter the student name: Jim The student is added Enter the student name: Alice The student is added Enter the student name: exit The course information: CSE202 Taylor Jim Alice 

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!