Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Given a struct type Employee with members string name and Employee * supervisor,

ID: 670431 • Letter: G

Question

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.

Explanation / Answer

void printSupervisors(const Employee & e){
   Employee *temp = e;
   while(temp->supervisor){
       printf("%s ",temp->supervisor->name);
       temp = temp->supervisor;
       if(temp->supervisor){
           printf("-> ");          
       }
   }
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote