Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Machine Learning And Knowledge Discovery In Databases European Conference Ecml Pkdd 2010 Barcelona Spain September 2010 Proceedings Part 1 Lnai 6321

Authors: Jose L. Balcazar ,Francesco Bonchi ,Aristides Gionis ,Michele Sebag

2010th Edition

364215879X, 978-3642158797

More Books

Students also viewed these Databases questions