OOP pointer

closed account (iN8poG1T)
Hi, I have a question regarding OOP. can someone guide me how to do number 4 b, c, d? since this is my first exercise on OOP. I do not really master the subject

1. Create a class named Staff with at least the following data members (id, name, birthdate, education, certification, address, and main language,).

2. Design a proper Address class that stores and manipulates the address elements.

3. The Hospital class must have at least the following members (Name as a string, Address as an Address object, phone, fax, e-mail, an array of departments, and any fields you feel necessary)

4. The Department class has at least the following members (name, an array of Staff, number of staff, and any number of data fields you find necessary).

5. In the main function:

a. Create 7 Address objects and initialize them with some data.
b. Create 6 objects of Staff and initialize them with data of your choice. Add an address object to each staff object created.
c. Create 2 department objects. Add the first 3 Staff objects to the first department object and the last three to the second department.
d. Create an object of type Hospital. Initialize the address of the hospital to the 7th address. Add the two departments to the hospital.
e. Display all the components you created with proper functions and messages.


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
#include <iostream>
#include <memory>

using namespace std;

class Staff;
class Address;
class Department;



class Hospital
{
private :
    string hName;
    unique_ptr<Address>hosp;
    unique_ptr<Department[]> d;
    string phone;
    string email;

public :
    Hospital();
    void setHospital(string hName, string phone, string email);
    string getHName();
    string getPhone();
    string getEmail();
    ~Hospital();

};

Hospital :: Hospital (){}
Hospital :: ~Hospital (){}

void Hospital :: setHospital(string hName, string phone,string email)
{
    this ->hName= hName;
    this ->phone =phone;
    this ->email=email;
}

string Hospital :: getHName()
{
     return hName;
}

string  Hospital :: getPhone()
{
    return phone;
}
string Hospital :: getEmail()
{
    return email;
}

class Staff
{
private :
    string id;
    string bdate;
    string name;
    string edu;
    string cert;
    string add;
    string lang;

public :
    Staff();
    void setStaff(string id,string bdate, string name, string edu, string cert, string add, string lang);
    string getID();
    string getDate ();
    string getName();
    string getEdu();
    string getCert();
    string getAdd();
    string getLang();
    ~Staff();


};

Staff :: Staff (){}
Staff :: ~Staff (){}

void Staff :: setStaff(string id, string bdate, string name, string edu, string cert, string add, string lang)
  {
      this ->id = id;
      this ->bdate = bdate;
      this ->name =name;
      this ->edu =edu;
      this ->cert=cert;
      this ->add=add;
      this ->lang=lang;
  }


string Staff :: getID()
{
    return id;
}

string Staff :: getDate()
{
    return bdate;
}
string Staff :: getName()
{
    return name;
}
string Staff :: getEdu()
{
    return edu;
}
string Staff :: getCert()
{
    return cert;
}
string Staff :: getAdd()
{
    return add;
}
string Staff :: getLang()
{
    return lang;
}


class Address
{
private :
    string num;
    string street;
    string city;
    string state;
    string postcode;
    string country;

public :
     Address();
     void setAdd(string num,string street, string city, string state, string postcode, string country);
     string getNum();
     string getStreet();
     string getCity();
     string getState();
     string getPostcode();
     string getCountry();
     ~Address();

};

Address :: Address (){}
Address :: ~Address (){}

void Address :: setAdd(string num,string street, string city, string state, string postcode, string country)
{
      this ->num = num;
      this ->street =street;
      this ->city =city;
      this ->state =state;
      this ->postcode=postcode;
      this ->country=country;

}

string Address :: getNum()
{
    return num;
}
string Address :: getStreet()
{
    return street;
}
string Address :: getCity()
{
    return city;
}
string Address :: getState()
{
    return state;
}
string Address :: getPostcode()
{
    return postcode;
}
string Address :: getCountry()
{
    return country;
}

class Department
{
private :
    string DName;
    shared_ptr<Staff[]>s;
    int numOfStaff;

public :
    Department();
    void setDepartment(string DName,int numOfStaff);
    string getDName();
    string getStaff();
    int getNumOfStaff();
    ~Department();

};

Department :: Department (){}
Department :: ~Department (){}

void Department :: setDepartment(string DName, int numOfStaff)
{
    this ->DName= DName;
    this ->numOfStaff =numOfStaff;
}

string Department:: getDName()
{
    return DName;
}

int Department :: getNumOfStaff ()
{
    return numOfStaff;
}


