0% found this document useful (0 votes)
3 views

project code

The document is a C++ program for a Hotel Management System that allows users to book rooms, view customers, search for customers, and check out. It utilizes file handling to store customer information in a text file. The program features a main menu for user interaction and performs operations based on user input.

Uploaded by

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

project code

The document is a C++ program for a Hotel Management System that allows users to book rooms, view customers, search for customers, and check out. It utilizes file handling to store customer information in a text file. The program features a main menu for user interaction and performs operations based on user input.

Uploaded by

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

#include <iostream>

#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;

cout << "\nEnter Customer Name: ";


cin >> name;
cout << "Enter Room No: ";
cin >> roomNo;
cout << "Enter Phone Number: ";
cin >> phone;
ofstream outFile("customers.txt", ios::app);
outFile << name << " " << roomNo << " " << phone << "\n";
outFile.close();

cout << "Room booked successfully!\n";


}

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;

cout << "\nEnter customer name to search: ";


cin >> targetName;

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;

cout << "\nEnter customer name to check-out: ";


cin >> targetName;

ifstream inFile("customers.txt");
ofstream tempFile("temp.txt");

while (inFile >> name >> roomNo >> phone) {


if (name == targetName) {
found = true;
cout << "Customer " << name << " has been checked out.\n";
} else {
tempFile << name << " " << roomNo << " " << phone << "\n";
}
}

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;
}

You might also like