Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

write a program for the following scenario There is a supermarket that has only 3 cashiers, numbered 0,1 and 2 . Therefore, in general, customers

image text in transcribed

write a program for the following scenario

There is a supermarket that has only 3 cashiers, numbered 0,1 and 2 . Therefore, in general, customers form three queues, waiting to check out in front of each of these three cashiers. For simplicity, we assume that at most one customer comes to check out every minute. When a customer comes, he will first check which of these three queues is the shortest, and will then join the shortest queue. If a customer finds that there are two queues of the same length, then he will prefer cashier 0 to cashier 1 , and cashier 1 to cashier 2 , because cashier 0 is the closest to the exit. The input to the program is read from a file. The first line in the file specifies the information of the customer who comes in the first minute; the second line specifies the information of the customer who comes in the second minute, and so on. An empty line indicates that no customer comes in that minute. Each line contains two numbers. The first is an integer that indicates the number of minutes the customer needs to be served at a cashier. The second is a floating point number that indicates the total cost of the goods he buys. There are one or more spaces between these two numbers. For example, if the file contains only the following five lines: Then it means that there are totally 4 customers: the first comes in the first minute, the second in the second minute, etc., and no customer comes in the fourth minute. The first customer will need to spend 3 minutes checking out (so he will leave the cashier just before the 4th minute), and he will need to pay $10.9; the second customer will need to spend 1 minute checking out (so he will leave the cashier just before the 3rd minute), and he will need to pay $2.1, and so on. There are no more customers after the fourth customer (who comes in the fifth minute), as we have reached the end of input file. Write a program that reads an input file (file name is "supermarket.dat"). The total number of lines in the input file is not known in advance. The program performs the simulation, and outputs the following information - The average time a customer needs to wait after he joins a queue until he starts to check out. - The total amount of money each of the cashiers receives. - The total number of customers each of the cashiers serves. You should represent a customer as a structure, the type of which is defined as typedef struct customerDataT \{ int checkoutTime; float payment; \} customerDataT; The type queueElementT in queue.h is redefined as typedef struct customerDataT *queueElementT; A cashier is a structure of the following type: typedef struct cashier \{ int numberOfCustomersServed; int totalCheckoutTime; float totalAmountReceived; queueADT customerQueue; \} cashierT; Finally, the three cashiers should be implemented as an array: cashierT cashier[3]

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access with AI-Powered 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

Students also viewed these Databases questions