project code
project code
#include <fstream>
#include <string>
using namespace std;
class Hotel {
public:
void mainMenu();
void bookRoom();
void viewCustomers();
void searchCustomer();
void checkOut();
};
void Hotel::mainMenu() {
int choice;
do {
cout << "\n========== Hotel Management System ==========\n";
cout << "1. Book a Room\n";
cout << "2. View All Customers\n";
cout << "3. Search Customer\n";
cout << "4. Check-Out\n";
cout << "5. Exit\n";
cout << "Enter your choice: ";
cin >> choice;
switch (choice) {
case 1:
bookRoom();
break;
case 2:
viewCustomers();
break;
case 3:
searchCustomer();
break;
case 4:
checkOut();
break;
case 5:
cout << "Exiting program...\n";
exit(0);
default:
cout << "Invalid choice. Try again.\n";
}
} while (true);
}
void Hotel::bookRoom() {
string name, phone;
int roomNo;
void Hotel::viewCustomers() {
string name, phone;
int roomNo;
ifstream inFile("customers.txt");
cout << "\nList of Customers:\n";
cout << "Name\tRoom\tPhone\n";
cout << "----------------------------\n";
while (inFile >> name >> roomNo >> phone) {
cout << name << "\t" << roomNo << "\t" << phone << "\n";
}
inFile.close();
}
void Hotel::searchCustomer() {
string targetName, name, phone;
int roomNo;
bool found = false;
ifstream inFile("customers.txt");
while (inFile >> name >> roomNo >> phone) {
if (name == targetName) {
cout << "\nCustomer Found:\n";
cout << "Name: " << name << "\nRoom: " << roomNo << "\nPhone: " <<
phone << "\n";
found = true;
break;
}
}
if (!found) {
cout << "Customer not found.\n";
}
inFile.close();
}
void Hotel::checkOut() {
string targetName, name, phone;
int roomNo;
bool found = false;
ifstream inFile("customers.txt");
ofstream tempFile("temp.txt");
inFile.close();
tempFile.close();
remove("customers.txt");
rename("temp.txt", "customers.txt");
if (!found) {
cout << "Customer not found.\n";
}
}
int main() {
Hotel h;
h.mainMenu();
return 0;
}