Here's a simple C++ program for a restaurant:
#include <iostream>
#include <string>
using namespace std;
class Restaurant {
private:
string itemName[10];
int itemPrice[10];
int itemQuantity[10];
int numberOfItems;
public:
void addItem() {
cout << "Enter item name: ";
cin.ignore();
getline(cin, itemName[numberOfItems]);
cout << "Enter item price: ";
cin >> itemPrice[numberOfItems];
cout << "Enter item quantity: ";
cin >> itemQuantity[numberOfItems];
numberOfItems++;
}
void displayMenu() {
cout << "\nRestaurant Menu\n";
for (int i = 0; i < numberOfItems; i++) {
cout << (i + 1) << ". " << itemName[i] << " - $" << itemPrice[i] << " (" << itemQuantity[i] << " available)\n";
}
}
void placeOrder() {
int choice, quantity;
cout << "Enter the item number to order: ";
cin >> choice;
cout << "Enter the quantity to order: ";
cin >> quantity;
if (choice > 0 && choice <= numberOfItems && quantity <= itemQuantity[choice - 1]) {
cout << "Order placed successfully!\n";
itemQuantity[choice - 1] -= quantity;
} else {
cout << "Invalid choice or insufficient quantity.\n";
}
}
void displayOrderSummary() {
cout << "\nOrder Summary\n";
for (int i = 0; i < numberOfItems; i++) {
if (itemQuantity[i] < itemQuantity[i]) {
cout << itemName[i] << " x " << (itemQuantity[i] - itemQuantity[i]) << "\n";
}
}
}
};
int main() {
Restaurant restaurant;
int choice;
restaurant.numberOfItems = 0;
while (true) {
cout << "\nRestaurant Management System\n";
cout << "1. Add item to menu\n";
cout << "2. Display menu\n";
cout << "3. Place order\n";
cout << "4. Display order summary\n";
cout << "5. Exit\n";
cout << "Enter your choice: ";
cin >> choice;
switch (choice) {
case 1:
restaurant.addItem();
break;
case 2:
restaurant.displayMenu();
break;
case 3:
restaurant.placeOrder();
break;
case 4:
restaurant.displayOrderSummary();
break;
case 5:
return 0;
default:
cout << "Invalid choice. Please try again.\n";
}
}
return 0;
}
*Example Output:*
Restaurant Management System
1. Add item to menu
2. Display menu
3. Place order
4. Display order summary
5. Exit
Enter your choice: 1
Enter item name: Burger
Enter item price: 10
Enter item quantity: 5
Restaurant Management System
1. Add item to menu
2. Display menu
3. Place order
4. Display order summary
5. Exit
Enter your choice: 2
Restaurant Menu
1. Burger - $10 (5 available)
Restaurant Management System
1. Add item to menu
2. Display menu
3. Place order
4. Display order summary
5. Exit
Enter your choice: 3
Enter the item number to order: 1
Enter the quantity to order: 2
Order placed successfully!
Restaurant Management System
1. Add item to menu
2. Display menu
3. Place order
4. Display order summary
5. Exit
Enter your choice: 4
Order Summary
Burger x 2
This program defines a `Restaurant` class with private member variables for menu items, prices, and quantities. The class includes public methods for adding items to the menu, displaying the menu, placing orders, and displaying order summaries.
In the `main()` function, a `Restaurant` object is created, and a simple text-based menu is displayed. The user can interact with the program by choosing options to add items, display the menu, place orders, or display order summaries.
No comments:
Post a Comment