Ohhh
Ohhh
#include <string>
#include <fstream>
#include <vector>
#include <stack>
#include <list>
#include <algorithm>
#include <sstream>
#include <cctype>
#include <limits>
struct Guest {
string name;
int age;
string gender;
string contactNumber;
};
// Structure to hold hotel booking information
struct HotelBooking {
Guest guest;
string hotelLocation;
string roomType;
string roomNumber;
string checkInDate;
string checkOutDate;
checkOutDate == other.checkOutDate;
};
stack<HotelBooking> bookingHistory;
list<HotelBooking> bookingsList;
// Constants
string availableRooms[ROOMS] = {
};
void showMainMenu();
void bookHotel();
void viewBookings();
void changeBooking();
void cancelBooking();
void saveBookingsToFile();
void loadBookingsFromFile();
int main() {
loadBookingsFromFile();
showMainMenu();
return 0;
void showMainMenu() {
int choice;
do {
system("cls");
switch (choice) {
case 1:
bookHotel();
break;
case 2:
viewBookings();
break;
case 3:
changeBooking();
break;
case 4:
cancelBooking();
break;
case 5:
break;
default:
cout << RED << "Invalid choice. Please try again.\n" << RESET;
if (choice != 5) {
cin.ignore();
cin.get();
void bookHotel() {
system("cls");
HotelBooking booking;
while (true) {
cout << GREEN << "Enter your name (First Name Last Name): " <<
RESET;
getline(cin, booking.guest.name);
if (isValidName(booking.guest.name)) {
break;
} else {
cout << RED << "Invalid input. Please enter a valid name.\n" <<
RESET << endl;
}
// Input age
cout << GREEN << "Enter your age: " << RESET;
while (true) {
cin.clear();
cin.ignore(numeric_limits<streamsize>::max(), '\n');
cout << RED << "Please enter a valid age (18 or older): " << RESET;
} else {
cin.ignore(numeric_limits<streamsize>::max(), '\n');
break;
// Input gender
cout << GREEN << "Enter your gender (Male 'M', Female 'F'): " <<
RESET;
while (true) {
cin.ignore(numeric_limits<streamsize>::max(), '\n');
// Convert to uppercase
booking.guest.gender = toupper(booking.guest.gender[0]);
break;
} else {
cout << RED << "Please enter 'M' for Male or 'F' for Female: " <<
RESET;
cout << GREEN << "Enter your contact number (11 digits starting with
'09'): " << RESET;
while (true) {
if (isValidContactNumber(booking.guest.contactNumber)) {
break;
} else {
cout << RED << "Must be exactly 11 digits and start with '09': " <<
RESET;
int roomCount = 0;
cout << YELLOW << ". " << availableRooms[i] << "\t";
roomCount++;
if (roomCount == 5) {
roomCount = 0;
}
cout << GREEN << "Enter room type (Single/Double/Suite): " << RESET;
while (true) {
booking.roomType[0] = toupper(booking.roomType[0]);
break;
} else {
cout << RED << "Invalid room type. Please enter 'Single', 'Double',
or 'Suite': " << RESET;
generateRoomNumber(booking);
assignRoomSchedule(booking);
<< " room) is: " << fixed << setprecision(2) << totalPrice << " PHP."
<< RESET << endl;
bookingsList.push_back(booking);
bookingHistory.push(booking);
cout << GREEN << "Booking successful! Please proceed with payment.\n"
<< RESET << endl;
processPayment(totalPrice);
showMainMenu();
roomCounter++;
cout << "\tYour room number is: " << booking.roomNumber << endl;
while (true) {
cout << "\tEnter check-in date (DD/MM/YYYY): ";
break;
} else {
cout << RED << "\tInvalid date format! Please use DD/MM/YYYY.\n"
<< RESET;
while (true) {
break;
} else {
cout << RED << "\tCheck-out date must be after check-in date.\n"
<< RESET;
} else {
cout << RED << "\tInvalid date format! Please use DD/MM/YYYY.\n"
<< RESET;
}
}
if (roomType == "Single") {
return price;
void viewBookings() {
loadBookingsFromFile();
system("cls");
if (bookingsList.empty()) {
cout << RED << "No bookings found.\n" << RESET << endl;
} else {
cout << CYAN << "=== Your Bookings ===\n" << RESET;
cout << YELLOW << "\nPress Enter to return to the main menu..." <<
RESET;
cin.ignore();
cin.get();
showMainMenu();
void changeBooking() {
if (bookingsList.empty()) {
cout << RED << "No bookings found to change.\n" << RESET << endl;
cout << YELLOW << "\nPress Enter to return to the main menu..." <<
RESET;
cin.ignore();
cin.get();
system("cls"); // Clear the console
showMainMenu();
return;
} else {
int index = 0;
cout << CYAN << "=== Your Bookings ===\n" << RESET;
cout << GREEN << "INDEX: " << index++ << RESET << endl;
int bookingIndex;
cout << "\tEnter the index of the booking you want to change: ";
cin.clear();
cin.ignore(numeric_limits<streamsize>::max(), '\n');
cout << RED << "Invalid index. Returning to main menu.\n" <<
RESET << endl;
cout << YELLOW << "\nPress Enter to return to the main menu..."
<< RESET;
cin.ignore();
cin.get();
showMainMenu();
return;
auto it = bookingsList.begin();
advance(it, bookingIndex);
char changeName;
cout << "\tCurrent Guest Name: " << booking.guest.name << endl;
cout << "\tDo you want to change the guest name? (y/n): ";
cin.ignore();
getline(cin, booking.guest.name);
if (!isValidName(booking.guest.name)) {
cout << RED << "\tInvalid name. Name not changed.\n" <<
RESET << endl;
}
// Change room type
char changeRoomType;
cout << "\tCurrent Room Type: " << booking.roomType << endl;
cout << "\tDo you want to change the room type? (y/n): ";
booking.roomType[0] = toupper(booking.roomType[0]);
} else {
cout << RED << "\tInvalid room type. Room type not changed.\n"
<< RESET << endl;
char changeDates;
cout << "\tCurrent Check-in Date: " << booking.checkInDate << endl;
cout << "\tDo you want to change the check-in and check-out dates?
(y/n): ";
assignRoomSchedule(booking);
cout << GREEN << "\tBooking updated successfully!\n" << RESET <<
endl;
cout << YELLOW << "\nPress Enter to return to the main menu..." <<
RESET;
cin.ignore();
cin.get();
showMainMenu();
void cancelBooking() {
if (bookingsList.empty()) {
cout << RED << "No bookings found to cancel.\n" << RESET << endl;
} else {
int index = 0;
cout << CYAN << "=== Your Bookings ===\n" << RESET;
cout << GREEN << "INDEX: " << index++ << RESET << endl;
int bookingIndex;
cout << "\tEnter the index of the booking you want to cancel: ";
cin.clear();
cin.ignore(numeric_limits<streamsize>::max(), '\n');
cout << RED << "Invalid index. Returning to main menu.\n" <<
RESET << endl;
cout << YELLOW << "\nPress Enter to return to the main menu..."
<< RESET;
cin.ignore();
cin.get();
showMainMenu();
return;
auto it = bookingsList.begin();
advance(it, bookingIndex);
char confirm;
cout << "\tAre you sure you want to cancel the booking for " << it-
>guest.name<< "? (y/n): ";
bookingsList.erase(it);
} else {
cout << YELLOW << "\nPress Enter to return to the main menu..." <<
RESET;
cin.ignore();
cin.get();
showMainMenu();
if (bookingsLoaded) {
return;
ifstream file("bookings.txt");
HotelBooking booking;
if (file.is_open()) {
bookingsList.push_back(booking);
file.close();
cout << GREEN << "Bookings loaded successfully.\n" << RESET <<
endl;
} else {
cout << YELLOW << "Unable to open bookings file. Starting with empty
bookings list.\n" << RESET << endl;
}
void processPayment(double totalPrice) {
int paymentOption;
cout << "Total Amount Due: " << fixed << setprecision(2) << totalPrice
<< " PHP\n";
switch (paymentOption) {
case 1:
cout<<" "<<endl;
break;
case 2:
cout<<" "<<endl;
break;
case 3:
cout<<" "<<endl;
cout << "You selected PayPal. Processing payment...\n";
break;
case 4:
cout<<" "<<endl;
break;
default:
cout<<" "<<endl;
cout << RED << "Invalid choice. Returning to main menu.\n" <<
RESET;
return;
cout << GREEN << "Payment successful! Your booking has been
confirmed.\n" << RESET;
cout << YELLOW << "\nPress Enter to return to the main menu..." <<
RESET;
cin.ignore();
cin.get();
showMainMenu();
return true;
char ch = name[i];
firstNameValid = true;
// Allow spaces
spaceCount++;
if (spaceCount > 1) {
} else {
return false;
return hasValidCharacter;