Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Raphael was very happy last week until his boss suddenly called him yesterday, asking him to rewrite his code. Despite being terribly upset about it,

  1. Raphael was very happy last week until his boss suddenly called him yesterday, asking him to rewrite his code. Despite being terribly upset about it, he has finished up writing part of the code below. However, same as his predicament from last week, he doesn't understand how to complete the code to include functions for a) searching for a person and b) deleting the person at the front. Please help him complete his .cpp file ABOVE by defining the two remaining functions.

    He keeps the people in his queue inside a structure called node_t, which consists of the data part string name and the pointer part node* next. He is using a class named BookstoreQueue, which consists of three private data members: int size, node_t* head, node_t* tail. He has implemented the functions getSize(), printQueue(), and addToEnd() already. Please help him finish the methods positionOfPerson() and deleteFromFront().

#include  #include  using namespace std; typedef struct node { string name; struct node* next; }node_t; class BookstoreQueue { // Private data members: int size; node_t* head; node_t* tail; public: // Public functions: // 1. Function to return the current size of the queue. int getSize() { return size; } // 2. Function to print the queue starting from the head. void printQueue() { if(size==0) { cout<<"EMPTY "; return; } node_t* p = head; for(int i=0; iname<<")->"; p = p->next; } cout<<"("<name<<"). "; } // 3. Function that takes as input a string searchPerson, searches whether that person is found in the queue, and returns his/her position from the front. The frontmost person is the 1st person, and so on. // If searchPerson is not found in the queue, this function should return -1. // int positionOfPerson(string searchPerson); // 4. Function that adds a newPerson to the end of the queue. void addToEnd(string newPerson) { // Create a new Node node_t* newNode = new node_t; newNode->name = newPerson; newNode->next = NULL; if(size==0) // If queue is empty: { head = newNode; tail = newNode; size = 1; } else // else queue had at least one element: { tail->next = newNode; tail = newNode; size++; } } // 5. Function that deletes a person from the front of the queue. It returns the name of the person who was at the front. // string deleteFromFront(); //Constructor: void BookStoreQueue() { size = 0; head = NULL; tail = NULL; } }; int main() { BookstoreQueue queue; cout<<"Current queue: "; queue.printQueue(); queue.addToEnd("Muimi"); cout<<"Added Muimi to queue. Current queue: "; queue.printQueue(); queue.addToEnd("Kyouka"); cout<<"Added Kyouka to queue. Current queue: "; queue.printQueue(); /* Tester code for positionOfPerson(): cout<<"Searching for Kyouka. "; cout<<"Found Kyouka in position"<< queue.positionOfPerson("Kyouka"); cout<<" Searching for Christina. "; cout<<"positionOfPerson() returned "<< queue.positionOfPerson("Christina"); */ /* Tester code for deleteFromFront(): string deletedPerson = queue.deleteFromFront(); cout<<"Deleting the following person from the front: "< 

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Transactions On Large Scale Data And Knowledge Centered Systems Xxxviii Special Issue On Database And Expert Systems Applications Lncs 11250

Authors: Abdelkader Hameurlain ,Roland Wagner ,Sven Hartmann ,Hui Ma

1st Edition

3662583836, 978-3662583838

Students also viewed these Databases questions

Question

The nature and importance of the global marketplace.

Answered: 1 week ago