c++实现题目:餐饮业管理系统 基本要求:设计一个餐饮业管理系统,使之能提供以下基本功能: (1) 输入顾客(顾客桌号、排队号、所点菜(若干)); (2) 修改(顾客点菜信息、菜品信息); (3) 显示(顾客、菜品等信息) (4) 顾客结账。
时间: 2023-06-27 15:08:31 浏览: 55
以下是一个简单的C++实现餐饮业管理系统的示例代码:
```c++
#include <iostream>
#include <vector>
#include <string>
using namespace std;
// 菜品类定义
class Dish {
public:
string name; // 菜名
double price; // 价格
int quantity; // 数量
Dish(string n, double p, int q) {
name = n;
price = p;
quantity = q;
}
};
// 顾客类定义
class Customer {
public:
int tableNo; // 桌号
int queueNo; // 排队号
vector<Dish> dishes; // 点的菜品
Customer(int tn, int qn) {
tableNo = tn;
queueNo = qn;
}
};
// 餐厅类定义
class Restaurant {
public:
vector<Customer> customers; // 所有顾客
vector<Dish> dishes; // 所有菜品
// 添加菜品
void addDish(string name, double price, int quantity) {
dishes.push_back(Dish(name, price, quantity));
}
// 显示所有菜品
void showAllDishes() {
cout << "所有菜品:" << endl;
for (int i = 0; i < dishes.size(); i++) {
cout << dishes[i].name << " 价格:" << dishes[i].price << " 数量:" << dishes[i].quantity << endl;
}
cout << endl;
}
// 显示指定桌号的顾客信息
void showCustomerInfo(int tableNo) {
for (int i = 0; i < customers.size(); i++) {
if (customers[i].tableNo == tableNo) {
cout << "桌号:" << customers[i].tableNo << " 排队号:" << customers[i].queueNo << endl;
cout << "所点菜品:" << endl;
for (int j = 0; j < customers[i].dishes.size(); j++) {
cout << customers[i].dishes[j].name << " 价格:" << customers[i].dishes[j].price << " 数量:" << customers[i].dishes[j].quantity << endl;
}
cout << endl;
}
}
}
// 顾客结账
void checkOut(int tableNo) {
double total = 0;
for (int i = 0; i < customers.size(); i++) {
if (customers[i].tableNo == tableNo) {
for (int j = 0; j < customers[i].dishes.size(); j++) {
total += customers[i].dishes[j].price * customers[i].dishes[j].quantity;
}
customers.erase(customers.begin() + i);
break;
}
}
cout << "桌号:" << tableNo << " 账单:" << total << endl;
}
// 修改指定桌号的顾客点菜信息
void modifyOrder(int tableNo, string dishName, int quantity) {
for (int i = 0; i < customers.size(); i++) {
if (customers[i].tableNo == tableNo) {
for (int j = 0; j < customers[i].dishes.size(); j++) {
if (customers[i].dishes[j].name == dishName) {
customers[i].dishes[j].quantity = quantity;
break;
}
}
break;
}
}
}
// 修改指定菜品信息
void modifyDish(string dishName, double price, int quantity) {
for (int i = 0; i < dishes.size(); i++) {
if (dishes[i].name == dishName) {
dishes[i].price = price;
dishes[i].quantity = quantity;
break;
}
}
}
};
int main() {
Restaurant restaurant;
// 添加菜品
restaurant.addDish("鱼香肉丝", 28.0, 10);
restaurant.addDish("宫保鸡丁", 25.0, 8);
restaurant.addDish("回锅肉", 35.0, 5);
// 显示所有菜品
restaurant.showAllDishes();
// 添加顾客并点菜
Customer c1(1, 1);
c1.dishes.push_back(Dish("鱼香肉丝", 28.0, 2));
c1.dishes.push_back(Dish("宫保鸡丁", 25.0, 3));
restaurant.customers.push_back(c1);
// 显示指定桌号的顾客信息
restaurant.showCustomerInfo(1);
// 顾客结账
restaurant.checkOut(1);
// 修改指定桌号的顾客点菜信息
restaurant.modifyOrder(1, "鱼香肉丝", 3);
// 修改指定菜品信息
restaurant.modifyDish("鱼香肉丝", 30.0, 5);
return 0;
}
```
在这个示例代码中,我们定义了三个类:Dish(菜品)、Customer(顾客)和Restaurant(餐厅)。其中,Dish和Customer类用来存储菜品和顾客信息,Restaurant类用来实现餐饮业管理系统的基本功能。
在Restaurant类中,我们实现了以下基本功能:
- 添加菜品;
- 显示所有菜品;
- 显示指定桌号的顾客信息;
- 顾客结账;
- 修改指定桌号的顾客点菜信息;
- 修改指定菜品信息。
你可以根据自己的需求对这些功能进行修改和扩展。