Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I need this in C Language !!! Write a program that simulates a checkout line in a supermarket over a 12-hour period (or a 720-minutes

I need this in C Language!!!

Write a program that simulates a checkout line in a supermarket over a 12-hour period (or a 720-minutes period). A queue is a FIFO data structure, soyou must enqueue at the tail of the queue, and dequeue at the head of thequeue. The line will be a queue of messages stored on an IPC message queue.Customers will arrive in random intervals from 1 to 4 minutes (see yourprevious program using the random number generator). Customers remainin the queue until they reach the head, at which time they are serviced - theservice times are also determined by another random interval from 1 to 4minutes. The next arrival times and the service times once the customerreaches the head of the queue are, then, integers between 1 and 4.

You WILL have to adjust some what as IPC message queues do NOT have an equivalent to the peek()method. This means that you HAVE to dequeue the message at the head ofthe queue (pretending it is still on the queue that is do not yet decrementthe queue length), and wait for the customers service time to expire beforedequeuing the next customer at the head. After all, the customer is still in theline when at the head of the line getting serviced (checked out). There is also no length() method, so you have to keep accurate track of the length of thequeue during each minute of the simulation (recommended), or you can usethe msgctl function to tell how many messages are remaining on the queue(not recommended). Even though you have to dequeue the customer at thehead of the queue, that customer is still in line until checked out.Very important: when creating a message queue with msgget do NOT useftok to get the key. Instead use: q_id = msgget(IPC_PRIVATE, IPC_CREAT|0644); and do not forget to check for an error return. The reasons are: 1) the sameprocess is doing the writing and reading of the queues and you do not need apublic key, and 2) if your simulation ends leaving message on the queue (andit almost always will!) and you do not specify IPC_PRIVATE, you will get theold messages off the queue when you run your simulation the next time. TheIPC_PRIVATE ensures that you get a new queue every time you invokemsgget.A customer should be a structure containing the following fields:

customer number (an integer) arrival time (on the queue an integer from 0 to 719)service time (when dequeued at the head a random integer between1 and 4 minutes)

When you are developing and testing you will want to change MINUTES tosomething considerably shorter (say, 10, 20, 30), as the simulator is going toproduce a lot of output if MINUTES is 720. Because the output is voluminousyou will need to write it to a file (and inform the user of the file name whendone).Run the simulation for 720 minutes (a 12-hour day). Use an algorithm similarto:a. Choose a random number between 1 and 4 to determine when thefirst customer arrives. When this time (in minutes) arrives, add acustomer to the queue (see also b below), and determine when the next random customer is to arrive.b. At each customers arrival time: 1) determine the customers servicetime (also between 1 and 4 minutes) when reaching the head of thequeue, 2) enqueue the customer, and 3) schedule the arrival of thenext customer (between 1 and 4 minutes).c. For each simulated minute of the day:i. When a customer arrives on the queue: 1) say so, 2) determinethe customers arrival time and service time and display it(arrival times are integers from 0 to 719 minutes, service timesare integers between 1 and 4 minutes), 3) enqueue the arrivalon the IPC message queue, and 4) schedule the next customers

arrival time, and display it.ii. The service timer does NOT start to run until the customer isdequeued from the head of the queue.iii. When service is completed for a customer: 1) say so, 2)determine the customers completion time (an integer between0 and 719 also display this time when you say so), and 3)determine the customers actual wait time (which is the timenow minus the customers arrival time on the queue).iv. Note: no butting in line! Only dequeue at the head of the queue,even if there are customers with shorter service times behindthe head.d. At the end of the simulation display the following statistics: 1) thetotal number of customers serviced in the simulation, 2) the maximumnumber of customers in the queue during all minutes of the 720-minute simulation, 3) the average number of customers in the queuethrough (each minute of) the simulation, (a double), 4) the averageactual wait time (wait time equals the total amount of time spentwaiting on the queue plus the additional time spent waiting for theservice interval to expire) for all customers (a double), and 5) thenumber of customers left on the queue when the simulation ends.e. Place all output into a file.

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

Modern Database Management

Authors: Jeff Hoffer, Ramesh Venkataraman, Heikki Topi

13th Edition Global Edition

1292263350, 978-1292263359

More Books

Students also viewed these Databases questions

Question

Provide examples of Dimensional Tables.

Answered: 1 week ago