CBSE · 083Class XII · 2023Section C3 marks

Question 30(1)

30 March 2023 · Computer Science (083)

A list contains the following record of a customer : [Customer_name, Room_Type]

Write the following user defined functions to perform given operations on the stack named 'Hotel' :

(i) Push_Cust() – To Push customers' names of those customers who are staying in 'Delux' Room Type. (ii) Pop_Cust() – To Pop the names of customers from the stack and display them. Also, display "Underflow" when there are no customers in the stack.

For example, if the lists with customer details are :

python
["Siddharth", "Delux"]
["Rahul", "Standard"]
["Jerry", "Delux"]

The stack should contain : Jerry, Siddharth

And the output of Pop_Cust() should be :

text
Jerry
Siddharth
Underflow

Answer

python
Hotel = []
Customer = [["Siddharth", "Delux"], ["Rahul", "Standard"], ["Jerry", "Delux"]]

def Push_Cust():
    for rec in Customer:
        if rec[1] == "Delux":
            Hotel.append(rec[0])

def Pop_Cust():
    while len(Hotel) > 0:
        print(Hotel.pop())
    else:
        print("Underflow")

Explanation

Push_Cust filters customer records by Room_Type and appends matching names. Pop_Cust pops and prints until the stack is empty, then displays 'Underflow'.