-
Notifications
You must be signed in to change notification settings - Fork 1
/
Hotel Management System Project.c
102 lines (88 loc) · 2.89 KB
/
Hotel Management System Project.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
#include <stdio.h>
#include <string.h>
#define MAX_ROOMS 50
#define MAX_NAME_LENGTH 50
typedef struct {
int roomNumber;
char guestName[MAX_NAME_LENGTH];
int isReserved;
double roomRate;
} Room;
Room rooms[MAX_ROOMS];
void initializeRooms() {
for (int i = 0; i < MAX_ROOMS; i++) {
rooms[i].roomNumber = i + 1;
strcpy(rooms[i].guestName, "");
rooms[i].isReserved = 0;
rooms[i].roomRate = 100.0; // Default room rate
}
}
void displayRooms() {
printf("Room Number\tGuest Name\tReservation\tRoom Rate\n");
for (int i = 0; i < MAX_ROOMS; i++) {
printf("%d\t\t%s\t\t%s\t\t%.2f\n", rooms[i].roomNumber, rooms[i].guestName,
rooms[i].isReserved ? "Reserved" : "Available", rooms[i].roomRate);
}
}
void reserveRoom(int roomNumber, const char *guestName) {
if (roomNumber < 1 || roomNumber > MAX_ROOMS) {
printf("Invalid room number.\n");
return;
}
if (rooms[roomNumber - 1].isReserved) {
printf("Room %d is already reserved.\n", roomNumber);
return;
}
rooms[roomNumber - 1].isReserved = 1;
strcpy(rooms[roomNumber - 1].guestName, guestName);
printf("Room %d has been reserved for %s.\n", roomNumber, guestName);
}
void setRoomRate(int roomNumber, double rate) {
if (roomNumber < 1 || roomNumber > MAX_ROOMS) {
printf("Invalid room number.\n");
return;
}
rooms[roomNumber - 1].roomRate = rate;
printf("Room rate for room %d has been set to %.2f.\n", roomNumber, rate);
}
int main() {
initializeRooms();
int choice;
do {
printf("\nHotel Management System\n");
printf("1. Display Rooms\n");
printf("2. Reserve Room\n");
printf("3. Set Room Rate\n");
printf("4. Exit\n");
printf("Enter your choice: ");
scanf("%d", &choice);
switch (choice) {
case 1:
displayRooms();
break;
case 2:
int roomNumber;
char guestName[MAX_NAME_LENGTH];
printf("Enter room number: ");
scanf("%d", &roomNumber);
printf("Enter guest name: ");
scanf("%s", guestName);
reserveRoom(roomNumber, guestName);
break;
case 3:
printf("Enter room number: ");
scanf("%d", &roomNumber);
double roomRate;
printf("Enter new room rate: ");
scanf("%lf", &roomRate);
setRoomRate(roomNumber, roomRate);
break;
case 4:
printf("Exiting the system.\n");
break;
default:
printf("Invalid choice. Please try again.\n");
}
} while (choice != 4);
return 0;
}