用Ubuntu编写一个C语言程序设计的酒店管理系统
时间: 2023-03-24 09:02:44 浏览: 189
好的,我可以回答这个问题。要编写一个C语言程序设计的酒店管理系统,你需要先确定系统的功能和需求,然后设计程序的结构和模块,最后编写代码并进行测试。在Ubuntu上,你可以使用gcc编译器来编译和运行C语言程序。具体的实现方法可以参考相关的教程和文档。
相关问题
用Ubuntu系统编写一个C语言程序设计酒店管理系统的代码
好的,我可以回答这个问题。以下是一个简单的酒店管理系统的C语言代码,可以在Ubuntu系统上编写和运行:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define MAX_ROOMS 100
struct Room {
int number;
char type[20];
int price;
int occupied;
};
struct Hotel {
char name[50];
struct Room rooms[MAX_ROOMS];
int num_rooms;
};
void initialize_hotel(struct Hotel *hotel, char *name) {
strcpy(hotel->name, name);
hotel->num_rooms = ;
}
void add_room(struct Hotel *hotel, int number, char *type, int price) {
if (hotel->num_rooms >= MAX_ROOMS) {
printf("Error: hotel is full\n");
return;
}
struct Room *room = &hotel->rooms[hotel->num_rooms];
room->number = number;
strcpy(room->type, type);
room->price = price;
room->occupied = ;
hotel->num_rooms++;
}
void print_hotel(struct Hotel *hotel) {
printf("Hotel: %s\n", hotel->name);
printf("Number of rooms: %d\n", hotel->num_rooms);
printf("Rooms:\n");
for (int i = ; i < hotel->num_rooms; i++) {
struct Room *room = &hotel->rooms[i];
printf("Room %d: %s, $%d per night, ", room->number, room->type, room->price);
if (room->occupied) {
printf("occupied\n");
} else {
printf("available\n");
}
}
}
int main() {
struct Hotel hotel;
initialize_hotel(&hotel, "My Hotel");
add_room(&hotel, 101, "Single", 50);
add_room(&hotel, 102, "Double", 75);
add_room(&hotel, 103, "Suite", 100);
print_hotel(&hotel);
return ;
}
用Ubuntu编写一个C语言程序设计的酒店管理系统源代码
好的,以下是一个使用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. 退出程序
你可以根据你的需求对程序进行修改和扩展。
阅读全文