Write a (mathrm{C}++) program to implement a many-to-many association between objects of type course and of type

Question:

Write a \(\mathrm{C}++\) program to implement a many-to-many association between objects of type course and of type student. You may choose to build on your previous programs that encapsulate student. The manyto-many relationship should work as follows:

1. A given student may take zero to many courses, and a given Course will associate to many student instances. Encapsulate the course class to minimally contain a course name, a set of pointers to associated student instances, and a reference count to keep track of the number of student instances that are in the Course (this will equate to how many student instances point to a given instance of a course). Add the appropriate interface to reasonably encapsulate this class.

2. Add to your student class a set of pointers to the course instances in which that student is enrolled. Additionally, keep track of how many course instances a given student is currently enrolled. Add appropriate member functions to support this new functionality.
3. Model your many-sided associations using either a linked list of pointers (that is, the data part is a pointer to the associated object) or as an array of pointers to the associated objects. Note that an array will enforce a limit on the number of associated objects you can have, however, this may be reasonable because a given course can only accommodate a maximum number of students and a student may only enroll up to a maximum number of courses per semester. If you choose the array of pointers approach, make sure your implementation includes error checking to accommodate exceeding the maximum number of associated objects in each array.
4. Be sure to check for simple errors, such as trying to add Students to a course that is full, or adding too many courses to a student's schedule (assume there is an upper bound to five courses per semester).
5. Make sure your destructors do not delete the associated instances.
6. Introduce at least three student objects, each of which takes two or more courses. Additionally, make sure each course has multiple students enrolled. Print each student, including each Course in which they are enrolled. Likewise, print each course, showing each student enrolled in the course.

Fantastic news! We've Found the answer you've been seeking!

Step by Step Answer: