c语言酒店入住系统课程设计
时间: 2023-12-23 21:04:31 浏览: 112
好的,下面是一个基于C语言的酒店入住系统课程设计方案:
1. 系统需求分析
- 酒店管理员需要能够添加、编辑和删除酒店房间信息
- 客人需要能够浏览酒店房间信息,并且进行预订
- 酒店管理员需要能够管理客人的预订信息,并且进行确认或取消操作
- 客人需要能够查看自己的预订信息,并且能够修改或取消预订
- 酒店管理员需要能够查看房间的占用情况和客人入住信息
2. 系统设计
- 数据结构设计:设计房间、客人和预订信息的数据结构,并且建立它们之间的关系
- 系统功能设计:实现管理员添加、编辑和删除房间信息的功能,客人浏览和预订房间的功能,管理员管理客人预订信息的功能,客人查看和修改预订信息的功能,管理员查看房间占用情况和客人入住信息的功能
3. 系统实现
- 使用C语言实现系统的业务逻辑和数据访问层
- 使用控制台展示系统的界面
- 使用文件存储系统的数据,例如使用文本文件存储房间、客人和预订信息
以下是一个基于C语言的酒店入住系统的简单实现代码示例,仅供参考:
```c
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define MAX_ROOMS 100
#define MAX_GUESTS 100
#define MAX_BOOKINGS 100
// 定义房间结构体
typedef struct Room {
int room_number;
char room_type[20];
float room_rate;
int is_occupied;
} Room;
// 定义客人结构体
typedef struct Guest {
char name[50];
char address[100];
char phone_number[20];
} Guest;
// 定义预订结构体
typedef struct Booking {
int room_number;
Guest guest;
char check_in_date[20];
char check_out_date[20];
int is_confirmed;
} Booking;
// 定义全局变量
Room rooms[MAX_ROOMS];
int num_rooms = 0;
Booking bookings[MAX_BOOKINGS];
int num_bookings = 0;
// 添加房间函数
void add_room() {
Room room;
printf("Enter room number: ");
scanf("%d", &room.room_number);
printf("Enter room type: ");
scanf("%s", room.room_type);
printf("Enter room rate: ");
scanf("%f", &room.room_rate);
room.is_occupied = 0;
rooms[num_rooms++] = room;
printf("Room added successfully.\n");
}
// 编辑房间函数
void edit_room() {
int room_number;
printf("Enter room number to edit: ");
scanf("%d", &room_number);
for (int i = 0; i < num_rooms; i++) {
if (rooms[i].room_number == room_number) {
printf("Enter new room number: ");
scanf("%d", &rooms[i].room_number);
printf("Enter new room type: ");
scanf("%s", rooms[i].room_type);
printf("Enter new room rate: ");
scanf("%f", &rooms[i].room_rate);
printf("Room edited successfully.\n");
return;
}
}
printf("Room not found.\n");
}
// 删除房间函数
void delete_room() {
int room_number;
printf("Enter room number to delete: ");
scanf("%d", &room_number);
for (int i = 0; i < num_rooms; i++) {
if (rooms[i].room_number == room_number) {
for (int j = i; j < num_rooms - 1; j++) {
rooms[j] = rooms[j + 1];
}
num_rooms--;
printf("Room deleted successfully.\n");
return;
}
}
printf("Room not found.\n");
}
// 显示房间函数
void display_rooms() {
printf("Room Number\tRoom Type\tRoom Rate\tIs Occupied\n");
for (int i = 0; i < num_rooms; i++) {
printf("%d\t\t%s\t\t%.2f\t\t%s\n", rooms[i].room_number, rooms[i].room_type, rooms[i].room_rate, rooms[i].is_occupied ? "Yes" : "No");
}
}
// 预订房间函数
void book_room() {
Booking booking;
printf("Enter room number to book: ");
scanf("%d", &booking.room_number);
for (int i = 0; i < num_rooms; i++) {
if (rooms[i].room_number == booking.room_number) {
if (rooms[i].is_occupied) {
printf("Room is already occupied.\n");
return;
}
printf("Enter guest name: ");
scanf("%s", booking.guest.name);
printf("Enter guest address: ");
scanf("%s", booking.guest.address);
printf("Enter guest phone number: ");
scanf("%s", booking.guest.phone_number);
printf("Enter check-in date: ");
scanf("%s", booking.check_in_date);
printf("Enter check-out date: ");
scanf("%s", booking.check_out_date);
booking.is_confirmed = 0;
bookings[num_bookings++] = booking;
rooms[i].is_occupied = 1;
printf("Room booked successfully.\n");
return;
}
}
printf("Room not found.\n");
}
// 管理预订函数
void manage_bookings() {
int choice;
printf("1. Confirm booking\n");
printf("2. Cancel booking\n");
printf("Enter your choice: ");
scanf("%d", &choice);
switch (choice) {
case 1:
// 确认预订
confirm_booking();
break;
case 2:
// 取消预订
cancel_booking();
break;
default:
printf("Invalid choice.\n");
break;
}
}
// 确认预订函数
void confirm_booking() {
int room_number;
printf("Enter room number to confirm booking: ");
scanf("%d", &room_number);
for (int i = 0; i < num_bookings; i++) {
if (bookings[i].room_number == room_number) {
bookings[i].is_confirmed = 1;
printf("Booking confirmed successfully.\n");
return;
}
}
printf("Booking not found.\n");
}
// 取消预订函数
void cancel_booking() {
int room_number;
printf("Enter room number to cancel booking: ");
scanf("%d", &room_number);
for (int i = 0; i < num_bookings; i++) {
if (bookings[i].room_number == room_number) {
for (int j = i; j < num_bookings - 1; j++) {
bookings[j] = bookings[j + 1];
}
num_bookings--;
printf("Booking cancelled successfully.\n");
return;
}
}
printf("Booking not found.\n");
}
// 显示预订函数
void display_bookings() {
printf("Room Number\tGuest Name\tCheck-in Date\tCheck-out Date\tIs Confirmed\n");
for (int i = 0; i < num_bookings; i++) {
printf("%d\t\t%s\t\t%s\t\t%s\t\t%s\n", bookings[i].room_number, bookings[i].guest.name, bookings[i].check_in_date, bookings[i].check_out_date, bookings[i].is_confirmed ? "Yes" : "No");
}
}
// 显示菜单函数
void display_menu() {
printf("1. Add room\n");
printf("2. Edit room\n");
printf("3. Delete room\n");
printf("4. Display rooms\n");
printf("5. Book room\n");
printf("6. Manage bookings\n");
printf("7. Display bookings\n");
printf("8. Exit\n");
}
// 保存数据到文件函数
void save_data() {
FILE *fp;
fp = fopen("data.txt", "w");
if (fp == NULL) {
printf("Error opening file.\n");
return;
}
fprintf(fp, "%d\n", num_rooms);
for (int i = 0; i < num_rooms; i++) {
fprintf(fp, "%d %s %.2f %d\n", rooms[i].room_number, rooms[i].room_type, rooms[i].room_rate, rooms[i].is_occupied);
}
fprintf(fp, "%d\n", num_bookings);
for (int i = 0; i < num_bookings; i++) {
fprintf(fp, "%d %s %s %s %s %d\n", bookings[i].room_number, bookings[i].guest.name, bookings[i].guest.address, bookings[i].guest.phone_number, bookings[i].check_in_date, bookings[i].check_out_date, bookings[i].is_confirmed);
}
fclose(fp);
printf("Data saved successfully.\n");
}
// 加载数据从文件函数
void load_data() {
FILE *fp;
fp = fopen("data.txt", "r");
if (fp == NULL) {
printf("Error opening file.\n");
return;
}
fscanf(fp, "%d", &num_rooms);
for (int i = 0; i < num_rooms; i++) {
Room room;
fscanf(fp, "%d %s %f %d", &room.room_number, room.room_type, &room.room_rate, &room.is_occupied);
rooms[i] = room;
}
fscanf(fp, "%d", &num_bookings);
for (int i = 0; i < num_bookings; i++) {
Booking booking;
fscanf(fp, "%d %s %s %s %s %d", &booking.room_number, booking.guest.name, booking.guest.address, booking.guest.phone_number, booking.check_in_date, booking.check_out_date, &booking.is_confirmed);
bookings[i] = booking;
}
fclose(fp);
printf("Data loaded successfully.\n");
}
int main() {
int choice;
load_data();
do {
display_menu();
printf("Enter your choice: ");
scanf("%d", &choice);
switch (choice) {
case 1:
add_room();
break;
case 2:
edit_room();
break;
case 3:
delete_room();
break;
case 4:
display_rooms();
break;
case 5:
book_room();
break;
case 6:
manage_bookings();
break;
case 7:
display_bookings();
break;
case 8:
save_data();
break;
default:
printf("Invalid choice.\n");
break;
}
} while (choice != 8);
return 0;
}
```
以上是一个基于C语言的酒店入住系统的简单实现代码示例,具体的实现过程中还需要根据具体需求进行微调和修改。
阅读全文