DSA Python Project – Restaurant Order Processing System

Program 1

#  Project: Restaurant Order Processing System(Based on Doubly linked list and DQUEUE)
   
#  Features:
# 1. Add order at the end of the queue (new order)
# 2. Serve the first order (remove from front)
# 3. Cancel the last order (remove from end)
# 4. View all pending orders (from first to last)
# 5. Search order according to order ID
# 6. Search order according to customer name
# 7. Total Count of pending orders


class Order:     # Node 
    def __init__(self, order_id, customer_name, food_item):
        self.prev = None
        self.order_id = order_id
        self.customer_name = customer_name
        self.food_item = food_item
        self.next = None

class RestaurantOrderSystem:
    def __init__(self):
        self.head = None
        self.tail = None
        self.next_order_id = 1

    def add_order(self, customer_name, food_item):
        new_order = Order(self.next_order_id, customer_name, food_item)
        self.next_order_id += 1

        if self.head is None:
            self.head = self.tail = new_order
        else:
            self.tail.next = new_order
            new_order.prev = self.tail
            self.tail = new_order

        print(f" Order #{new_order.order_id} added for {customer_name}: {food_item}")

    def serve_order(self):
        if self.head is None:
            print("No orders to serve.")
            return

        print(f" Serving Order #{self.head.order_id}: {self.head.customer_name} - {self.head.food_item}")
        temp=self.head
        self.head = self.head.next
        if self.head!=None:
            self.head.prev = None
        else:
            self.tail = None
        del temp

    def cancel_last_order(self):
        if self.tail is None:
            print("No orders to cancel.")
            return

        print(f Cancelling Order #{self.tail.order_id}: {self.tail.customer_name} - {self.tail.food_item}")
        temp=self.tail
        self.tail = self.tail.prev
        if self.tail!=None:
            self.tail.next = None
        else:
            self.head = None
        del temp
    def view_orders(self):
        if self.head is None:
            print("No pending orders.")
            return

        print("\n--- Pending Orders ---")
        temp = self.head
        while temp!=None:
            print(f"Order #{temp.order_id:3d} | Customer: {temp.customer_name:15} | Item: {temp.food_item}")
            temp = temp.next

    def search_by_id(self, order_id):
        temp = self.head
        while temp!=None:
            if temp.order_id == order_id:
                print(f" Found Order #{temp.order_id}: {temp.customer_name} - {temp.food_item}")
                return
            temp = temp.next
        print(" Order ID not found.")

    def search_by_name(self, name):
        temp = self.head
        found = False
        while temp:
            if temp.customer_name.lower() == name.lower():
                print(f" Order #{temp.order_id}: {temp.food_item}")
                found = True
            temp = temp.next
        if not found:
            print(f" No orders found for {name}")

    def count_orders(self):
        count = 0
        temp = self.head
        while temp:
            count += 1
            temp = temp.next
        print(f" Total pending orders: {count}")

    def menu(self):
        while True:
            print("\n========== Restaurant Order System ==========")
            print("1. Add New Order")
            print("2. Serve First Order")
            print("3. Cancel Last Order")
            print("4. View All Orders")
            print("5. Search Order by ID")
            print("6. Search Order by Customer Name")
            print("7. Count Pending Orders")
            print("8. Exit")
            print("\n=======================================\n")
            choice = input("Choose an option: ")

            if choice == '1':
                name = input("Enter customer name: ")
                item = input("Enter food item: ")
                self.add_order(name, item)
            elif choice == '2':
                self.serve_order()
            elif choice == '3':
                self.cancel_last_order()
            elif choice == '4':
                self.view_orders()
            elif choice == '5':
                try:
                    order_id = int(input("Enter Order ID: "))
                    self.search_by_id(order_id)
                except ValueError:
                    print("Invalid input.")
            elif choice == '6':
                name = input("Enter customer name: ")
                self.search_by_name(name)
            elif choice == '7':
                self.count_orders()
            elif choice == '8':
                print("Exiting system. Goodbye!")
                break
            else:
                print("Invalid option. Try again.")

# Run the application
if __name__ == "__main__":
    system = RestaurantOrderSystem()
    system.menu()

 

 

courses

DataFlair Team

DataFlair Team provides high-impact content on programming, Java, Python, C++, DSA, AI, ML, data Science, Android, Flutter, MERN, Web Development, and technology. We make complex concepts easy to grasp, helping learners of all levels succeed in their tech careers.

Leave a Reply

Your email address will not be published. Required fields are marked *