The fact that Person has setters and getters for every data member implies that Person is a value class.
That said, I would make the data members public and rip at least the getters (otherwise they should be
const member functions if you decide to keep them).
I would also make two Person constructors, implemented as follows:
1 2 3 4
|
Person::Person() : name(), id(), faculty(), branch() {}
Person::Person( const std::string& name, int id, const std::string& faculty, const std::string& branch ) :
name( name ), id( id ), faculty( faculty ), branch( branch ) {}
| |
Do the same for advisor. (Constructor should take at least contact_num and room_num; whether or
not it takes an array of students depends on how you use the object).
These allow you to write:
|
Person me( "jsmith", 7, "foobar", "blah" );
| |
instead of
1 2 3 4 5
|
Person me;
me.set_name( "jsmith );
me.set_id( 7 );
me.set_faculty( "foobar" );
me.set_branch( "blah" );
| |
The former is easier to get right than the latter. The latter code gets silently broken whenever you add a new data member to Person and forget to update the code. In the former case, you'd add another parameter to the constructor, and then the code will fail to compile until you pass the additional parameter. (The latter code is
also slightly less efficient).
The easiest way to do what you want with the Advisee list is to store the list as an STL container such as a deque and return a copy of the deque (which would be one "thing" instead of two).
If you are not allowed to do that, then you have to return the values via function arguments. For example:
1 2 3 4 5 6 7 8 9 10
|
void foo( int& x, int& y ) {
x = 4;
y = 5;
}
int main() {
int a, b;
foo( a, b );
// a = 4, b = 5 now
}
| |
Or you can also use pointers:
1 2 3 4 5 6 7 8 9 10
|
void foo( int* x, int* y ) {
*x = 4;
*y = 5;
}
int main() {
int a, b;
foo( &a, &b );
// a = 4, b = 5 now
}
| |
The former is preferred to the latter.