int main ()
{
     unique_ptr<Address[]>addObj = make_unique<Address[]>(7);


         addObj[0].setAdd("1", "AA", "TALL", "SL", "24000", "CHINA");
         addObj[1].setAdd("2", "BB", "LONG", "MZ", "25000", "CAMBODIA");
         addObj[2].setAdd("3", "CC", "BONE", "SL", "33000", "MANILA");
         addObj[3].setAdd("4", "DD", "LEGS", "PR", "55000", "PARIS");
         addObj[4].setAdd("5", "EE", "HAND", "SL", "77000", "USA");
         addObj[5].setAdd("6", "FF", "HEAD", "MK", "89000", "UK");
         addObj[6].setAdd("7", "GG", "NAIL", "SL", "70000", "KOREA");

        for(int i = 0; i < 7; i++)
         {
               cout << addObj[i].getNum() << ", " << addObj[i].getStreet() << ", " << addObj[i].getCity() << ", "<< addObj[i].getState() << ", "<< addObj[i].getPostcode() << ", " << addObj[i].getCountry() << endl;

         }
     cout <<endl;

     unique_ptr<Staff[]>staffObj = make_unique<Staff[]>(6);

     unique_ptr<Department[]>deptObj = make_unique<Department[]>(2);

     shared_ptr<Hospital>objHosp = make_shared<Hospital>();

}
Last edited on
Have you studied initialization lists yet? For example:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
#include <string>
#include <vector>

class Staff
{
   // Whatever.
};

class Department
{
    private :
        std::string name;
        std::vector<Staff> staff;
    public :
        Department() = default;
        Department(const std::string& Dname) : name(Dname) {}
        // Using constructor initialization list. 
        Department(const std::string& Dname, const std::vector<Staff>& personal )
                        : name(Dname), staff(personal) {}
        void add_staff_member(const Staff& staff_member);
        std::string getDName() const { return name;}
        int getNumOfStaff() const { return staff.size();}
//    ~Department(); // Not needed.

};



Why all the pointers in main()? Those pointers are not really necessary (and are not required in your assignment text), use a std::vector instead and regular non-pointer class instances.

You really don't need any of the destructors since they are not doing anything.

You should also pass those std::string by reference/const reference into your functions to reduce the amount of unnecessary copying.


You can get rid of that Javascript style syntax (this->) just by giving your parameters smarter names.
You can also get rid of your empty constructors and destructors, since the compiler will write them for you (your empty ones prevent the compiler from doing that).

If you changed the order of your class this way:
- Address
- Staff
- Department
- Hospital
you wouldn’t need to forward declare them anymore.

Methods which don’t modify the class should be declared const (e.g. getters).

About the habit of initializing a class by a function different from the constructor:
http://www.modernescpp.com/index.php/c-core-guidelines-constructors
A class having a init method is asking for trouble.
[omissis]
The user might mistakenly invoke read before init or might just forget to invoke init.

