C语言 酒店管理系统 结账
时间: 2023-09-23 15:07:12 浏览: 122
以下是一个简单的C语言酒店管理系统结账功能的代码:
```c
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define MAX_ROOMS 100
#define MAX_NAME 50
typedef struct {
char name[MAX_NAME];
int room_number;
int days_stayed;
int room_rate;
} Guest;
Guest guests[MAX_ROOMS]; // 客人信息数组
int num_guests = 0; // 客人数量
void add_guest() {
Guest guest;
printf("请输入客人姓名:");
scanf("%s", guest.name);
printf("请输入房间号码:");
scanf("%d", &guest.room_number);
printf("请输入停留天数:");
scanf("%d", &guest.days_stayed);
printf("请输入房间费用:");
scanf("%d", &guest.room_rate);
guests[num_guests++] = guest;
}
void print_guest(Guest guest) {
printf("%s\t\t%d\t\t%d\t\t%d\t\t%d\n", guest.name, guest.room_number, guest.days_stayed, guest.room_rate, guest.days_stayed * guest.room_rate);
}
void list_guests() {
printf("姓名\t\t房间号码\t停留天数\t房间费用\t总费用\n");
for (int i = 0; i < num_guests; i++) {
print_guest(guests[i]);
}
}
void remove_guest() {
int room_number;
printf("请输入要删除的客人的房间号码:");
scanf("%d", &room_number);
for (int i = 0; i < num_guests; i++) {
if (guests[i].room_number == room_number) {
for (int j = i; j < num_guests - 1; j++) {
guests[j] = guests[j + 1];
}
num_guests--;
printf("客人信息已删除。\n");
return;
}
}
printf("未找到该客人的房间号码。\n");
}
int main() {
int choice;
while (1) {
printf("请选择要执行的操作:\n");
printf("1. 添加客人\n");
printf("2. 列出客人\n");
printf("3. 删除客人\n");
printf("4. 退出\n");
printf("请选择操作:");
scanf("%d", &choice);
switch (choice) {
case 1:
add_guest();
break;
case 2:
list_guests();
break;
case 3:
remove_guest();
break;
case 4:
exit(0);
default:
printf("无效的选项,请重试。\n");
}
}
return 0;
}
```
该程序使用了一个简单的结构体来存储客人信息,包括姓名、房间号码、停留天数和房间费用。通过添加、列出和删除客人来管理客人信息。在列出客人时,程序会计算每个客人的总费用。
阅读全文