Key Points Code must be object oriented Code must be thoroughly commented The project shall use the queue data structure learned in the course. Do not use the queue library. Scenario A supermarket has...

1 answer below »

Key Points


Code must be object oriented
Code must be thoroughly commented
The project shall use the queue data structure learned in the course. Do not use the queue library.


Scenario


A supermarket has 9 cashiers. A customer arrives every 3 seconds and a customer leaves every 6 seconds. The goal of the program is to put the next arriving customer in the shortest queue out of the 9 cashier queues. Your program will need to loop infinitely to simulate the passing of a certain amount of time. I suggest looping the program every second and clearing the screen and displaying all queues. Use asterisks (*) to represent customers in the queues and a for loop to create a one second delay.


Submit your final as a single word document with the code and output screenshots.


Good luck!



Answered Same DayDec 12, 2021

Answer To: Key Points Code must be object oriented Code must be thoroughly commented The project shall use the...

Anandkumar answered on Dec 13 2021
129 Votes
Code:
// required header files
#include
#include
using namespace std;
// r
equired class
class Cashier {
private:
// required private variables
int first, last, size, count;
int *storage;
public:
// create a constructor
Cashier(int n) {
// initialize the variables
first = 0;
last = -1;
count = 0;
size = n;
// dynamic storage
storage = new int[size];
}
//checking for queue, if full
bool is_full() {
// return count
return (count >= size);
}
//check if queue is empty.
bool is_empty() {
return (count == 0);
}
// adding the elements in queue
int enqueue(int el) {
// check if it is not full
if (!is_full()) {
// find the last
last = (last + 1) % size;
// increment the counter
count++;
storage[last] = el;
// return whn element is added
return 1;
} else {
// return 0 when not added
return 0;
}
}
// dequeue the elements
int dequeue() {
if (!is_empty()) {
//int tmp = storage[first];
// find the first
first = (first + 1) % size;
//...
SOLUTION.PDF

Answer To This Question Is Available To Download

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here