(Of course there are exceptions: https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#c50-use-a-factory-function-if-you-need-virtual-behavior-during-initialization )

Please, tell us about std::vectors, if you can use them or not.
Last edited on
closed account (iN8poG1T)
@Enoizat actually my professor did not tell use weather we can use vector or not, he only assign us to try this. lets say if we can, where should i put it?
where should i put it?

Where ever you now have your arrays. I showed an example in my last post.

closed account (iN8poG1T)
This is my code after following your advice using the initialization list but i still have lots error

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
#include <iostream>
#include <memory>
#include <vector>

using namespace std;

class Address
{
private :
    string num;
    string street;
    string city;
    string state;
    string postcode;
    string country;

public :
     Address();
     Address(const string& a_num,const string& a_street, const string& a_city, const string& a_state, const string& a_postcode, const string& a_country)
     : num(a_num), street(a_street), city(a_city), state(a_state),postcode(a_postcode),country(a_country){}
     string getNum()const {return num;}
     string getStreet()const {return street;}
     string getCity()const {return city;}
     string getState()const {return state;}
     string getPostcode()const {return postcode;}
     string getCountry()const {return country;}


};
class Staff
{
private :
    string id;
    string bdate;
    string name;
    string edu;
    string cert;
    string add;
    string lang;

public :
    Staff();
    Staff(const string& s_id, const string& s_date, const string& s_name, const string& s_edu, const string& s_cert, const string& s_add, const string& s_lang )
          : id(s_id), bdate(s_date),name(s_name), edu(s_edu),cert(s_cert), add(s_add), lang(s_lang){}
    string getID() const {return id;}
    string getDate ()const {return bdate;}
    string getName()const {return name;}
    string getEdu()const {return edu;}
    string getCert()const {return cert;}
    string getAdd()const {return add;}
    string getLang()const {return lang;}
};



class Department
{
    private :
        string name;
        vector<Staff> staff;
    public :
        Department() = default;
        Department(const string& Dname) : name(Dname) {}
        Department(const string& Dname, const vector<Staff>& personal )
                        : name(Dname), staff(personal) {}
        void add_staff_member(const Staff& staff_member);
        string getDName() const { return name;}
        int getNumOfStaff() const { return staff.size();}

};


class Hospital
{
private :
    string hName;
    vector<Address>address;
    vector<Department> department;
    string phone;
    string email;

public :
    Hospital();
    Hospital(const string& HName, const string& HPhone, const string& HEmail)
            :hName(HName), phone(HPhone), email(HEmail){}
    Hospital(const string& HName, const string& HPhone, const string& HEmail,const vector<Address>& personal, const vector<Department>& personal)
            :hName(HName), phone(HPhone), email(HEmail), address(personal), department(personal){}
    string getHName();
    string getPhone();
    string getEmail();
    ~Hospital();

};



int main ()
{
     unique_ptr<Address[]>addObj = make_unique<Address[]>(7);


         addObj[0].setAdd("1", "AA", "TALL", "SL", "24000", "CHINA");
         addObj[1].setAdd("2", "BB", "LONG", "MZ", "25000", "CAMBODIA");
         addObj[2].setAdd("3", "CC", "BONE", "SL", "33000", "MANILA");
         addObj[3].setAdd("4", "DD", "LEGS", "PR", "55000", "PARIS");
         addObj[4].setAdd("5", "EE", "HAND", "SL", "77000", "USA");
         addObj[5].setAdd("6", "FF", "HEAD", "MK", "89000", "UK");
         addObj[6].setAdd("7", "GG", "NAIL", "SL", "70000", "KOREA");

        for(int i = 0; i < 7; i++)
         {
               cout << addObj[i].getNum() << ", " << addObj[i].getStreet() << ", " << addObj[i].getCity() << ", "<< addObj[i].getState() << ", "<< addObj[i].getPostcode() << ", " << addObj[i].getCountry() << endl;

         }
     cout <<endl;

     unique_ptr<Staff[]>staffObj = make_unique<Staff[]>(6);

     unique_ptr<Department[]>deptObj = make_unique<Department[]>(2);

     shared_ptr<Hospital>objHosp = make_shared<Hospital>();

}

What don't you understand about your error messages?

A quick couple of points about initialization lists,
1: The order of parameters matter. Each item in the initialization list should be in the same order as defined in the class definition.
2. The type of variables need to match what is expected from the definition.

C++ has an awkward syntax, so keeping the code tidy helps a lot - but of course your greatest friend is the compiler:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
// Hi, I have a question regarding OOP. can someone guide me how to do number
// 4 b, c, d? since this is my first exercise on OOP. I do not really master
// the subject
// 1. Create a class named Staff with at least the following data members (id,
//    name, birthdate, education, certification, address, and main language,).
// 2. Design a proper Address class that stores and manipulates the address
//    elements.
// 3. The Hospital class must have at least the following members (Name as a
//    std::string, Address as an Address object, phone, fax, e-mail, an array of
//    departments, and any fields you feel necessary)
// 4. The Department class has at least the following members (name, an array
//    of Staff, number of staff, and any number of data fields you find
//    necessary).
// 5. In the main function:
//    a. Create 7 Address objects and initialize them with some data.
//    b. Create 6 objects of Staff and initialize them with data of your choice.
//       Add an address object to each staff object created.
//    c. Create 2 department objects.
//       Add the first 3 Staff objects to the first department object and the
//       last three to the second department.
//    d. Create an object of type Hospital.
//       Initialize the address of the hospital to the 7th address.
//       Add the two departments to the hospital.
//    e. Display all the components you created with proper functions and
//       messages.
#include <iostream>
#include <memory>
#include <vector>


class Address
{
public :
    Address();
    Address(const std::string& a_num,
            const std::string& a_street,
            const std::string& a_city,
            const std::string& a_state,
            const std::string& a_postcode,
            const std::string& a_country)
        : num (a_num)
        , street (a_street)
        , city (a_city)
        , state (a_state)
        , postcode (a_postcode)
        , country (a_country)
    {
    }

    std::string getNum() const {return num;}
    std::string getStreet() const {return street;}
    std::string getCity() const {return city;}
    std::string getState() const {return state;}
    std::string getPostcode() const {return postcode;}
    std::string getCountry() const {return country;}

private :
    std::string num;
    std::string street;
    std::string city;
    std::string state;
    std::string postcode;
    std::string country;
};



class Staff
{
public :
    Staff();
    Staff(const std::string& s_id,
          const std::string& s_date,
          const std::string& s_name,
          const std::string& s_edu,
          const std::string& s_cert,
          const std::string& s_add,
          const std::string& s_lang)
        : id (s_id)
        , bdate (s_date)
        , name (s_name)
        , edu (s_edu)
        , cert (s_cert)
        , add (s_add)
        , lang (s_lang)
    {
    }

    std::string getID() const    { return id; }
    std::string getDate () const { return bdate; }
    std::string getName() const  { return name; }
    std::string getEdu() const   { return edu; }
    std::string getCert() const  { return cert; }
    std::string getAdd() const   { return add; }
    std::string getLang() const  { return lang; }

private :
    std::string id;
    std::string bdate;
    std::string name;
    std::string edu;
    std::string cert;
    std::string add;    // Are you sure this is not required to be an Address?
    std::string lang;
};



class Department
{
public :
    Department() = default;
    Department(const std::string& d_name)
        : name (d_name)
    {
    }
    Department(const std::string& d_name, const std::vector<Staff>& personal)
        : name(d_name)
        , staff(personal)
    {
    }

    void add_staff_member(const Staff& staff_member);
    std::string getName() const { return name; }
    int getNumOfStaff() const { return staff.size(); }

private :
    std::string name;
    std::vector<Staff> staff;
};


class Hospital
{
public :
    Hospital();
    Hospital(const std::string& h_name,
             const std::string& h_phone,
             const std::string& h_email)
        : name (h_name)
        , phone (h_phone)
        , email (h_email)
    {
    }
    Hospital(const std::string& h_name,
             const std::string& h_phone,
             const std::string& h_email,
             const std::vector<Address>& personal,
             const std::vector<Department>& personal)
        : name (h_name)
        , phone (h_phone)
        , email (h_email)
        , address (personal)
        , department (personal)
    {
    }
    std::string getHName();
    std::string getPhone();
    std::string getEmail();
    ~Hospital();

private :
    std::string name;
    std::vector<Address> address;
    std::vector<Department> department;
    std::string phone;
    std::string email;
};


int main ()
{
    std::unique_ptr<Address[]>addObj = std::make_unique<Address[]>(7);


    addObj[0].setAdd("1", "AA", "TALL", "SL", "24000", "CHINA");
    addObj[1].setAdd("2", "BB", "LONG", "MZ", "25000", "CAMBODIA");
    addObj[2].setAdd("3", "CC", "BONE", "SL", "33000", "MANILA");
    addObj[3].setAdd("4", "DD", "LEGS", "PR", "55000", "PARIS");
    addObj[4].setAdd("5", "EE", "HAND", "SL", "77000", "USA");
    addObj[5].setAdd("6", "FF", "HEAD", "MK", "89000", "UK");
    addObj[6].setAdd("7", "GG", "NAIL", "SL", "70000", "KOREA");

    for(int i = 0; i < 7; i++)
    {
        std::cout << addObj[i].getNum() << ", "
                  << addObj[i].getStreet() << ", "
                  << addObj[i].getCity() << ", "
                  << addObj[i].getState() << ", "
                  << addObj[i].getPostcode() << ", "
                  << addObj[i].getCountry() << '\n';

    }
    std::cout << '\n';

    std::unique_ptr<Staff[]>staffObj = std::make_unique<Staff[]>(6);

    std::unique_ptr<Department[]>deptObj = std::make_unique<Department[]>(2);

    std::shared_ptr<Hospital>objHosp = std::make_shared<Hospital>();

}


Looking at the code now, it stands out that in your third Hospital constructor you use twice the same parameter name:
1
2
3
4
5
     const std::vector<Address>& personal,
     const std::vector<Department>& personal)
