Hotel Management Code With Output
Hotel Management Code With Output
CS PROJECT ON
“HOTEL MANAGEMENT”
Guided by–
MRS. RENU DHIMAN
CONTENT
1. Certificate
2. Acknowledgement
3. Requirements
4. Program
5. Output
6. Bibliography
CERTIFICATE
______________
_______________
DATE:
ACKNOWLEDGEMENT
OPERATING SYSTEM:-
WINDOWS 8.1
SOFTWARE REQUIREMENTS:-
PYTHON 3.7 AND USE PYCHARM OR VISUAL
STUDIO CODE FOR BEST INTERFACE
#main.py
from rooms importroom_menu
from customers importcustomer_menu
frommyprintimport print_center, input_center
if __name__ == '__main__':
whileTrue:
print()
print_center("==============================")
print_center("=====THE TITAN HOTELS=====")
print_center("==============================")
print_center("1. Manage Rooms")
print_center("2. Manage Customers")
print_center("0. Exit")
print()
class DataFile:
def __init__(self, name):
self.name = name
defadd_record(self, record):
file = open(self.name, "ab")
pickle.dump(record, file)
file.close()
defget_records(self):
records = []
try:
file = open(self.name, "rb")
except FileNotFoundError:
return records
while True:
try:
record = pickle.load(file)
records.append(record)
except EOFError:
break
file.close()
return records
def overwrite(self, records):
file = open(self.name, "wb")
for record in records:
pickle.dump(record, file)
file.close()
#customer.py
class Customer:
def __init__(self, customer_id, name, address, phone, room_no, entry_date,
checkout_date):
self.customer_id = customer_id
self.name = name
self.address = address
self.phone = phone
self.room_no = room_no
self.entry_date = entry_date
self.checkout_date = checkout_date
defprint_all(self):
print(str(self.customer_id).ljust(3),
self.name[0:15].ljust(15),
self.address[0:15].ljust(15),
self.phone.ljust(15),
str(self.room_no).ljust(10),
self.entry_date.strftime("%d-%b-%y").ljust(15),
(self.checkout_date.strftime("%d %b %y") if self.checkout_date is not
None else "None").ljust(15))
defprint_full(self):
print_bar()
print("Customer #", self.customer_id)
print("Name: ", self.name)
print("Address: ", self.address)
print("Phone: ", self.phone)
print("Checked in to room #", self.room_no, " on ",
self.entry_date.strftime("%d %b %y"))
print("Checkout: ", self.checkout_date.strftime("%d %b %y") if
self.checkout_date is not None else None)
print_bar()
defcreate_customer(customer_id, room_no):
name = input("Enter the name: ")
address = input("Enter the address: ")
phone = input("Enter the phone: ")
entry_date = datetime.now()
return Customer(customer_id, name, address, phone, room_no, entry_date, None)
defprint_header():
print("="*100)
print("id".ljust(3),
"name".ljust(15),
"address".ljust(15),
"phone".ljust(15),
"room no".ljust(10),
"entry".ljust(15),
"check out".ljust(15))
print("="*100)
#customers.py
NUMBER_OF_RECORDS_PER_PAGE = 10
customerTable = DataFile("customers.dat")
defadd_customer():
rooms, found, position = get_and_print_room_by_no()
if found:
room_no = rooms[position].room_no
customers = customerTable.get_records()
if len(customers) == 0:
customer_id = 0
else:
customer_id = customers[len(customers)-1].customer_id + 1
customer = create_customer(customer_id, room_no)
confirm = input("Complete the operation? (Y/N) ")
if confirm.lower() == 'y':
customerTable.add_record(customer)
change_room_status(room_no, False)
print("Operation Successful")
else:
print("Operation Canceled")
defget_and_print_customer_list_by_name():
customers = customerTable.get_records()
results = []
if len(customers) == 0:
print("No Records found")
else:
name = input("Enter the name: ").lower()
words = name.split()
defget_and_print_employee_by_id():
customers = customerTable.get_records()
found = False
position = -1
if len(customers) == 0:
print("No Records found")
else:
customer_id = int(input("Enter the id: "))
for customer in customers:
position += 1
if customer_id == customer.customer_id:
found = True
break
if not found:
print("No matching record")
else:
customers[position].print_full()
return customers, found, position
defget_and_print_customer_list_by_address():
customers = customerTable.get_records()
results = []
if len(customers) == 0:
print("No Records found")
else:
address = input("Enter the address: ").lower()
words = address.split()
defget_and_print_customer_by_room_no():
customers = customerTable.get_records()
found = False
position = -1
if len(customers) == 0:
print("No Records found")
else:
room_no = int(input("Enter the room no: "))
for customer in customers:
position += 1
if room_no == customer.room_no and customer.checkout_date is None:
found = True
break
if not found:
print("No matching record")
else:
customers[position].print_full()
return customers, found, position
defprint_customer_list_by_check_in():
customers = customerTable.get_records()
if len(customers) == 0:
print("No customers found")
else:
print("Enter the date: ")
day = int(input("day of month: "))
month = int(input("month: "))
year = int(input("year: "))
check_in = datetime(year, month, day)
results = []
for customer in customers:
if customer.entry_date.date() == check_in.date():
results.append(customer)
if len(results) == 0:
print("no matching records")
else:
print(len(results), " matching customers")
print_header()
for customer in results:
customer.print_all()
defprint_current_list_of_customers():
customers = customerTable.get_records()
if len(customers) == 0:
print("No customers found")
else:
results = []
for customer in customers:
if customer.checkout_date is None:
results.append(customer)
if len(results) == 0:
print("no matching records")
else:
print(len(results), " matching customers")
print_header()
for customer in results:
customer.print_all()
defcheck_out():
customers, found, position = get_and_print_customer_by_room_no()
if found:
customer = customers[position]
customer.checkout_date = datetime.now()
confirm = input("Confirm checkout? (Y/N): ")
if confirm == 'y':
customerTable.overwrite(customers)
change_room_status(customer.room_no, True)
print("Operation Successful")
else:
print("Operation Cancelled")
defedit_customer_details():
customers, found, position = get_and_print_customer_by_room_no()
if found:
customer = customers[position]
print("Input new values (leave blank to keep previous value)")
name = input("Enter new name: ")
if len(name) > 0:
customer.name = name
address = input("Enter new address: ")
if len(address) > 0:
customer.address = address
phone = input("Enter new phone: ")
if len(phone) > 0:
customer.phone = phone
confirm = input("Confirm Edit? (Y/N): ")
if confirm == 'y':
customerTable.overwrite(customers)
print("Operation Successful")
else:
print("Operation Cancelled")
defdelete_customer():
customers, found, position = get_and_print_customer_by_room_no()
if found:
print("Confirm delete?? (Y/N): ")
confirm = input()
if confirm == 'y':
customers.pop(position)
customerTable.overwrite(customers)
print("Operation Successful")
else:
print("Operation Cancelled")
defview_all_customers():
customers = customerTable.get_records()
if len(customers) == 0:
print("No Record found")
else:
i = 0
print_header()
for customer in customers:
i += 1
customer.print_all()
if i == NUMBER_OF_RECORDS_PER_PAGE:
input("Press any key to continue.")
defcustomer_menu():
while True:
print()
print("==============================")
print("==========Customer Menu=========")
print("==============================")
print()
print("1. New Customer")
print("2. Show Customer Details by name")
print("3. Show customer details by id")
print("4. Show customer details by address")
print("5. Show customer details by phone number")
print("6. Show customer details by room no")
print("7. Show customer details by check in date")
print("8. Show current list of customers")
print("9. Check out")
print("10. Edit customer Details")
print("11. Delete Customer record")
print("12. View all customers")
print("0. Go Back")
choice = int(input("Enter your choice: "))
if choice == 1:
add_customer()
elif choice == 2:
get_and_print_customer_list_by_name()
elif choice == 3:
get_and_print_employee_by_id()
elif choice == 4:
get_and_print_customer_list_by_address()
elif choice == 5:
get_and_print_customer_list_by_phone()
elif choice == 6:
get_and_print_customer_by_room_no()
elif choice == 7:
print_customer_list_by_check_in()
elif choice == 8:
print_current_list_of_customers()
elif choice == 9:
check_out()
elif choice == 10:
edit_customer_details()
elif choice == 11:
delete_customer()
elif choice == 12:
view_all_customers()
elif choice == 0:
break
else:
print("Invalid choice (Press 0 to go back)"
#room.py
from myprint import print_bar
class Room:
def __init__(self, room_id, room_no, floor, beds, available):
self.room_id = room_id
self.room_no = room_no
self.floor = floor
self.beds = beds
self.available = available
defprint_all(self):
print(str(self.room_id).ljust(3),
str(self.room_no).ljust(15),
self.floor.ljust(15),
str(self.beds).ljust(15),
str(self.available).ljust(15))
defprint_full(self):
print_bar()
print("Record #", self.room_id)
print("Room No: ", self.room_no)
print("Floor: ", self.floor)
print("Beds: ", self.beds)
print("available: ", self.available)
print_bar()
defcreate_room(room_id):
room_no = int(input("Enter the room no: "))
floor = input("Enter the floor (Ex. ground, first etc.): ")
beds = int(input("Enter number of beds: "))
available = True
return Room(room_id, room_no, floor, beds, available)
defprint_header():
print("="*100)
print("id".ljust(3),
"room no".ljust(15),
"floor".ljust(15),
"beds".ljust(15),
"available".ljust(15)
)
print("="*100)
#rooms.py
NUMBER_OF_RECORDS_PER_PAGE = 10
roomTable = DataFile("rooms.dat")
defadd_room():
rooms = roomTable.get_records()
if len(rooms) == 0:
room_id = 0
else:
room_id = rooms[len(rooms) - 1].room_id + 1
room = create_room(room_id)
roomTable.add_record(room)
print("Operation Successful")
defget_and_print_room_by_no():
rooms = roomTable.get_records()
found = False
position = -1
if len(rooms) == 0:
print("No Record found")
else:
room_no = int(input("Enter the room no: "))
for room in rooms:
position += 1
if room_no == room.room_no:
found = True
break
if not found:
print("No matching record")
else:
rooms[position].print_full()
return rooms, found, position
defget_and_print_room_by_beds():
rooms = roomTable.get_records()
results = []
if len(rooms) == 0:
print("No Records found")
else:
beds = int(input("Enter the number of required beds: "))
for room in rooms:
if beds == room.beds:
results.append(room)
if len(results) == 0:
print("No matching record")
else:
print(len(results), " matching records")
print_header()
for room in results:
room.print_all()
return results
defedit_room_details():
rooms, found, position = get_and_print_room_by_no()
if found:
room = rooms[position]
print("Input new values (leave blank to keep previous value)")
room_no = input("Enter new room no: ")
if len(room_no) > 0:
room.room_no = int(room_no)
floor = input("Enter new floor: ")
if len(floor) > 0:
room.floor = floor
beds = input("Enter number of beds: ")
if len(beds) > 0:
room.beds = int(beds)
roomTable.overwrite(rooms)
print("Operation Successful")
defdelete_room():
rooms, found, position = get_and_print_room_by_no()
if found:
room = rooms[position]
print("Delete this room ? (Y/N) : ")
confirm = input()
if confirm.lower() == 'y':
rooms.remove(room)
roomTable.overwrite(rooms)
print("Operation Successful")
else:
print("Operation Canceled")
defchange_room_status(room_no, available):
rooms = roomTable.get_records()
found = False
position = -1
if len(rooms) == 0:
print("No Record found")
else:
for room in rooms:
position += 1
if room_no == room.room_no:
found = True
break
if not found:
print("No matching record")
else:
room = rooms[position]
room.available = available
roomTable.overwrite(rooms)
print("Operation Successful")
defview_all_rooms():
rooms = roomTable.get_records()
if len(rooms) == 0:
print("No Record found")
else:
i = 0
print_header()
for room in rooms:
i += 1
room.print_all()
if i == NUMBER_OF_RECORDS_PER_PAGE:
input("Press any key to continue.")
defroom_menu():
while True:
print()
print("============================")
print("==========Room Menu=========")
print("============================")
print()
print("1. Add new room")
print("2. Get room details by room no")
print("3. Find available rooms by number of beds")
print("4. Edit Room details")
print("5. Delete room")
print("6. View all rooms")
print("0. Go Back")
choice = int(input("Enter your choice: "))
if choice == 1:
add_room()
elif choice == 2:
get_and_print_room_by_no()
elif choice == 3:
get_and_print_room_by_beds()
elif choice == 4:
edit_room_details()
elif choice == 5:
delete_room()
elif choice == 6:
view_all_rooms()
elif choice == 0:
break
else:
print("Invalid choice (Press 0 to go back)")
#myprint.py
SCREEN_WIDTH = 100
defprint_center(s):
x_pos = SCREEN_WIDTH // 2
print((" " * x_pos), s)
defprint_bar():
print("=" * 100)
defprint_bar_ln():
print_bar()
print()
definput_center(s):
x_pos = SCREEN_WIDTH // 2
print((" " * x_pos), s, end='')
return input()
OUTPUT
BIBLIOGRAPHY