0% found this document useful (0 votes)
34 views12 pages

Hms Final

Uploaded by

pranavsp2810
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
34 views12 pages

Hms Final

Uploaded by

pranavsp2810
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 12

Hotel management systemin C+ +

Introduction:

This article discusses a C++ hotel management project that automates various
functions essential for hotel operations. The system offers a range of features,
including reserving rooms, reviewing customer information, modifying or
removing client records, and viewing all assigned rooms. By providing these
functionalities, the system enhances the efficiency of hotel management and
improves customer service. It ensures that hotel staff can easily handle
reservations and manage guest details, streamlining day-to-day operations and
improving overall organization.

The development of this project employs two key C++ concepts: classes and file
handling. Classes are used to encapsulate the data and behaviours associated
with hotel entities, such as customers and rooms, promoting modularity and
reusability in the code. File handling is crucial for maintaining persistent
records, allowing customer and room information to be stored in files that can
be accessed and updated as needed. By leveraging these concepts, the hotel
management system provides a robust and scalable solution for managing hotel
operations effectively.

1 NMPI/CO3K/2024-25
Hotel management systemin C+ +

Features of Hotel
• Show all rooms
• Book a room
• Show all bookings
• Exit

Advantages:
1. Performance: C++ offers fast and efficient execution, suitable
for real-time hotel operations.
2. Object-Oriented Programming (OOP): C++ allows modular
system design with classes for rooms, customers, etc.
3. Memory Management: Provides control over memory usage,
ensuring efficient resource handling.
4. Extensibility: The system can easily be extended with new
features or modules.
5. Cross-platform: C++ can be compiled for multiple operating
systems, offering deployment flexibility.

2 NMPI/CO3K/2024-25
Hotel management systemin C+ +

Source Code
#include <iostream>
#include <vector>
#include <string>
class Room {
int roomNumber;
std::string roomType;
bool isAvailable;
double price;
public:
Room(int number, std::string type, double price)
: roomNumber(number), roomType(type), isAvailable(true),
price(price) {}
int getRoomNumber() const { return roomNumber; }
std::string getRoomType() const { return roomType; }
bool checkAvailability() const { return isAvailable; }
void bookRoom() { isAvailable = false; }
void freeRoom() { isAvailable = true; }
double getPrice() const { return price; }
void displayDetails() const {
std::cout << "Room Number: " << roomNumber << ", Type: "
<< roomType
<< ", Price: $" << price << ", Available: " <<
(isAvailable ? "Yes" : "No") << std::endl;

3 NMPI/CO3K/2024-25
Hotel management systemin C+ +

}
};
class Guest {
std::string name;
std::string contact;
public:
Guest(std::string guestName, std::string guestContact)
: name(guestName), contact(guestContact) {}
std::string getName() const { return name; }
std::string getContact() const { return contact; }
void displayDetails() const {
std::cout << "Name: " << name << ", Contact: " << contact <<
std::endl;
}
};
class Booking {
Room &room;
Guest &guest;
int stayDuration;
double totalBill;
public:
Booking(Room &r, Guest &g, int days)
: room(r), guest(g), stayDuration(days) {
room.bookRoom();

4 NMPI/CO3K/2024-25
Hotel management systemin C+ +

totalBill = stayDuration * room.getPrice();


}
void checkOut() {
room.freeRoom();
std::cout << "Checkout successful! Total bill: $" << totalBill <<
std::endl;
}
void displayBookingDetails() const {
std::cout << "Booking Details:\n";
room.displayDetails();
guest.displayDetails();
std::cout << "Stay Duration: " << stayDuration << " days\n"
<< "Total Bill: $" << totalBill << std::endl;
}
};
class Hotel {
std::vector<Room> rooms;
std::vector<Guest> guests;
std::vector<Booking> bookings;
public:
void addRoom(int number, std::string type, double price) {
rooms.emplace_back(number, type, price);
}
void addGuest(std::string name, std::string contact) {

5 NMPI/CO3K/2024-25
Hotel management systemin C+ +

guests.emplace_back(name, contact);
}
Room* findAvailableRoom(std::string type) {
for (auto &room : rooms) {
if (room.getRoomType() == type &&
room.checkAvailability()) {
return &room;
}
}
return nullptr;
}
void bookRoom(std::string roomType, std::string guestName,
std::string guestContact, int days) {
Room* room = findAvailableRoom(roomType);
if (room) {
guests.emplace_back(guestName, guestContact);
Booking booking(*room, guests.back(), days);
bookings.push_back(booking);
std::cout << "Room booked successfully!" << std::endl;
} else {
std::cout << "Sorry, no available rooms of the specified type."
<< std::endl;
}
}

6 NMPI/CO3K/2024-25
Hotel management systemin C+ +

void showRooms() const {


for (const auto &room : rooms) {
room.displayDetails();
}
}
void showGuests() const {
for (const auto &guest : guests) {
guest.displayDetails();
}
}
void showBookings() const {
for (const auto &booking : bookings) {
booking.displayBookingDetails();
}
}
};
int main() {
Hotel hotel;
// Pre-populate the hotel with some rooms
hotel.addRoom(101, "Single", 100.0);
hotel.addRoom(102, "Double", 150.0);
hotel.addRoom(103, "Suite", 250.0);
int choice;
do {

7 NMPI/CO3K/2024-25
Hotel management systemin C+ +

std::cout << "\nHotel Management System\n";


std::cout << "1. Show all rooms\n";
std::cout << "2. Book a room\n";
std::cout << "3. Show all bookings\n";
std::cout << "4. Exit\n";
std::cout << "Enter your choice: ";
std::cin >> choice;
switch (choice) {
case 1: {
hotel.showRooms();
break;
}
case 2: {
std::string name, contact, roomType;
int days;
std::cin.ignore(); // Clear the buffer
std::cout << "Enter your name: ";
std::getline(std::cin, name);
std::cout << "Enter your contact number: ";
std::getline(std::cin, contact);
std::cout << "Enter room type (Single/Double/Suite): ";
std::getline(std::cin, roomType);
std::cout << "Enter number of days: ";
std::cin >> days;

8 NMPI/CO3K/2024-25
Hotel management systemin C+ +

hotel.bookRoom(roomType, name, contact, days);


break;
}
case 3: {
hotel.showBookings();
break;
}
case 4: {
std::cout << "Exiting the system.\n";
break;
}
default: {
std::cout << "Invalid choice. Please try again.\n";
}
}
} while (choice! = 4);
return 0;
}

Output:

9 NMPI/CO3K/2024-25
Hotel management systemin C+ +

Conclusion:

10 NMPI/CO3K/2024-25
Hotel management systemin C+ +

PURPOSE OF THE SYSTEM The Hotel Management Systemics to


makes imperative’s interaction with the various modules of the Hotel
and ease the process of acquiring information and providing services.
It seeks to improve efficiency and operational process performance,
strategies are established so that a hotel can be differentiated from
what its competitor or offer, better ways are sought to improve user
experience and customer satisfaction, etc

11 NMPI/CO3K/2024-25
Hotel management systemin C+ +

Reference:
https://www.javatpoint.com/
https://www.cppbuzz.com/
www.google.com

12 NMPI/CO3K/2024-25

You might also like