#include "course.h" using namespace std; //default constructor Course::Course(){ cout << "Course() " << endl; this->name = "CS162"; this->roster = nullptr; this->enroll = 0; this->ins = "Roger"; } //non-default constructor Course::Course(string new_n, int new_e, string new_i){ cout << "non defaut Course(string, int, string) " << endl; this->name = new_n; this->enroll = new_e; this->roster = new string[this->enroll]; for (int i = 0; i < this->enroll; i++) this->roster[i] = "Some student"; this->ins = new_i; } //destructor Course::~Course(){ cout << "~Course()" << endl; if (this->roster != nullptr){ delete [] this->roster; this->roster = nullptr; } } //AOO Course& Course::operator=(const Course& obj){ cout << "AOO is called" << endl; //shallow copy this->name = obj.name; this->enroll = obj.enroll; this->ins = obj.ins; //this->roster = obj.roster; //we don't want //deep copy if (this->roster != nullptr) delete [] roster; this->roster = new string [this->enroll]; for (int i = 0; i < this->enroll; ++i) { this->roster[i] = obj.roster[i]; } return *this; } //Copy Constructor Course::Course(const Course& obj){ cout << "CC called " << endl; //shallow copy this->name = obj.name; this->enroll = obj.enroll; this->ins = obj.ins; //this->roster = obj.roster; //we don't want //deep copy this->roster = new string [this->enroll]; for (int i = 0; i < this->enroll; ++i) { this->roster[i] = obj.roster[i]; } } //getters string Course::get_name()const {return this->name;} int Course::get_enroll()const {return this->enroll;} string Course::get_ins() const{return this->ins;} string* Course::get_roster()const {return this->roster;} //setters void Course::set_name(const string n){ this->name = n; } void Course::set_roster(string* r) { this->roster = r; } void Course::set_enroll (const int e){ this->enroll = e; } void Course::set_ins (const string i) { this->ins = i; } void Course::display() const { cout << "--------------------" << endl; cout << "Name: " << this->name << endl; cout << "Enroll: " << this->enroll << endl; cout << "Instructor: " << this->ins << endl; for (int i = 0; i < enroll; ++i) { cout << "Student " << i+1 << ": " ; cout << this->roster[i] << endl; } cout << "--------------------" << endl; }