Why this c++ code doesn’t work? (lab on Aggregation)

  aggregation, c++

Why this code doesn’t execute anything after the function course.addStudent() executed in the main?
I think the problem in the this line

studentsEnrolled[counter] = Student;

But I can’t figure out why it’s worng!

#include <iostream>
#include "string.h"

using namespace std;

class FCIIdentity
{
private:
    string id;
    string fciMail;

public:
    FCIIdentity(string d, string fcm)
    {
        id = d;
        fciMail = fcm;
    }
    void setid(string d){ id =d; }
    string getid() { return id;}
    void setmail(string m) { fciMail = m; }
    string getmail() { return fciMail; }
    void print()
    {
        cout << "id: " << id;
        cout << "mail: " << fciMail;
    }
};

class FCIStudent
{
private:
    string name;
    int age;

public:
    FCIStudent();
    FCIIdentity* fciID;
    FCIStudent(string n, int a, FCIIdentity f)
    {
        name = n;
        age = a;
        fciID = &f;
    }

    //FCIIdentity* getobject(){ return fciID; }
    void setage(int a){ age = a; }
    int getage(){return age; }
    void setname(string n){ name = n; }
    string getname(){return name; }
    void printdetails()
    {
        cout << "Name: " << name << endl;
        cout << "Age: " << age << endl;
        cout << "ID: " << fciID->getid() << endl;
        cout << "mail: " << fciID->getmail() << endl;
    }
};


class FCICourse
{
private:
    string name;
    int counter = 0;
    int maxNumberOfStudentsCanBeEnrolled;
    FCIStudent* studentsEnrolled;

public:
    FCICourse();
    FCICourse( string names, int maxStudentsNum)
    {
        name = names;
        maxNumberOfStudentsCanBeEnrolled = maxStudentsNum;
    };
    void Setname(string n){ name = n; };
    string Getname(){return name; };
    void Setmaxstudents(int NoOfStudent ){ NoOfStudent = maxNumberOfStudentsCanBeEnrolled; };
    int Getmaxstudents(){return maxNumberOfStudentsCanBeEnrolled; };

    bool addStudent(FCIStudent &Student)
    {
        studentsEnrolled[counter] = Student;
        counter++;
        return true;
    }

    void printAllStudentsEnrolled()
    {
        for(int i=0; i<counter; i++)
        {
            studentsEnrolled[i].printdetails();
            cout << endl;
        }
    }

};


int main()
{
    //Add the first student
    FCIIdentity m("20200818", "[email protected]");
    FCIStudent s("malek", 20, m);
    s.printdetails();
    FCICourse course("OOP", 200);
    course.addStudent(s);

    cout << "Why this doesn't executed?!!";
    
    //Add a second student
    FCIIdentity m2("20200124", "[email protected]");
    FCIStudent s2("Ahmed", 10, m2);
    s2.printdetails();

    return 0;
}

Source: Windows Questions C++

LEAVE A COMMENT