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

Draw a class diagram that shows a StackOfPersons class that contains a stack of

ID: 3648363 • Letter: D

Question

Draw a class diagram that shows a StackOfPersons class that contains a stack of Person objects as defined in problem 3. Note: StackOfPersons is a stack data structure. Write StackOfPersons and test.

Explanation / Answer

#include #include #include using namespace std; struct person { string name; person *next; }; class StackOfPersons { private: person *head; person P; public: StackOfPersons() { head=NULL; } void push(string name) { person *curr=head; person *prev=NULL; if (head==NULL) { head=new person; head->name=name; head->next=NULL; } else { while (curr!=NULL) { prev=curr; curr=curr->next; } curr=new person; curr->name=name; prev->next=curr; curr->next=NULL; } } void pop() { person *curr=head; person *prev=NULL; while (curr->next!=NULL) { prev=curr; curr=curr->next; } delete curr; prev->next=NULL; } void print() { person *curr=head; while(curr!=NULL) { cout
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