餐厅的管理系统c语言代码
时间: 2023-10-15 10:06:56 浏览: 42
以下是一个简单的餐厅管理系统的C语言代码示例,包含菜单管理、订单管理和库存管理等功能:
```
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define MAX_ITEM 100
#define MAX_NAME 50
typedef struct {
char name[MAX_NAME];
double price;
char desc[MAX_NAME];
int stock;
} Item;
Item menu[MAX_ITEM];
int num_items = 0;
void add_item() {
if (num_items >= MAX_ITEM) {
printf("Error: menu is full\n");
return;
}
printf("Enter item name: ");
scanf("%s", menu[num_items].name);
printf("Enter item price: ");
scanf("%lf", &menu[num_items].price);
printf("Enter item description: ");
scanf("%s", menu[num_items].desc);
printf("Enter item stock: ");
scanf("%d", &menu[num_items].stock);
num_items++;
}
void display_menu() {
printf("Menu:\n");
for (int i = 0; i < num_items; i++) {
printf("%d. %s ($%.2lf): %s (%d left)\n", i + 1, menu[i].name, menu[i].price, menu[i].desc, menu[i].stock);
}
}
void place_order() {
int choice, quantity;
double total = 0;
printf("Enter item number: ");
scanf("%d", &choice);
printf("Enter quantity: ");
scanf("%d", &quantity);
if (choice < 1 || choice > num_items) {
printf("Error: invalid item number\n");
return;
}
Item *item = &menu[choice - 1];
if (item->stock < quantity) {
printf("Error: not enough stock\n");
return;
}
total = item->price * quantity;
printf("Total: $%.2lf\n", total);
item->stock -= quantity;
}
void restock() {
int choice, quantity;
printf("Enter item number: ");
scanf("%d", &choice);
if (choice < 1 || choice > num_items) {
printf("Error: invalid item number\n");
return;
}
Item *item = &menu[choice - 1];
printf("Enter quantity: ");
scanf("%d", &quantity);
item->stock += quantity;
}
int main() {
int choice;
while (1) {
printf("Choose an option:\n");
printf("1. Add item to menu\n");
printf("2. Display menu\n");
printf("3. Place order\n");
printf("4. Restock item\n");
printf("5. Quit\n");
scanf("%d", &choice);
switch (choice) {
case 1:
add_item();
break;
case 2:
display_menu();
break;
case 3:
place_order();
break;
case 4:
restock();
break;
case 5:
exit(0);
break;
default:
printf("Error: invalid choice\n");
break;
}
}
return 0;
}
```
该示例实现了菜单管理、订单管理和库存管理等功能,其中菜单管理包括添加菜品、显示菜单;订单管理包括下单和计算总价;库存管理包括补货。
相关推荐
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.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_column_c1.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)