...
, address (personal)
, department (personal)


This raises an error, since the compiler tries to initialize a std::vector<Department> by a std::vector<Address>.


- - -
The compiler also warns you that you don’t ask to initialize your properties in the order you declare them.
The compiler will initialize them in the order they are declared, not in the order of your list initialization.
In this case this is insignificant, but when you initialize a property by another already initialized one, the order becomes important.
(So, it is a good habit to initialize them in the same order they are declared.)


- - -
There’s a problem with std::strings. You use them but... (look at the headers).


- - -
You ask the compiler for a defaulted no-argument Department constructor.

 
Department() = default;


What about the other classes?


- - -
So,
- Hospital must have an array (std::vector) of Department
- Department must have an array (std::vector) of Staff

There’s no requirement for other arrays. Am I wrong?

Now, in your main() function you don’t need any more those smart pointers: your arrays are declared inside your classes.
You just need to provide data for those std::vectors, don’t you?

You can create std::vectors in your main() and then pass them to your classes or you can add elements to the std::vectors inside your classes by some class methods.
By the way, you declare three methods in Hospital:
1
2
3
std::string getHName();
std::string getPhone();
std::string getEmail();


but you don’t implement them.
You mean them to be constant, don’t you? ;-)


- - -
 
addObj[0].setAdd("1", "AA", "TALL", "SL", "24000", "CHINA");


