Knowee
Questions
Features
Study Tools

Priya is designing a supermarket checkout queue system to efficiently manage customer flow at the supermarket. Customers join the checkout queue, and cashiers process their orders. Her goal is to implement the core functionality of this system using a queue data structure with an array. Add Customer to Queue: Add a customer to the checkout queue. Each customer is identified by a unique customer ID.Delete Customer: Remove the customer at the front of the queue. Display Queue: Display the customer IDs of all customers in the queue.Help her in designing the program.Input format :The input consists of integers corresponding to the operation that needs to be performed:Choice 1: Add a customer to the queue. If the choice is 1, the following input consists of a space-separated integer, representing the customer ID.Choice 2: Dequeue a customer ID from the queue.Choice 3: Display the list of customer IDs waiting in the queue.Choice 4: Exit the program.Output format :The output displays messages according to the choice and the status of the queue:If the choice is 1:Insert the given customer ID into the queue and display "Customer ID [id] joined the checkout queue." where [id] is the customer ID that is inserted.If the queue is full, print "Checkout queue is full."If the choice is 2:Dequeue a customer ID from the queue and display "Processed Customer ID: " followed by the corresponding ID that is dequeued.If the queue is empty without any elements, print "Checkout queue is empty."If the choice is 3:The output prints "Customers waiting in the checkout queue: " followed by the space-separated customer IDs present in the queue.If there are no elements in the queue, print "Checkout queue is empty."If the choice is 4:Exit the program and print "Exiting Program"If any other choice is entered, print "Invalid option."Refer to the sample output for the exact text and format.Code constraints :Maximum size of the queue = 5Choice: 1, 2, 3 or 4.Sample test cases :Input 1 :1 101 1 102 234Output 1 :Customer ID 101 joined the checkout queue.Customer ID 102 joined the checkout queue.Processed Customer ID: 101Customers waiting in the checkout queue: 102 Exiting ProgramInput 2 :1 1301 140232324Output 2 :Customer ID 130 joined the checkout queue.Customer ID 140 joined the checkout queue.Processed Customer ID: 130Customers waiting in the checkout queue: 140 Processed Customer ID: 140Checkout queue is empty.Checkout queue is empty.Exiting ProgramInput 3 :384Output 3 :Checkout queue is empty.Invalid option.Exiting ProgramInput 4 :1 201 1 202 1 203 1 204 1 205 1 20622234Output 4 :Customer ID 201 joined the checkout queue.Customer ID 202 joined the checkout queue.Customer ID 203 joined the checkout queue.Customer ID 204 joined the checkout queue.Customer ID 205 joined the checkout queue.Checkout queue is full.Processed Customer ID: 201Processed Customer ID: 202Processed Customer ID: 203Customers waiting in the checkout queue: 204 205 Exiting Program

Question

Priya is designing a supermarket checkout queue system to efficiently manage customer flow at the supermarket. Customers join the checkout queue, and cashiers process their orders. Her goal is to implement the core functionality of this system using a queue data structure with an array. Add Customer to Queue: Add a customer to the checkout queue. Each customer is identified by a unique customer ID.Delete Customer: Remove the customer at the front of the queue. Display Queue: Display the customer IDs of all customers in the queue.Help her in designing the program.Input format :The input consists of integers corresponding to the operation that needs to be performed:Choice 1: Add a customer to the queue. If the choice is 1, the following input consists of a space-separated integer, representing the customer ID.Choice 2: Dequeue a customer ID from the queue.Choice 3: Display the list of customer IDs waiting in the queue.Choice 4: Exit the program.Output format :The output displays messages according to the choice and the status of the queue:If the choice is 1:Insert the given customer ID into the queue and display "Customer ID [id] joined the checkout queue." where [id] is the customer ID that is inserted.If the queue is full, print "Checkout queue is full."If the choice is 2:Dequeue a customer ID from the queue and display "Processed Customer ID: " followed by the corresponding ID that is dequeued.If the queue is empty without any elements, print "Checkout queue is empty."If the choice is 3:The output prints "Customers waiting in the checkout queue: " followed by the space-separated customer IDs present in the queue.If there are no elements in the queue, print "Checkout queue is empty."If the choice is 4:Exit the program and print "Exiting Program"If any other choice is entered, print "Invalid option."Refer to the sample output for the exact text and format.Code constraints :Maximum size of the queue = 5Choice: 1, 2, 3 or 4.Sample test cases :Input 1 :1 101 1 102 234Output 1 :Customer ID 101 joined the checkout queue.Customer ID 102 joined the checkout queue.Processed Customer ID: 101Customers waiting in the checkout queue: 102 Exiting ProgramInput 2 :1 1301 140232324Output 2 :Customer ID 130 joined the checkout queue.Customer ID 140 joined the checkout queue.Processed Customer ID: 130Customers waiting in the checkout queue: 140 Processed Customer ID: 140Checkout queue is empty.Checkout queue is empty.Exiting ProgramInput 3 :384Output 3 :Checkout queue is empty.Invalid option.Exiting ProgramInput 4 :1 201 1 202 1 203 1 204 1 205 1 20622234Output 4 :Customer ID 201 joined the checkout queue.Customer ID 202 joined the checkout queue.Customer ID 203 joined the checkout queue.Customer ID 204 joined the checkout queue.Customer ID 205 joined the checkout queue.Checkout queue is full.Processed Customer ID: 201Processed Customer ID: 202Processed Customer ID: 203Customers waiting in the checkout queue: 204 205 Exiting Program

