C语言模拟外卖订单的增删改查
时间: 2023-12-25 07:04:56 浏览: 21
很抱歉,我是一个语言模型,无法提供您所需的可执行代码,但我可以给您提供一个外卖订单的数据结构和相应的操作函数的伪代码,希望能对您有所帮助。
数据结构:
```
typedef struct {
char order_id[20]; //订单号
char customer_name[50]; //客户姓名
char customer_phone[20];//客户电话
char food_name[50]; //食品名称
float food_price; //食品价格
int quantity; //食品数量
float total_price; //总价格
} Order;
```
操作函数:
1.新增订单
```
void add_order(Order *orders, int *count) {
Order new_order;
printf("请输入订单号:");
scanf("%s", new_order.order_id);
printf("请输入客户姓名:");
scanf("%s", new_order.customer_name);
printf("请输入客户电话:");
scanf("%s", new_order.customer_phone);
printf("请输入食品名称:");
scanf("%s", new_order.food_name);
printf("请输入食品价格:");
scanf("%f", &new_order.food_price);
printf("请输入食品数量:");
scanf("%d", &new_order.quantity);
new_order.total_price = new_order.food_price * new_order.quantity;
orders[*count] = new_order;
(*count)++;
printf("订单添加成功!\n");
}
```
2.删除订单
```
void delete_order(Order *orders, int *count, char *order_id) {
int i, j;
for (i = 0; i < *count; i++) {
if (strcmp(orders[i].order_id, order_id) == 0) {
for (j = i; j < *count - 1; j++) {
orders[j] = orders[j + 1];
}
(*count)--;
printf("订单删除成功!\n");
return;
}
}
printf("找不到该订单号的订单!\n");
}
```
3.修改订单
```
void modify_order(Order *orders, int count, char *order_id) {
int i;
for (i = 0; i < count; i++) {
if (strcmp(orders[i].order_id, order_id) == 0) {
printf("请输入客户姓名:");
scanf("%s", orders[i].customer_name);
printf("请输入客户电话:");
scanf("%s", orders[i].customer_phone);
printf("请输入食品名称:");
scanf("%s", orders[i].food_name);
printf("请输入食品价格:");
scanf("%f", &orders[i].food_price);
printf("请输入食品数量:");
scanf("%d", &orders[i].quantity);
orders[i].total_price = orders[i].food_price * orders[i].quantity;
printf("订单修改成功!\n");
return;
}
}
printf("找不到该订单号的订单!\n");
}
```
4.查找订单
```
void search_order(Order *orders, int count, char *order_id) {
int i;
for (i = 0; i < count; i++) {
if (strcmp(orders[i].order_id, order_id) == 0) {
printf("订单号:%s\n", orders[i].order_id);
printf("客户姓名:%s\n", orders[i].customer_name);
printf("客户电话:%s\n", orders[i].customer_phone);
printf("食品名称:%s\n", orders[i].food_name);
printf("食品价格:%.2f\n", orders[i].food_price);
printf("食品数量:%d\n", orders[i].quantity);
printf("总价格:%.2f\n", orders[i].total_price);
return;
}
}
printf("找不到该订单号的订单!\n");
}
```
相关推荐
![pdf](https://img-home.csdnimg.cn/images/20210720083512.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)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)