用C写一个餐厅管理系统
时间: 2023-05-13 12:05:15 浏览: 145
餐饮管理系统(C语言编写)
5星 · 资源好评率100%
好的,我可以为您提供一个基本的餐厅管理系统的代码示例,如下:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define MAX_MENU_ITEMS 100
#define MAX_ORDER_ITEMS 100
typedef struct {
char name[50];
float price;
} MenuItem;
typedef struct {
MenuItem menu[MAX_MENU_ITEMS];
int num_items;
} Menu;
typedef struct {
MenuItem item;
int quantity;
} OrderItem;
typedef struct {
OrderItem items[MAX_ORDER_ITEMS];
int num_items;
float total_price;
} Order;
void print_menu(Menu menu) {
printf("Menu:\n");
for (int i = 0; i < menu.num_items; i++) {
printf("%d. %s - $%.2f\n", i+1, menu.menu[i].name, menu.menu[i].price);
}
}
void add_menu_item(Menu *menu, char *name, float price) {
MenuItem item;
strcpy(item.name, name);
item.price = price;
menu->menu[menu->num_items++] = item;
}
void place_order(Menu menu, Order *order) {
int choice, quantity;
do {
print_menu(menu);
printf("Enter item number to add to order (0 to finish): ");
scanf("%d", &choice);
if (choice > 0 && choice <= menu.num_items) {
printf("Enter quantity: ");
scanf("%d", &quantity);
OrderItem item;
item.item = menu.menu[choice-1];
item.quantity = quantity;
order->items[order->num_items++] = item;
order->total_price += item.item.price * quantity;
}
} while (choice != 0);
}
void print_order(Order order) {
printf("Order:\n");
for (int i = 0; i < order.num_items; i++) {
printf("%d. %s x%d - $%.2f\n", i+1, order.items[i].item.name, order.items[i].quantity, order.items[i].item.price * order.items[i].quantity);
}
printf("Total price: $%.2f\n", order.total_price);
}
int main() {
Menu menu;
menu.num_items = 0;
add_menu_item(&menu, "Hamburger", 5.99);
add_menu_item(&menu, "Cheeseburger", 6.99);
add_menu_item(&menu, "Fries", 2.99);
add_menu_item(&menu, "Onion Rings", 3.99);
add_menu_item(&menu, "Soda", 1.99);
Order order;
order.num_items = 0;
order.total_price = 0.0;
place_order(menu, &order);
print_order(order);
return 0;
}
阅读全文