...expand
🧐 Not the exact question you are looking for?Go ask a question

Solution 1

Here is a Python program that implements the supermarket checkout queue system as described in the problem:

class Queue:
    def __init__(self):
        self.queue = []
        self.max_size = 5

    def enqueue(self, id):
        if len(self.queue) < self.max_size:
            self.queue.append(id)
            print(f"Customer ID {id} joined the checkout queue.")
        else:
            print("Checkout queue is full.")

    def dequeue(self):
        if len(self.queue) > 0:
            id = self.queue.pop(0)
            print(f"Processed Customer ID: {id}")
        else:
            print("Checkout queue is empty.")

    def display(self):
        if len(self.queue) > 0:
            print("Customers waiting in the checkout queue: ", end="")
            for id in self.queue:
                print(id, end=" ")
            print()
        else:
            print("Checkout queue is empty.")

def main():
    q = Queue()
    while True:
        choice = int(input())
        if choice == 1:
            id = int(input())
            q.enqueue(id)
        elif choice == 2:
            q.dequeue()
        elif choice == 3:
            q.display()
        elif choice == 4:
            print("Exiting Program")
            break
        else:
            print("Invalid option.")

if __name__ == "__main__":
    main()

This program creates a queue with a maximum size of 5. It then enters a loop where it waits for user input. Depending on the input, it either adds a customer to the queue, removes a customer from the queue, displays the queue, or exits the program. If the user enters an invalid option, it prints an error message.

This problem has been solved

Solution 2

Here is a Python program that implements the queue system for the supermarket checkout as described in the problem:

class Queue:
    def __init__(self):
        self.queue = []
        self.max_size = 5

    def enqueue(self, id):
        if len(self.queue) < self.max_size:
            self.queue.append(id)
            print(f"Customer ID {id} joined the checkout queue.")
        else:
            print("Checkout queue is full.")

    def dequeue(self):
        if len(self.queue) > 0:
            id = self.queue.pop(0)
            print(f"Processed Customer ID: {id}")
        else:
            print("Checkout queue is empty.")

    def display(self):
        if len(self.queue) > 0:
            print("Customers waiting in the checkout queue: ", end="")
            for id in self.queue:
                print(id, end=" ")
            print()
        else:
            print("Checkout queue is empty.")

queue = Queue()

while True:
    choice = int(input())
    if choice == 1:
        id = int(input())
        queue.enqueue(id)
    elif choice == 2:
        queue.dequeue()
    elif choice == 3:
        queue.display()
    elif choice == 4:
        print("Exiting Program")
        break
    else:
        print("Invalid option.")

This program creates a queue with a maximum size of 5. It then enters a loop where it waits for user input. Depending on the input, it either adds a customer to the queue, removes a customer from the queue, displays the queue, or exits the program. If the user enters an invalid option, it prints an error message.

This problem has been solved

Similar Questions

You are developing an order processing system for a company. To efficiently manage incoming orders, you decide to implement a queue data structure using an array. The queue will store order IDs. Implement the following operations:Insert Order: Add an order ID to the end of the queue.Process Order: Remove and process the next order ID from the queue.Display Queue: Display the order IDs in the queue.Input format :The input consists of an integer option representing the action to be performed:Option 1: Enqueue a new order ID into the queue. The next line contains an integer representing the element to be inserted.Option 2: Dequeue an order ID from the queue for processing.Option 3: Display the list of order IDs currently in the queue.Output format :The program provides appropriate outputs based on the choice:When enqueuing an order (option 1), the program outputs the order ID that is inserted into the queue.When dequeuing an order (option 2), the program outputs the order ID that is being processed.When displaying the order IDs (option 3), the program shows the order IDs in the queue.If an enqueue operation is attempted when the queue is full, the program outputs "Queue is full."If a dequeue operation is attempted when the queue is empty, the program outputs "Queue is empty."If the user provides an invalid option, the program outputs an "Invalid option."Refer to the sample output for the exact text and format.Code constraints :The maximum size of the queue is defined as max = 5.The queue can store integer values.Each order is identified by a unique positive integer order ID.Sample test cases :Input 1 :1103Output 1 :Order ID 10 is inserted in the queue.Order IDs in the queue are: 10 Input 2 :13014023Output 2 :Order ID 30 is inserted in the queue.Order ID 40 is inserted in the queue.Processed Order ID: 30Order IDs in the queue are: 40 Input 3 :34Output 3 :Queue is empty.Invalid option.Input 4 :110120130140150160Output 4 :Order ID 10 is inserted in the queue.Order ID 20 is inserted in the queue.Order ID 30 is inserted in the queue.Order ID 40 is inserted in the queue.Order ID 50 is inserted in the queue.Queue is full.

