Question: I need help in c++ for the bolded sections #ifndef _SERVICE_QUEUE_H #define _SERVICE_QUEUE_H #include #include #include class ServiceQueue { private: /** Your private data members
I need help in c++ for the bolded sections #ifndef _SERVICE_QUEUE_H #define _SERVICE_QUEUE_H #include#include #include class ServiceQueue { private: /** Your private data members here! * (you should have NO PUBLIC data members! * * Nested private types also go here. * For example, if your design needs some kind of * structure, you would specify it here. */ public: /** * Constructor * Description: intializes an empty service queue. * * RUNTIME REQUIREMENT: O(1) * * TODO */ ServiceQueue() { }
/** * function: seat() * description: if the queue is non-empty, it removes the first * entry from (front of queue) and returns the * buzzer ID. * Note that the returned buzzer can now be re-used. * * If the queue is empty (nobody to seat), -1 is returned to * indicate this fact. * * Returns: buzzer ID of dequeued customer, or -1 if queue is empty. * * RUNTIME REQUIREMENT: O(1) */ int seat() { return -1; // placeholder } /** * function: kick_out() * * description: Some times buzzer holders cause trouble and * a bouncer needs to take back their buzzer and * tell them to get lost. * * Specifially: * * If the buzzer given by the 2nd parameter is * in the queue, the buzzer is removed (and the * buzzer can now be re-used) and 1 (one) is * returned (indicating success). * * Return: If the buzzer isn't actually currently in the * queue, the queue is unchanged and false is returned * (indicating failure). Otherwise, true is returned. * * RUNTIME REQUIREMENT: O(1) */ bool kick_out(int buzzer) { return false; // placeholder } /** * function: take_bribe() * description: some people just don't think the rules of everyday * life apply to them! They always want to be at * the front of the line and don't mind bribing * a bouncer to get there. * * In terms of the function: * * - if the given buzzer is in the queue, it is * moved from its current position to the front * of the queue. 1 is returned indicating success * of the operation. * - if the buzzer is not in the queue, the queue * is unchanged and 0 is returned (operation failed). * * Return: If the buzzer isn't actually currently in the * queue, the queue is unchanged and false is returned * (indicating failure). Otherwise, true is returned. * * RUNTIME REQUIREMENT: O(1) */ bool take_bribe(int buzzer) { return false; // placeholder } }; // end ServiceQueue class #endif #include#include /* FILE: Driver.cpp * desc: simple menu-based interactive program which lets user exercise * the ServiceQueue class functions, inspect the queue, etc. */ // The #ifdef directives below enables compilation using different // implementations of the ServiceQueue class. // // Default compilation uses the ServiceQueue.h implementation: // // g++ -std=c++11 Driver.cpp -o Driver // // Compilation which sets the _SLOW preprocessor variable uses the // ServiceQueueSlow.h implementation: // // g++ -std=c++11 -D_SLOW Driver.cpp -o DriverSlow // // Compilation which sets the _SLOW2 preprocessor variable uses the // ServiceQueueSlow2.h implementation: // // g++ -std=c++11 -D_SLOW2 Driver.cpp -o DriverSlow2 #ifdef _SLOW #include "ServiceQueueSlow.h" std::string SourceFile = "ServiceQueueSlow.h"; #define __IMPL_INCL #endif #ifdef _SLOW2 #ifndef __IMPL_INCL #include "ServiceQueueSlow2.h" std::string SourceFile = "ServiceQueueSlow2.h"; #define __IMPL_INCL #endif #endif #ifndef __IMPL_INCL #include "ServiceQueue.h" std::string SourceFile = "ServiceQueue.h"; #define __IMPL_INCL #endif void display(ServiceQueue &q) { std::vector snap; q.snapshot(snap); std::cout << " [ "; for(int b : snap) { std::cout << b << " "; } std::cout << "] " << std::endl; } /** * takes a full line of user input and * parses it. * * Executes specified command and prints appropriate * message if syntactially correct. * otherwise prints an error message. * * Returns 1 only to indicate the the quite command 'q' was * entered. * Otherwise, 0 is returned. */ int execute_cmd(ServiceQueue &q, char *buf) { int tok; char cmd; int buzzer; char junk[128]; // tok stores number of tokens parsed // Note that all commands have either one or two 'tokens': // example: b 8 // 'b' is the first token and '8' is the 2nd // junk array is used to detect if an extraneous 3rd argument // has been entered (parse error). tok = sscanf(buf, " %c %i %s", &cmd, &buzzer, junk); if(tok==0) return 0; if(tok > 2){ printf(" bad command. try again "); return 0; } switch (cmd) { case 'q': if(tok != 1){ printf(" bad command. try again "); return 0; } else{ printf(" goodbye... "); return 1; } case 'd' : if(tok != 1) printf(" bad command. try again "); else display(q); return 0; case 'l': if(tok != 1) printf(" bad command. try again "); else printf(" len: %i ", q.length()); return 0; case 'g': if(tok != 1) printf(" bad command. try again "); else printf(" buzzer: %i ", q.give_buzzer()); return 0; case 's': if(tok != 1) printf(" bad command. try again "); else{ buzzer = q.seat(); if(buzzer != -1) printf(" seating buzzer: %i ", buzzer); else printf(" sorry, queue is empty "); } return 0; case 'k': if(tok != 2) printf(" bad command. try again "); else { if(q.kick_out(buzzer)) printf(" %i is outta here! ", buzzer); else printf(" could not remove tkt %i! ", buzzer); } return 0; case 'b': if(tok != 2) printf(" bad command. try again "); else { if(q.take_bribe( buzzer)) printf(" VIP coming through! "); else printf(" Get in line, then bribe me! "); } return 0; default: printf(" bad command. try again "); return 0; } } int main() { ServiceQueue q; char buf[128]; int done = 0; printf(" Welcome to the simple service-queue interactive program "); printf(" (SOURCE FILE USED FOR ServiceQueue CLASS: %s) ", SourceFile.c_str()); printf(" An empty service queue has been created for you "); printf(" Commands: "); printf(" d : display queue "); printf(" l : report length of queue "); printf(" g : give out a buzzer "); printf(" s : serve the first buzzer in line "); printf(" k : kick specified buzzer out! "); printf(" b : take a bribe to move specified buzzer to front! "); printf(" q : quit "); printf("----------------------------------- "); while(!done) { printf("cmd > "); if(fgets(buf, 127, stdin) != NULL) { if(execute_cmd(q, buf)) done = 1; } } return 0; }
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
