Cover Image for Canteen Management System in C++
86 views

Canteen Management System in C++

Creating a full-fledged Canteen Management System in C++ is a complex project beyond the scope of a single response. However, I can provide you with a simplified example that demonstrates some basic functionality you might find in such a system. This simplified system will include features like adding food items, placing orders, and calculating the total bill. In a real-world scenario, you would likely need a database to manage the data.

Here’s a basic outline of a Canteen Management System in C++:

C++
#include <iostream>
#include <vector>
#include <string>

// Structure to represent a food item
struct FoodItem {
    std::string name;
    double price;
};

// Function to display the menu
void displayMenu(const std::vector<FoodItem>& menu) {
    std::cout << "Menu:" << std::endl;
    for (const FoodItem& item : menu) {
        std::cout << item.name << " - $" << item.price << std::endl;
    }
}

// Function to place an order
void placeOrder(std::vector<FoodItem>& menu) {
    int choice;
    std::cout << "Enter the item number to order (1-" << menu.size() << "): ";
    std::cin >> choice;

    if (choice >= 1 && choice <= menu.size()) {
        const FoodItem& selected = menu[choice - 1];
        std::cout << "You ordered: " << selected.name << " - $" << selected.price << std::endl;
    } else {
        std::cout << "Invalid choice." << std::endl;
    }
}

int main() {
    std::vector<FoodItem> menu;
    menu.push_back({"Burger", 4.99});
    menu.push_back({"Pizza", 6.99});
    menu.push_back({"Fries", 2.49});
    menu.push_back({"Soda", 1.49});

    int option;
    do {
        std::cout << "\nCanteen Management System" << std::endl;
        std::cout << "1. Display Menu" << std::endl;
        std::cout << "2. Place Order" << std::endl;
        std::cout << "3. Exit" << std::endl;
        std::cout << "Enter your choice: ";
        std::cin >> option;

        switch (option) {
            case 1:
                displayMenu(menu);
                break;
            case 2:
                placeOrder(menu);
                break;
            case 3:
                std::cout << "Exiting the program." << std::endl;
                break;
            default:
                std::cout << "Invalid choice. Please try again." << std::endl;
        }
    } while (option != 3);

    return 0;
}

In this simplified example:

  • The FoodItem struct represents a food item with a name and price.
  • The displayMenu function displays the menu, and the placeOrder function allows the user to place an order.
  • The main function includes a menu-driven interface that lets users view the menu, place orders, and exit the program.

Please note that this is a basic demonstration, and a real-world Canteen Management System would involve additional features like user authentication, managing orders, tracking inventory, and processing payments. You would also need a database or a file system to store and retrieve data persistently.

YOU MAY ALSO LIKE...

The Tech Thunder

The Tech Thunder

The Tech Thunder


COMMENTS