In C Write a program that simulates a checkout line at a sup

In C++. Write a program that simulates a checkout line at a supermarket. The line is a queue object. Customers (i.e. customer objects) arrive in random integer intervals of 1-4 minutes, also, each customer is served in random integers intervals of 1-4 minutes. Obviously, the rates need to be balanced. If the average arrival rate is larger than the average service rate, the queue will grow infinitely. Even with balanced rates, randomness can still cause long lines. Run the supermarket simulation for a 2-hour period (120 minutes) using the following algorithm:

Choose a random integer from 1 to 4 to determine the minute at which the first customer arrives

At the first customer’s arrival time:

Determine customer’s service time

Begin servicing the customer;

Schedule arrival time of next customers

For each minute of the day

If the next customer arrives, Say so, enqueue the customer, and schedule the arrival time of the next customer.

If the services was completed for the last customer, Say so, dequeue next customer to be serviced and determined customer’s service completion time (random integer 1 – 4 added to the current time).

Now run your simulation for 120 minutes, and answer each of the following:

What is the maximum number of customers in the queue at any time?

What is the longest wait any one customer experiences?

What happens if the arrival interval is changed from 1-4 minutes to 1-3 minutes?

Please upload the following:

The class .cpp file

The main program

The class .h file

Output File

Answers to the Questions Above

Solution

#include #include #include struct queueNode { int cust_n; int serv_t; int arr_t; struct queueNode *nextPtr; }; typedef struct queueNode customer; typedef customer *customerPtr; void printQueue( customerPtr ); int isEmpty( customerPtr ); void dequeue( customerPtr *, customerPtr * ); void enqueue( customerPtr *, customerPtr *, int ,int ,int ); int main() { int i; int t_time = 0; int t_arrival = 0; int t_depart = -1; int customer_n = 0; int serv_time = 0; int MAX_SERV_TIME = serv_time; int tot_wait_t = 0; customerPtr headptr = NULL, tailptr = NULL; srand((unsigned int)time(NULL)); while(t_time != 120) { printf(\"TIME = %d,MAX_SERV_TIME = %d,TOT WAIT TIME = %d\ \",t_time,MAX_SERV_TIME,tot_wait_t); if(t_time == t_depart && !isEmpty(headptr)) { printf(\"customer %d ON\ \ \",headptr->cust_n); serv_time = headptr->serv_t; tot_wait_t += (t_time - headptr->arr_t); dequeue(&headptr,&tailptr); serv_time = rand()%4 + 1; if(isEmpty(headptr)) t_depart = t_time + serv_time; } if(t_time == t_arrival) { customer_n++; serv_time = rand()%4 + 1; MAX_SERV_TIME = (serv_time>MAX_SERV_TIME?serv_time:MAX_SERV_TIME); if(isEmpty(headptr)) t_depart = t_time + serv_time; enqueue(&headptr,&tailptr,customer_n,serv_time,t_arrival); t_arrival += rand()%4 + 1; printf(\"customer %d joins at %d,serv_time %d,new_cust %d\ \",tailptr->cust_n,tailptr->arr_t,tailptr->serv_t,t_arrival); } printQueue(headptr); getchar(); t_time++; } customer_n = (tailptr->cust_n - headptr->cust_n)+ 1; printf(\"average wait time = %d,max service time = %d,tot custs unserved %d\ \ \",tot_wait_t/customer_n,MAX_SERV_TIME,customer_n); for(i = 0; icust_n = cust_n; newPtr->serv_t = serv_t; newPtr->arr_t = arr_t; newPtr->nextPtr = NULL; if ( isEmpty( *headPtr ) ) *headPtr = newPtr; else ( *tailPtr )->nextPtr = newPtr; *tailPtr = newPtr; } else printf(\"No memory available.\ \"); } void dequeue( customerPtr *headPtr, customerPtr *tailPtr ) { //char value; customerPtr tempPtr; //value = ( *headPtr )->data; tempPtr = *headPtr; *headPtr = ( *headPtr )->nextPtr; if ( *headPtr == NULL ) *tailPtr = NULL; free( tempPtr ); } int isEmpty( customerPtr headPtr ){ return headPtr == NULL; } void printQueue( customerPtr currentPtr ) { if ( currentPtr == NULL ) printf( \"Queue is empty.\ \ \" ); else{ printf( \"The queue is:\ \" ); while ( currentPtr != NULL ) { printf( \"%d <-- \", currentPtr->cust_n ); currentPtr = currentPtr->nextPtr; } printf( \"NULL\ \ \" ); } }
In C++. Write a program that simulates a checkout line at a supermarket. The line is a queue object. Customers (i.e. customer objects) arrive in random integer
In C++. Write a program that simulates a checkout line at a supermarket. The line is a queue object. Customers (i.e. customer objects) arrive in random integer

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site