A bank has a customer service counter where customers line up to receive assistance. The bank can handle a maximum of 10 customers in the queue at any given time. Customers arrive at the bank and are added to the queue in the order they arrive. The bank teller serves the customers one by one in the order they are in the queue.You are tasked with writing a program to manage this queue. The program should:Accept the maximum number of customers (max_size) that can be processed, but no more than 10.Allow customers to be added to the queue up to the specified maximum size.Dequeue and display the customers in the order they arrived for service.Input format :The first line consists of an integer n, which represents the number of customers the bank will process.The second line consists of a sequence of integers where each integer represents a customer ID, with the total number of customer IDs not exceeding n.Output format :The output displays space-separated integers, representing the order in which customers are dequeued for service, displayed as customer IDs.If the number of customers exceeds the maximum capacity of the queue (which is 10), print "Queue is full", followed by the line the customer's IDs are printed.Refer to the sample output for the exact text and format.Code constraints :In this scenario, the test cases fall under the following constraints:1 ≤ N ≤ 10101 ≤ customer ID ≤ 1001Sample test cases :Input 1 :5101 102 103 104 105Output 1 :Dequeuing customers: 101 102 103 104 105 Input 2 :11101 102 103 104 105 106 107 108 109 110 111Output 2 :Queue is fullDequeuing customers: 101 102 103 104 105 106 107 108 109 110 Note :The program will be evaluated only after the “Submit Code” is clicked.Extra spaces and new line characters in the program output will result in the failure of the test case.

Which one of the following is an application of Queue Data Structure?

Implement a circular queue using an array. Provide the enqueue and dequeue operations. give the answer for 5 marks

Sharon, an enthusiastic computer science student, is eager to learn about queues and their implementation using arrays to efficiently handle character data. Your task is to create a user-friendly character queue program to support her learning journey. Implement a circular queue that can perform enqueue, dequeue, and display operations on character data. The program should provide clear feedback on the status of the queue after each operation. Input format :The input consists of integers corresponding to the operation that needs to be performed:Choice 1: Enqueue the character into the queue. If the choice is 1, the following input is a space-separated character, representing the character to be enqueued into the queue.Choice 2: Dequeue a character from the queue.Choice 3: Display the characters in the queue.Choice 4: Exit the program.Output format :The output displays messages according to the choice and the status of the queue:If the choice is 1:Insert the given character into the queue and display "Character [char] is enqueued." where [char] is the character that is inserted.If the queue is full, print "Queue is full. Cannot enqueue."If the choice is 2:Dequeue a character from the queue and display "Dequeued Character: " followed by the corresponding character that is dequeued.If the queue is empty without any elements, print "Queue is empty."If the choice is 3:The output prints "Characters in the queue are: " followed by the space-separated characters present in the queue.If there are no elements in the queue, print "Queue is empty."If the choice is 4:Exit the program and print "Exiting program"If any other choice is entered, the output prints "Invalid option."Refer to the sample output for the exact text and format.Code constraints :Maximum size of the queue = 5Choice: 1, 2, 3, or 4.Sample test cases :Input 1 :1 A1 B1 C1 D1 E1 H3234Output 1 :Character A is enqueued.Character B is enqueued.Character C is enqueued.Character D is enqueued.Character E is enqueued.Queue is full. Cannot enqueue.Characters in the queue are: A B C D EDequeued Character: ACharacters in the queue are: B C D EExiting programInput 2 :21 K54Output 2 :Queue is empty.Character K is enqueued.Invalid option.Exiting programInput 3 :1 X1 Y3232324Output 3 :Character X is enqueued.Character Y is enqueued.Characters in the queue are: X YDequeued Character: XCharacters in the queue are: YDequeued Character: YQueue is empty.Queue is empty.Exiting program

1/1

Upgrade your grade with Knowee

Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.