The Course Class
The code has been modified slightly and now uploaded to the site.

11.13.cpp
#include <iostream>
#include <string>
class Course{
public:
Course(const std::string& courseName, int capacity);
~Course();
Course(const Course&);
std::string getCourseName() const;
void addStudent(const std::string& name);
void dropStudent(const std::string& name);
std::string* getStudents() const;
int getNumberOfStudents() const;
void clear();
private:
std::string courseName;
std::string* students;
int numberOfStudents;
int capacity;
};
Course::Course(const std::string& courseName, int capacity){
this -> courseName = courseName;
this -> capacity = capacity;
students = new std::string[1];
numberOfStudents = 0;
}
Course::~Course(){
delete[] students;
}
Course::Course(const Course& v){
this -> numberOfStudents = v.numberOfStudents;
this -> students = new std::string[this -> numberOfStudents];
for (int i = 0; i < this -> numberOfStudents; i++){
this -> students[i] = v.students[i];
}
}
std::string Course::getCourseName() const{
return this -> courseName;
}
void Course::addStudent(const std::string& name){
std::string* arr = nullptr;
if (numberOfStudents == 0){
students[0] = name;
numberOfStudents += 1;
delete[] arr;
return;
}
else {
numberOfStudents += 1;
// std::cout << "Capacity" << numberOfStudents << std::endl;
arr = new std::string[numberOfStudents];
for (int i = 0; i < numberOfStudents - 1; i++){
arr[i] = students[i];
}
arr[numberOfStudents - 1] = name;
delete[] students;
students = arr;
}
}
void Course::dropStudent(const std::string& name){
std::string* arr = new std::string[numberOfStudents - 1];
// for (int i = 0; i < capacity; i++){
// arr[i] = students[i];
// }
int count = 0;
for (int i = 0; i < numberOfStudents; i++){
if (students[i] == name){
students[i] = "";
}
}
for (int i = 0; i < numberOfStudents; i++){
if (students[i] == ""){
continue;
}
arr[count] = students[i];
count++;
}
delete[] students;
students = arr;
numberOfStudents -= 1;
}
std::string* Course::getStudents() const{
return students;
}
int Course::getNumberOfStudents() const{
return numberOfStudents;
}
void Course::clear(){
std::string* empty = {};
delete[] students;
students = empty;
}
int main(){
Course course1("Data structures", 10);
Course course2("Database Systems", 15);
std::cout << course1.getCourseName() << std::endl;;
course1.addStudent("Peter Jones");
course1.addStudent("Brian Smith");
course1.addStudent("Anne Kennedy");
course1.dropStudent("Peter Jones");
course2.addStudent("Peter Jones");
course2.addStudent("Steve Smith");
std::cout << "Number of students in course1: " <<
course1.getNumberOfStudents() << "\n";
std::string* students = course1.getStudents();
for (int i = 0; i < course1.getNumberOfStudents(); i++){
std::cout << students[i] << ", ";
}
std::cout << "\nNumber of students in course2: " << course2.getNumberOfStudents() << "\n";
students = course2.getStudents();
for (int i = 0; i < course2.getNumberOfStudents(); i++){
std::cout << students[i] << ", ";
}
return 0;
}