Class object contains struct vector that has a pointer to another class object – How to access it and print it?

  c++, oop, pointers, vector
Student.h
    struct Course_Records{
        Course* course;//how can I access this object? Should it be accessed from the Roster class or Student class?
        double grade;
    };
    class Student
    {
    
    private: 
        string fName;
        string lName;
        string phone;
        string ID;
        Date birthday;
        vector<Course_Records> tabel;
    
    
    Student.cpp
    //to print my student object
    ostream& operator <<(ostream& ostr, const Student& stud){
       ostr<<stud.get_fName()<<"t"<<stud.get_lName()<<"t"<<stud.get_id()<<"nBirthday: "
        <<stud.birthday<<"nStudent ID: "<<stud.ID<<"nPhone Number: "<<stud.phone<<endl;
//here I am trying to access Course_Records of a student object (not working)
       for (const Course_Records &a:stud.tabel){
            cout<<"Records: "<<*a.course<<endl;
        }
        return ostr;
    }
    
    Course.h
    struct Student_Records{
            Student* student;
            double grade;
    };
    class Course
    {
    private:
        string course_id;
        Date start;
        Date end;
        int enrolled;
        int capacity;
        vector<Student_Records> enrolled_students;
        int find_student(string id);
    
    Roster.h //this class is for storing Student objects in vector
    class Roster
    {
    private:
        vector <Student> students; 
    public:
        Roster();
        void add_students (Student& student);
        bool check_for_student (string student_id);
        Student find_student (string name) const;
        Student print_all_students(void)const;
        friend ostream& operator << (ostream& ostr, const Roster&roster);
    };
    
    class Roster_Course
    {
         vector <Course> courses;   
    public:
        Roster_Course();
        void add_course(Course& course);
        bool check_for_course(string course_id) const;
        Course find_course (string course_id) const;
        Course print_all_courses(void)const;
        friend ostream& operator << (ostream& osrt, const Roster_Course& roster);
        Course print_a_Course(Course& course);
    };
    Function.cpp
    void enrollment_file(string filename,Roster_Course& courses, Roster& students){
        Student temp_student;
        Course temp_course;
        fstream enrollment;
        string line, course_id, student_id, number;
        int num;
        enrollment.open(filename);
        if (!enrollment){
            cout<<"Issues with opening a file enrollment.txt"<<endl;
        }
        while (getline(enrollment, line)){
            istringstream ss (line);
            ss>>student_id;
            if (students.check_for_student(student_id)==true){
                temp_student = students.find_student(student_id);
            }
            else{
                cout<<"Sorry cannot enroll a student with a student ID: "<<student_id<<" becasue they are not in the system."<<endl;
            }
            ss>>number;
            num  = stoi(number);
            for (int i=0; i<num; i++){
                ss>>course_id;
                if (courses.check_for_course(course_id)==true){
                    temp_course = courses.find_course(course_id);             
                }
                temp_course.add_to_vector_student_records(&temp_student, 0);
                temp_student.add_to_vector_course_records(&temp_course, 0);
            }    
        }
        enrollment.close();
    }

I am very new to C++. I need to link the Course object to a struct vector in class Student and be able to print course object info that is linked to the student object.
Here is what I tried. It prints student object info but I can’t seem to access the vector that is part of the student object. The goal is to print a student and display a course they are registered in. Thanks!

Source: Windows Questions C++

LEAVE A COMMENT