C++ – creating association class to store information about the relationship between two other classes

  associations, c++, class, inheritance, uml

So I’m trying to implement an association class called Taken where each Taken object will represent
the fact that a specific student has taken a specific course, and it will store the grade that the student earned in that course. The issue is I’m having trouble actually implementing the association. I’ve looked at examples online, and this is what I’ve tried to recreate with just Taken and Course. I’m still getting errors saying that certain variables like ‘code’ from Course.h are private. I’m wondering if I’m missing anything/doing anything wrong? I’m not trying to implement a bidirectional association but rather implement an association class.

The association between the 3 classes is illustrated in the diagram below.

#ifndef TAKEN_H
#define TAKEN_H

#include "Course.h"
#include "Student.h"

class Course;
class Student;

class Taken{
  public:
    Taken(Student*, Course*, string = "X");
    ~Taken();
    Student* getStu();
    Course* getCou();
    void print();
    
  private:
    string grade;
    Student* student;
    Course* course;

};


#ifndef COURSE_H
#define COURSE_H

class Taken;
class Course{
  public:
    Course(int id=0, string="X", int=0, char = '0', string="X", string="X");
    ~Course();
    bool lessThan(Course*);
    int getCourseCode();
    void print();
  private:
    int id;
    string subject;
    int code;
    char section;
    string term;
    string instructor;

};

#endif

enter image description here

Source: Windows Questions C++

LEAVE A COMMENT