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

revise the Average Waiting Time program to do the following: a) Also output the

ID: 3803760 • Letter: R

Question

revise the Average Waiting Time program to do the following: a) Also output the largest number of customers who were on a queue at the same time. b) Choose the queue for a customer to enter based on shortest finish time, rather than shortest size. The user should have the ability to choose which approach to use for any simulation run. Revise based off the AWT code AWT public class GlassQueue extends ArrayUnbndQueue public class ArrayUnbndQueue implements UnboundedQueueInterface public interface UnboundedQueueInterface extends QueueInterface { void enqueue(T element); //Adds element to the rear of this quee. } public interface QueueInterface { T dequeue() throws QueueUnderflowException; //Throws QueueUnderflowException if this queue is empty; //otherwise, removes front element from this queue and returns it boolean isEmpty(); //Returns true if this queue is empty; otherwise, return false } revise the Average Waiting Time program to do the following: a) Also output the largest number of customers who were on a queue at the same time. b) Choose the queue for a customer to enter based on shortest finish time, rather than shortest size. The user should have the ability to choose which approach to use for any simulation run. Revise based off the AWT code AWT public class GlassQueue extends ArrayUnbndQueue public class ArrayUnbndQueue implements UnboundedQueueInterface public interface UnboundedQueueInterface extends QueueInterface { void enqueue(T element); //Adds element to the rear of this quee. } public interface QueueInterface { T dequeue() throws QueueUnderflowException; //Throws QueueUnderflowException if this queue is empty; //otherwise, removes front element from this queue and returns it boolean isEmpty(); //Returns true if this queue is empty; otherwise, return false } revise the Average Waiting Time program to do the following: a) Also output the largest number of customers who were on a queue at the same time. b) Choose the queue for a customer to enter based on shortest finish time, rather than shortest size. The user should have the ability to choose which approach to use for any simulation run. Revise based off the AWT code AWT public class GlassQueue extends ArrayUnbndQueue public class ArrayUnbndQueue implements UnboundedQueueInterface public interface UnboundedQueueInterface extends QueueInterface { void enqueue(T element); //Adds element to the rear of this quee. } public interface QueueInterface { T dequeue() throws QueueUnderflowException; //Throws QueueUnderflowException if this queue is empty; //otherwise, removes front element from this queue and returns it boolean isEmpty(); //Returns true if this queue is empty; otherwise, return false }

Explanation / Answer

#include <stdio.h>
#include <stdlib.h>
#include<conio.h>

int check_if_done(int processes[], int m)
{
int k;
for(k=0; k<m; k++)
if(processes[k] > 0)
return 0;
return 1;
}

int main()
{
int processes[6];
int waiting_times[6];

processes[0] = 3;
processes[1] = 7;
processes[2] = 4;
processes[3] = 2;
processes[4] = 9;

int tq = 2;
int i = 0, j, n = 6;

for(j=0; j<n; j++)
waiting_times[j] = 0;

while(1)
{
if(check_if_done(processes, n))
break;

if(processes[i] > 0)
{
printf("P%d = %d ", i+1, processes[i]);
waiting_times[i] += processes[i];
processes[i] -= tq;
}
k++;
if(i == n)
{
printf(" ");
i = 0;
}
}

printf(" ");
for(k=0; k<n; k++)
{
printf("P%d waiting time = %d ", (k+1), waiting_times[k]);
}

return 0;
}