Question: using c++. please show your output screen. Consider the class Course given in the appendix (last page in this file). Rewrite the addStudent function in
| using c++. please show your output screen. Consider the class Course given in the appendix (last page in this file). Rewrite the addStudent function in the Course.cpp to throw a runtime_error if the number of students exceeds the capacity. #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
Get step-by-step solutions from verified subject matter experts
