1

I have a class Course with information about a course in the university (like when in starts, how long it is, which day of the week, etc). Now I have to do a class Semester with an undefined length of courses :

class Semester {
    public :
       void addCourse(Course c);
    private :
       Course* courses;
}

So I'd like to know how can I do the addCourse function so that I can add infinite number of courses (class Course) to my class Semester ?

2

1 Answer 1

1

Take a look at the code below:

class Semester {
    public :
       void addCourse(Course *c) { courses.push_back(c); }
    private :
       std::vector<Course*> courses;
};
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.