Is there a method setAdd() in your class Address?
Last edited on
closed account (iN8poG1T)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
#include <iostream>
#include <memory>
#include <vector>
#include <string>

using namespace std;


class Address
{
private :
    string num;
    string street;
    string city;
    string state;
    string postcode;
    string country;
public :
    Address();
    Address(const string& a_num,
            const string& a_street,
            const string& a_city,
            const string& a_state,
            const string& a_postcode,
            const string& a_country)
        : num (a_num)
        , street (a_street)
        , city (a_city)
        , state (a_state)
        , postcode (a_postcode)
        , country (a_country)
    {
    }
    void setAdd(string num,string street, string city, string state, string postcode, string country);

    string getNum() const {return num;}
    string getStreet() const {return street;}
    string getCity() const {return city;}
    string getState() const {return state;}
    string getPostcode() const {return postcode;}
    string getCountry() const {return country;}


};



class Staff
{
private :
    string id;
    string bdate;
    string name;
    string edu;
    string cert;
    string add;
    string lang;

public :
    Staff();
    Staff(const string& s_id,
          const string& s_date,
          const string& s_name,
          const string& s_edu,
          const string& s_cert,
          const string& s_add,
          const string& s_lang)
        : id (s_id)
        , bdate (s_date)
        , name (s_name)
        , edu (s_edu)
        , cert (s_cert)
        , add (s_add)
        , lang (s_lang)
    {
    }

    string getID() const    { return id; }
    string getDate () const { return bdate; }
    string getName() const  { return name; }
    string getEdu() const   { return edu; }
    string getCert() const  { return cert; }
    string getAdd() const   { return add; }
    string getLang() const  { return lang; }


};



class Department
{
private :
    string name;
    vector<Staff> staff;
public :
    Department();
    Department(const string& d_name)
        : name (d_name)
    {
    }
    Department(const string& d_name, const vector<Staff>& personal)
        : name(d_name)
        , staff(personal)
    {
    }

    void add_staff_member(const Staff& staff_member);
    string getName() const { return name; }
    int getNumOfStaff() const { return staff.size(); }


};


class Hospital
{
public :
    Hospital();
    Hospital(const string& h_name,
             const string& h_phone,
             const string& h_email)
        : name (h_name)
        , phone (h_phone)
        , email (h_email)
    {
    }
    Hospital(const string& h_name,
             const string& h_phone,
             const string& h_email,
             const vector<Address>& personal,
             const vector<Department>& person)
        : name (h_name)
        , phone (h_phone)
        , email (h_email)
        , address (personal)
        , department (person)
    {
    }
    string getHName()const{return name;}
    string getPhone()const{return phone;}
    string getEmail()const{return email;}
    ~Hospital();

private :
    string name;
    vector<Address> address;
    vector<Department> department;
    string phone;
    string email;
};


int main ()
{
    
   


}


i fix my mistakes but i still dont have idea on how to do number 5 a until c. for c how can i add 3 staff to the first and the rest into second department?
Last edited on
i fix my mistakes but i still dont have idea on how to do number 5 a until c. for c how can i add 3 staff to the first and the rest into second department?

To ‘solve’ this assignment, you should read the instructions with the brain fully activated, not begrudgingly and hoping some else will come and make it for you.

Connect the points in sensible scheme:

- The Hospital class must have ... Address as an Address object ... an array of departments

- Create an object of type Hospital. Initialize the address of the hospital to the 7th address. Add the two departments to the hospital.

- The Department class has ... an array of Staff

- Create 2 department objects. Add the first 3 Staff objects to the first department object and the last three to the second department.

- Create a class named Staff with ... address

- Create 6 objects of Staff and initialize them with data of your choice.

- Add an address object to each staff object created.

- Design a proper Address class

- Create 7 Address objects and initialize them with some data.

Hospital contains an array of Departments which contains an array of Staffs which contains an Address.
Was is that difficult to understand?
Haven’t you seen my comment at line 103 in my second-last post?

What have you done, instead? An array of Address inside Hospital!

This is a forum about C++, not a forum about «how can I do my homework if I don’t even feel like reading the text?».
If you don’t know how to add elements to a std::vector, don’t use std::vectors - use C-style arrays or whatever - or search for a tutorial about them.
Topic archived. No new replies allowed.