Sure, here is an example of a hotel reservation system implemented in C++:
#include <iostream>
#include <string>
#include <vector>
using namespace std;
// Define a guest class
class Guest {
public:
Guest(string name, string email, string phone) : name(name), email(email), phone(phone) {}
string getName() const {
return name;
}
string getEmail() const {
return email;
}
string getPhone() const {
return phone;
}
private:
string name;
string email;
string phone;
};
// Define a room class
class Room {
public:
Room(int roomNumber, string roomType, double price) : roomNumber(roomNumber), roomType(roomType), price(price) {
available = true;
}
int getRoomNumber() const {
return roomNumber;
}
string getRoomType() const {
return roomType;
}
double getPrice() const {
return price;
}
bool isAvailable() const {
return available;
}
void setAvailability(bool availability) {
available = availability;
}
private:
int roomNumber;
string roomType;
double price;
bool available;
};
// Define a reservation class
class Reservation {
public:
Reservation(Guest guest, Room room, string startDate, string endDate) : guest(guest), room(room), startDate(startDate), endDate(endDate) {}
Guest getGuest() const {
return guest;
}
Room getRoom() const {
return room;
}
string getStartDate() const {
return startDate;
}
string getEndDate() const {
return endDate;
}
private:
Guest guest;
Room room;
string startDate;
string endDate;
};
// Define a hotel class
class Hotel {
public:
Hotel(string name) : name(name) {}
string getName() const {
return name;
}
void addRoom(Room room) {
rooms.push_back(room);
}
void addReservation(Reservation reservation) {
reservations.push_back(reservation);
}
void listRooms() const {
for (const Room& room : rooms) {
cout << "Room number: " << room.getRoomNumber() << endl;
cout << "Room type: " << room.getRoomType() << endl;
cout << "Price per night: $" << room.getPrice() << endl;
if (room.isAvailable()) {
cout << "Availability: Available" << endl;
} else {
cout << "Availability: Not available" << endl;
}
cout << endl;
}
}
void listReservations() const {
for (const Reservation& reservation : reservations) {
cout << "Guest name: " << reservation.getGuest().getName() << endl;
cout << "Room number: " << reservation.getRoom().getRoomNumber() << endl;
cout << "Start date: " << reservation.getStartDate() << endl;
cout << "End date: " << reservation.getEndDate() << endl;
cout << endl;
}
}
private:
string name;
vector<Room> rooms;
vector<Reservation> reservations;
};
int main() {
// Create a hotel object
Hotel hotel("My Hotel");
// Add rooms to the hotel
Room room1(101, "Single", 50.00);
Room room2(102, "Double", 75.00);
Room room3(103, "Double", 75.00);
Room room4(104, "Suite", 100.00);
hotel.addRoom(room1);
hotel.addRoom(room2);
hotel.addRoom(room3);
hotel.addRoom(room4);
// Make reservations
Guest guest1("John Smith", "john@example.com", "555-1234");
Reservation reservation1(guest1, room1, "2022-01-01", "2022-01-03");
hotel.addReservation(reservation1);
Guest guest2("Jane Doe", "jane@example.com", "555-5678");
Reservation reservation2(guest2, room2, "2022-02-01", "2022-02-05");
hotel.addReservation(reservation2);
// Display room and reservation information
cout << "Available rooms at " << hotel.getName() << ":" << endl;
hotel.listRooms();
cout << "Reservations at " << hotel.getName() << ":" << endl;
hotel.listReservations();
return 0;
}
This code defines a hotel reservation system using classes for Guests, Rooms, Reservations, and the Hotel itself. The main() function creates a Hotel object and adds Rooms to it, makes Reservations for those Rooms with Guests, and then lists the available Rooms and Reservations.