C++ MyProgrammingLab problem: Given a struct type Employee with members string n
ID: 3563167 • Letter: C
Question
C++ MyProgrammingLab problem:
Given a struct type Employee with members
string name and
Employee * supervisor,
implement the function
void printSupervisors(const Employee & e);
the prints the name of e's supervisor, the supervisor's supervisor and so on.
The chain stops when the supervisor value is NULL.
Your function is called on some employee in the chain Mike --> Sue --> Bob --> Ann --> Juan.
For example if the input is 0 (for Mike) then the output should be Sue Bob Ann Juan.
If the input is 4 (for Juan) there will be no output since Juan has no supervisor.
Do not write the entire program and do not create any other functions.
Explanation / Answer
Given a struct type Employee with members
string name and
Employee * supervisor,
// implement the function
// the prints the name of e's supervisor, the supervisor's supervisor and so on.
// The chain stops when the supervisor value is NULL.
void printSupervisors(const Employee & e){
Employee* local = &e;
while(loal->supervisor!=NULL)
{
cout << local->supervisor->name << " "
local = local->supervisor;
}
}
Your function is called on some employee in the chain Mike --> Sue --> Bob --> Ann --> Juan.
For example if the input is 0 (for Mike) then the output should be Sue Bob Ann Juan.
If the input is 4 (for Juan) there will be no output since Juan has no supervisor.
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.