1、餐厅点餐系统 设计一个早餐店点餐系统,实现电子点餐、结算和付款功能。程序运行,用户可查看该餐厅餐品名称和价钱,通过菜单选择实现点餐、查看已点餐品、结算和付款功能。各个功能通过函数实现,在主函数中通过调用相应函数实现相应功能。 程序运行显示以下界面: *************欢迎光临美味早餐店,本店将为您提供优质美味的早餐*************** 1.小笼包子 10元/屉 2.肉夹馍 8元/个 3.牛肉面 15元/碗 4.小米粥3元/碗 5.茶叶蛋1元/个 6.豆腐脑3元/碗 7.油条2元/个 8.凉菜5元/盘 *************************************************************************** 请根据菜单选项进行以下操作: 1.点餐 2.查看已点餐食 3.结算 4.付款 0.退出 该系统完成以下功能: 1.点餐:进入点餐界面,输入餐品编号和数量进行点餐。 2.查看已点餐品:列车已点餐品名称和数量。 3.结算:根据已点餐品计算应付款金额。 4.付款:进行结账付款,根据用户输入的付款金额,系统自动进行找钱等功能。 0.退出:退出程序。
时间: 2023-08-26 14:04:47 浏览: 45
这个点餐系统可以分成几个部分来实现:
1. 菜单显示:定义一个显示菜单的函数,根据菜单选项编号和相应的价格进行输出。
2. 点餐:定义一个函数,实现用户输入餐品编号和数量,将其保存到一个结构体数组中。
3. 查看已点餐品:定义一个函数,遍历结构体数组,输出已点餐品和数量。
4. 结算:定义一个函数,根据已点餐品计算应付款金额。
5. 付款:定义一个函数,根据用户输入的付款金额,进行找钱等功能。
6. 退出:定义一个函数,结束程序运行。
下面是一个简单的代码实现,供您参考:
```c
#include <stdio.h>
// 定义一个结构体,保存餐品编号和数量
struct order {
int id;
int num;
};
// 菜单显示函数
void show_menu() {
printf("*************欢迎光临美味早餐店,本店将为您提供优质美味的早餐***************\n");
printf("1.小笼包子\t10元/屉\n");
printf("2.肉夹馍\t8元/个\n");
printf("3.牛肉面\t15元/碗\n");
printf("4.小米粥\t3元/碗\n");
printf("5.茶叶蛋\t1元/个\n");
printf("6.豆腐脑\t3元/碗\n");
printf("7.油条\t2元/个\n");
printf("8.凉菜\t5元/盘\n");
printf("***************************************************************************\n");
}
// 点餐函数
void order_food(struct order o[], int *count) {
int id, num;
printf("请输入餐品编号和数量:");
scanf("%d %d", &id, &num);
o[*count].id = id;
o[*count].num = num;
(*count)++;
}
// 查看已点餐品函数
void view_order(struct order o[], int count) {
printf("已点餐品:\n");
for (int i = 0; i < count; i++) {
printf("%d号餐品:%d个\n", o[i].id, o[i].num);
}
}
// 结算函数
void settle_account(struct order o[], int count, float *total) {
for (int i = 0; i < count; i++) {
switch (o[i].id) {
case 1:
*total += o[i].num * 10;
break;
case 2:
*total += o[i].num * 8;
break;
case 3:
*total += o[i].num * 15;
break;
case 4:
*total += o[i].num * 3;
break;
case 5:
*total += o[i].num * 1;
break;
case 6:
*total += o[i].num * 3;
break;
case 7:
*total += o[i].num * 2;
break;
case 8:
*total += o[i].num * 5;
break;
}
}
printf("应付款金额为%.2f元\n", *total);
}
// 付款函数
void pay(float total) {
float money, change;
printf("请输入付款金额:");
scanf("%f", &money);
change = money - total;
if (change >= 0) {
printf("找零%.2f元,谢谢惠顾!\n", change);
} else {
printf("付款金额不足,请重新输入!\n");
pay(total);
}
}
int main() {
struct order orders[100];
int count = 0;
float total = 0;
int option = -1;
while (option != 0) {
show_menu();
printf("请根据菜单选项进行以下操作:\n");
printf("1.点餐\n");
printf("2.查看已点餐品\n");
printf("3.结算\n");
printf("4.付款\n");
printf("0.退出\n");
printf("请选择操作:");
scanf("%d", &option);
switch (option) {
case 1:
order_food(orders, &count);
break;
case 2:
view_order(orders, count);
break;
case 3:
settle_account(orders, count, &total);
break;
case 4:
pay(total);
break;
case 0:
printf("谢谢惠顾!\n");
break;
default:
printf("输入有误,请重新输入!\n");
break;
}
}
return 0;
}
```
相关推荐
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)