Question: Consider the class Course given in the appendix . Rewrite the addStudent function in the Course.cpp to throw a runtime_error if the number of students

Consider the class Course given in the appendix . Rewrite the addStudent function in the Course.cpp to throw a runtime_error if the number of students exceeds the capacity

StackOfIntegers.h

#ifndef COURSE_H

#define COURSE_H

#include

using namespace std;

class Course

{

public:

Course(const string& courseName, int capacity);

~Course();

string getCourseName() const;

void addStudent(const string& name);

void dropStudent(const string& name);

string* getStudents() const;

int getNumberOfStudents() const;

private:

string courseName;

string* students;

int numberOfStudents;

int capacity;

};

#endif.

StackOfIntegers.cpp

#include

#include "Course.h"

using namespace std;

Course::Course(const string& courseName, int capacity)

{

numberOfStudents = 0;

this->courseName = courseName;

this->capacity = capacity;

students = new string[capacity];

}

Course::~Course()

{

delete [] students;

}

string Course::getCourseName() const

{

return courseName;

}

void Course::addStudent(const string& name)

{

students[numberOfStudents] = name;

numberOfStudents++;

}

void Course::dropStudent(const string& name)

{

// Left as an exercise

}

string* Course::getStudents() const

{

return students;

}

int Course::getNumberOfStudents() const

{

return numberOfStudents;

}

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!