#include #include #include #include using namespace std; class FoodItem { string name; double price; public: FoodItem(string n, double p) : name(n), price(p) {} string getName() const { return name; } double getPrice() const { return price; } }; class Order { vector items; public: void addItem(const FoodItem& item) { items.push_back(item); } double getTotal() const { double total = 0; for (const FoodItem& item : items) { total += item.getPrice(); } return total; } void displayOrder() const { cout << "Order:" << endl; for (const FoodItem& item : items) { cout << item.getName() << " - " << item.getPrice() << " BDT" << endl; } cout << "Total: " << getTotal() << " BDT" << endl; } const vector& getItems() const { return items; } }; class Menu { vector items; public: Menu() { // Add menu items items.push_back(FoodItem("French Fry", 140)); items.push_back(FoodItem("Chicken Cheese Burger", 230)); items.push_back(FoodItem("Steamed Momo", 180)); items.push_back(FoodItem("Chicken Strips", 160)); items.push_back(FoodItem("Cold Drinks", 25)); items.push_back(FoodItem("Water", 20)); } void displayMenu() const { cout << "Menu:" << endl; for (size_t i = 0; i < items.size(); ++i) { cout << i+1 << ". " << items[i].getName() << " - " << items[i].getPrice() << " BDT" << endl; } } FoodItem getItem(int index) const { if (index >= 0 && index < items.size()) { return items[index]; } else { throw out_of_range("Invalid menu item index"); } } }; class FileManager { public: static void saveOrder(const Order& order, const string& filename) { ofstream file(filename); if (file.is_open()) { for (const FoodItem& item : order.getItems()) { file << item.getName() << "," << item.getPrice() << endl; } file.close(); cout << "Order saved to " << filename << endl; } else { cout << "Error: Unable to open file for saving order." << endl; } } static Order loadOrder(const string& filename) { Order order; ifstream file(filename); if (file.is_open()) { string line; while (getline(file, line)) { size_t pos = line.find(","); if (pos != string::npos) { string name = line.substr(0, pos); double price = stod(line.substr(pos + 1)); order.addItem(FoodItem(name, price)); } } file.close(); cout << "Order loaded from " << filename << endl; } else { cout << "Error: Unable to open file for loading order." << endl; } return order; } }; int main() { Menu menu; Order order; // Display a welcome message cout << "Welcome to the Food Ordering System!" << endl; // Main menu loop while (true) { cout << "\nMain Menu:" << endl; cout << "1. View Menu" << endl; cout << "2. Add Item to Order" << endl; cout << "3. View Order" << endl; cout << "4. Save Order" << endl; cout << "5. Load Order" << endl; cout << "6. Checkout and Exit" << endl; cout << "Enter your choice: "; int choice; cin >> choice; switch (choice) { case 1: // View Menu menu.displayMenu(); break; case 2: // Add Item to Order int index; cout << "Enter the item number to add: "; cin >> index; try { order.addItem(menu.getItem(index - 1)); cout << "Item added to order." << endl; } catch (const out_of_range& e) { cout << "Error: " << e.what() << endl; } break; case 3: // View Order order.displayOrder(); break; case 4: // Save Order FileManager::saveOrder(order, "order.txt"); break; case 5: // Load Order order = FileManager::loadOrder("order.txt"); break; case 6: // Checkout and Exit cout << "Total Bill: " << order.getTotal() << " BDT" << endl; cout << "Thank you for using the Food Ordering System!" << endl; return 0; default: cout << "Invalid choice. Please enter a number from 1 to 6." << endl; break; } } return 0; }