用Ubuntu编写一个C语言程序设计的酒店管理系统源代码
时间: 2023-03-22 07:03:49 浏览: 195
好的,以下是一个使用Ubuntu操作系统编写的C语言程序的示例,用于管理一家酒店:
```c
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define MAX_ROOMS 100
#define MAX_NAME 50
typedef struct {
int room_number;
char guest_name[MAX_NAME];
int num_of_nights;
float rate;
} Room;
int main()
{
Room rooms[MAX_ROOMS];
int num_rooms = 0;
int choice;
int i;
while (1) {
printf("\n\nHotel Management System\n");
printf("-----------------------\n");
printf("1. Add Room\n");
printf("2. Remove Room\n");
printf("3. View Rooms\n");
printf("4. Exit\n");
printf("\nEnter your choice: ");
scanf("%d", &choice);
switch (choice) {
case 1:
if (num_rooms == MAX_ROOMS) {
printf("Error: Maximum number of rooms reached.\n");
break;
}
printf("\nEnter room number: ");
scanf("%d", &rooms[num_rooms].room_number);
printf("Enter guest name: ");
scanf("%s", rooms[num_rooms].guest_name);
printf("Enter number of nights: ");
scanf("%d", &rooms[num_rooms].num_of_nights);
printf("Enter rate per night: ");
scanf("%f", &rooms[num_rooms].rate);
num_rooms++;
printf("\nRoom added successfully.\n");
break;
case 2:
if (num_rooms == 0) {
printf("Error: No rooms to remove.\n");
break;
}
printf("\nEnter room number to remove: ");
int room_number;
scanf("%d", &room_number);
for (i = 0; i < num_rooms; i++) {
if (rooms[i].room_number == room_number) {
num_rooms--;
rooms[i] = rooms[num_rooms];
printf("\nRoom removed successfully.\n");
break;
}
}
if (i == num_rooms) {
printf("\nError: Room not found.\n");
}
break;
case 3:
if (num_rooms == 0) {
printf("\nNo rooms found.\n");
break;
}
printf("\nRoom Number\tGuest Name\tNumber of Nights\tRate per Night\n");
printf("----------------------------------------------------------------\n");
for (i = 0; i < num_rooms; i++) {
printf("%d\t\t%s\t\t%d\t\t%.2f\n", rooms[i].room_number, rooms[i].guest_name, rooms[i].num_of_nights, rooms[i].rate);
}
break;
case 4:
printf("\nGoodbye!\n");
exit(0);
default:
printf("\nError: Invalid choice.\n");
break;
}
}
return 0;
}
```
这个程序使用结构体来存储每个房间的信息,包括房间号、客人姓名、入住天数和每晚的费率。程序提供了以下操作:
1. 添加房间
2. 删除房间
3. 查看房间
4. 退出程序
你可以根据你的需求对程序进行修改和扩展。
阅读全文