Need help with pointers and object composition

I have three classes to make, Person, the base class, and the derived classes Professor and Student. The student class is to have a Professor member variable called adviser, and the Professor should be able to create a Student array to hold up to 4 students as advisees.

I'm having several issues with developing these classes.

I'm not sure how to make a default constructor the class Student because I don't know what to do with my adviser member if there is no Professor object for me to automatically set it to.

I have the same problem with the class Professor, however an even bigger problem is I'm not sure how to set up the the pointer array to hold its advisees since once again, not student are being automatically passed to it (this may not be the correct terminology).

The second issue is to me a bigger problem, simply because I think it will have a bigger impact on my grade for the assignment.

Below I what I have so far. I would appreciate any input, and if there is anything else you think you need to know tell me.

And thanks ahead of time for any help.

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
#include <iostream>
#include <string>
using namespace std;

class Person
{
protected:
	string name;
public:
	void setName(string name); 
	string getName();
	Person(string name);
	Person();
};

class Professor: public Person
{
private:
	string employeeID;
	string officeNo;
	string officePhone;
	//Student *ptr;
public:
	void setEmployeeID(string employeedID);
	string getEmployeeID();
	void setOfficeNo(string officeNo);
	string getOfficeNo();
	void setOfficePhone(string officePhone);
	string getOfficePhone();
	Professor(string name,string employeeID, string officeNo, string officePhone);
};

class Student: public Person
{
private:
	string studentID;
	string major;
	Professor adviser;
public:
	void setStudentID(string studentID);
	string getStudentID();
	void setMajor(string major);
	string getMajor();
	Student(string name, string studentID, string major, Professor adviser);
	void setAdviser(Professor adviser);
	string getAdviser();
};

int main()
{
	Professor p1("John Williams", "e0123", "Combs 123", "3-1234");
	cout << "Professor: " << p1.getName() << endl;
	cout << "ID: " << p1.getEmployeeID() << endl;
	cout << "Office: " << p1.getOfficeNo() << endl;
	cout << "Phone: " << p1.getOfficePhone() << endl;
	cout << endl;

	Professor p2("Paul King", "e0222", "Combs 222", "3-222");
	cout << "Professor: " << p2.getName() << endl;
	cout << "ID: " << p2.getEmployeeID() << endl;
	cout << "Office: " << p2.getOfficeNo() << endl;
	cout << "Phone: " << p2.getOfficePhone() << endl;
	cout << endl;

	Student s1("Mary Jane", "s0123", "Accounting", p1);
	cout << "Student: " << s1.getName() << endl;
	cout << "ID: " << s1.getStudentID() << endl;
	cout << "Major: " << s1.getMajor() << endl;
	cout << "Adviser: " << s1.getAdviser() << endl;
	cout << endl;

	Student s2("James Pete", "s0222", "Marketing", p1);
	cout << "Student: " << s2.getName() << endl;
	cout << "ID: " << s2.getStudentID() << endl;
	cout << "Major: " << s2.getMajor() << endl;
	cout << "Adviser: " << s2.getAdviser() << endl;
	cout << endl;

	Student s3("Jane Eyre", "s0333", "Accounting", p2);
	cout << "Student: " << s3.getName() << endl;
	cout << "ID: " << s3.getStudentID() << endl;
	cout << "Major: " << s3.getMajor() << endl;
	cout << "Adviser: " << s3.getAdviser() << endl;
	cout << endl;

	Student s4("Charlotte Bronte", "s0444", "CIS", p2);
	cout << "Student: " << s4.getName() << endl;
	cout << "ID: " << s4.getStudentID() << endl;
	cout << "Major: " << s4.getMajor() << endl;
	cout << "Adviser: " << s4.getAdviser() << endl;
	cout << endl;

	Student s5("George Owell", "s0555", "CIS", p2);
	cout << "Student: " << s5.getName() << endl;
	cout << "ID: " << s5.getStudentID() << endl;
	cout << "Major: " << s5.getMajor() << endl;
	cout << "Adviser: " << s5.getAdviser() << endl;


	return 0;
}

	//Person function definitions
	void Person::setName(string name) 
	{ 
		this->name = name;
	}

	string Person::getName()
	{
		return name;
	}

	Person::Person(string name)
	{
		this->name = name;
	}
	
	Person::Person()
	{}

	//Professor function definitions
	void Professor::setEmployeeID(string employeedID)
	{
		this->employeeID = employeeID;
	}

	string Professor::getEmployeeID()
	{
		return employeeID;
	}

	void Professor::setOfficeNo(string officeNo)
	{
		this->officeNo = officeNo;
	}

	string Professor::getOfficeNo()
	{
		return officeNo;
	}

	void Professor::setOfficePhone(string officePhone)
	{
		this->officePhone = officePhone;
	}

	string Professor::getOfficePhone()
	{
		return officePhone;
	}

	Professor::Professor(string name,string employeeID, string officeNo, string officePhone)
		:Person(name) ,employeeID(employeeID), officeNo(officeNo), officePhone(officePhone)
	{

	}

	//Student function definitions
	void Student::setStudentID(string studentID)
	{
		this->studentID = studentID;
	}

	string Student::getStudentID()
	{
		return studentID;
	}

	void Student::setMajor(string major)
	{
		this->major = major;
	}

	string Student::getMajor()
	{
		return major;
	}

	Student::Student(string name, string studentID, string major, Professor adviser)
		:Person(name), studentID(studentID), major(major), adviser(adviser)
	{
	}

	void Student::setAdviser(Professor adviser)
	{
		this->adviser = adviser;
	}

	string Student::getAdviser()
	{
		return adviser.getName();
	}
Topic archived. No new replies allowed.