The Wayback Machine - https://web.archive.org/web/20241009013350/https://www.geeksforgeeks.org/hotel-management-system/
Open In App

Hotel Management System

Last Updated : 05 Mar, 2024
Summarize
Comments
Improve
Suggest changes
Like Article
Like
Save
Share
Report
News Follow

Given the data for Hotel management and User:
Hotel Data: 

Hotel Name     Room Available     Location     Rating      Price per Room
H1 4 Bangalore 5 100
H2 5 Bangalore 5 200
H3 6 Mumbai 3 100

User Data: 

User Name         UserID             Booking Cost
U1 2 1000
U2 3 1200
U3 4 1100

The task is to answer the following question.

  1. Print the hotel data.
  2. Sort hotels by Name.
  3. Sort Hotel by highest rating.
  4. Print Hotel data for Bangalore Location.
  5. Sort hotels by maximum number of rooms Available.
  6. Print user Booking data.

Machine coding round involves solving a design problem in a matter of a couple of hours. 
It requires designing and coding a clean, modular and extensible solution based on a specific set of requirements. 
 

Approach:  

  • Create classes for Hotel data and User data.
  • Initialize variables that stores Hotel data and User data.
  • Create Objects for Hotel and user classes that access the Hotel data and User data.
  • initialize two vector array that holds the hotel data and user data.
  • solve the Above questions one by one.

Below is the implementation of the above approach. 

C++




// C++ program to solve
// the given question
 
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
 
using namespace std;
 
// Create class for hotel data.
class Hotel {
public:
    string name;
    int roomAvl;
    string location;
    int rating;
    int pricePr;
};
 
// Create class for user data.
class User : public Hotel {
public:
    string uname;
    int uId;
    int cost;
};
 
// Function to Sort Hotels by
// Bangalore location
bool sortByBan(Hotel& A, Hotel& B)
{
    return A.name > B.name;
}
 
// Function to sort hotels
// by rating.
bool sortByr(Hotel& A, Hotel& B)
{
    return A.rating > B.rating;
}
 
// Function to sort hotels
// by rooms availability.
bool sortByRoomAvailable(Hotel& A,
                        Hotel& B)
{
    return A.roomAvl < B.roomAvl;
}
 
// Print hotels data.
void PrintHotelData(vector<Hotel> hotels)
{
    cout << "PRINT HOTELS DATA:" << endl;
    cout << "HotelName"
         << "   "
         << "Room Available"
         << "    "
         << "Location"
         << "    "
         << "Rating"
         << "    "
         << "PricePer Room:" << endl;
 
    for (int i = 0; i < 3; i++) {
        cout << hotels[i].name
             << "          "
             << hotels[i].roomAvl
             << "              "
             << hotels[i].location
             << "       "
             << hotels[i].rating
             << "            "
             << hotels[i].pricePr
             << endl;
    }
    cout << endl;
}
 
// Sort Hotels data by name.
void SortHotelByName(vector<Hotel> hotels)
{
    cout << "SORT BY NAME:" << endl;
 
    std::sort(hotels.begin(), hotels.end(),
              sortByBan);
 
    for (int i = 0; i < hotels.size(); i++) {
        cout << hotels[i].name << " "
             << hotels[i].roomAvl << " "
             << hotels[i].location << " "
             << hotels[i].rating << " "
             << " " << hotels[i].pricePr
             << endl;
    }
    cout << endl;
}
 
// Sort Hotels by rating
void SortHotelByRating(vector<Hotel> hotels)
{
    cout << "SORT BY A RATING:" << endl;
 
    std::sort(hotels.begin(),
              hotels.end(), sortByr);
 
    for (int i = 0; i < hotels.size(); i++) {
        cout << hotels[i].name << " "
             << hotels[i].roomAvl << " "
             << hotels[i].location << " "
             << hotels[i].rating << " "
             << " " << hotels[i].pricePr
             << endl;
    }
    cout << endl;
}
 
// Print Hotels for any city Location.
void PrintHotelBycity(string s,
                      vector<Hotel> hotels)
{
    cout << "HOTELS FOR " << s
         << " LOCATION IS:"
         << endl;
    for (int i = 0; i < hotels.size(); i++) {
 
        if (hotels[i].location == s) {
 
            cout << hotels[i].name << " "
                 << hotels[i].roomAvl << " "
                 << hotels[i].location << " "
                 << hotels[i].rating << " "
                 << " " << hotels[i].pricePr
                 << endl;
        }
    }
    cout << endl;
}
 
// Sort hotels by room Available.
void SortByRoomAvailable(vector<Hotel> hotels)
{
    cout << "SORT BY ROOM AVAILABLE:" << endl;
 
    std::sort(hotels.begin(), hotels.end(),
              sortByRoomAvailable);
 
    for (int i = hotels.size() - 1; i >= 0; i--) {
 
        cout << hotels[i].name << " "
             << hotels[i].roomAvl << " "
             << hotels[i].location << " "
             << hotels[i].rating << " "
             << " " << hotels[i].pricePr
             << endl;
    }
    cout << endl;
}
 
// Print the user's data
void PrintUserData(string userName[],
                   int userId[],
                   int bookingCost[],
                   vector<Hotel> hotels)
{
 
    vector<User> user;
    User u;
 
    // Access user data.
    for (int i = 0; i < 3; i++) {
        u.uname = userName[i];
        u.uId = userId[i];
        u.cost = bookingCost[i];
        user.push_back(u);
    }
 
    // Print User data.
    cout << "PRINT USER BOOKING DATA:"
         << endl;
    cout << "UserName"
         << " "
         << "UserID"
         << " "
         << "HotelName"
         << " "
         << "BookingCost" << endl;
 
    for (int i = 0; i < user.size(); i++) {
        cout << user[i].uname
             << "         "
             << user[i].uId
             << "        "
             << hotels[i].name
             << "         "
             << user[i].cost
             << endl;
    }
}
 
// Functiont to solve
// Hotel Management problem
void HotelManagement(string userName[],
                     int userId[],
                     string hotelName[],
                     int bookingCost[],
                     int rooms[],
                     string locations[],
                     int ratings[],
                     int prices[])
{
    // Initialize arrays that stores
    // hotel data and user data
    vector<Hotel> hotels;
 
    // Create Objects for
    // hotel and user.
    Hotel h;
 
    // Initialise the data
    for (int i = 0; i < 3; i++) {
        h.name = hotelName[i];
        h.roomAvl = rooms[i];
        h.location = locations[i];
        h.rating = ratings[i];
        h.pricePr = prices[i];
        hotels.push_back(h);
    }
    cout << endl;
 
    // Call the various operations
    PrintHotelData(hotels);
    SortHotelByName(hotels);
    SortHotelByRating(hotels);
    PrintHotelBycity("Bangalore",
                     hotels);
    SortByRoomAvailable(hotels);
    PrintUserData(userName,
                  userId,
                  bookingCost,
                  hotels);
}
 
// Driver Code.
int main()
{
 
    // Initialize variables to stores
    // hotels data and user data.
    string userName[] = { "U1", "U2", "U3" };
    int userId[] = { 2, 3, 4 };
    string hotelName[] = { "H1", "H2", "H3" };
    int bookingCost[] = { 1000, 1200, 1100 };
    int rooms[] = { 4, 5, 6 };
    string locations[] = { "Bangalore",
                           "Bangalore",
                           "Mumbai" };
    int ratings[] = { 5, 5, 3 };
    int prices[] = { 100, 200, 100 };
 
    // Function to perform operations
    HotelManagement(userName, userId,
                    hotelName, bookingCost,
                    rooms, locations,
                    ratings, prices);
 
    return 0;
}


Java




import java.util.*;
 
// Create class for hotel data.
class Hotel implements Comparable<Hotel> {
    static String sortParam = "name";
    String name;
    int roomAvl;
    String location;
    int rating;
    int pricePr;
 
    // Constructor
    public Hotel(String name, int roomAvl, String location, int rating, int pricePr) {
        this.name = name;
        this.roomAvl = roomAvl;
        this.location = location;
        this.rating = rating;
        this.pricePr = pricePr;
    }
 
    // Function to change sort parameter to name
    public static void sortByName() {
        sortParam = "name";
    }
 
    // Function to change sort parameter to rating.
    public static void sortByRate() {
        sortParam = "rating";
    }
 
    // Function to change sort parameter to room availability.
    public static void sortByRoomAvailable() {
        sortParam = "roomAvl";
    }
 
    @Override
    public int compareTo(Hotel other) {
        switch(sortParam) {
            case "name":
                return this.name.compareTo(other.name);
            case "rating":
                return Integer.compare(this.rating, other.rating);
            case "roomAvl":
                return Integer.compare(this.roomAvl, other.roomAvl);
            default:
                return 0;
        }
    }
 
    @Override
    public String toString() {
        return "PRHOTELS DATA:\nHotelName:" + this.name + "\tRoom Available:" + this.roomAvl + "\tLocation:" + this.location + "\tRating:" + this.rating + "\tPricePer Room:" + this.pricePr;
    }
}
 
// Create class for user data.
class User {
    String uname;
    int uId;
    int cost;
 
    // Constructor
    public User(String uname, int uId, int cost) {
        this.uname = uname;
        this.uId = uId;
        this.cost = cost;
    }
 
    @Override
    public String toString() {
        return "UserName:" + this.uname + "\tUserId:" + this.uId + "\tBooking Cost:" + this.cost;
    }
}
 
public class Main {
    // Print hotels data.
    public static void printHotelData(ArrayList<Hotel> hotels) {
        for (Hotel h : hotels) {
            System.out.println(h);
        }
    }
 
    // Sort Hotels data by name.
    public static void sortHotelByName(ArrayList<Hotel> hotels) {
        System.out.println("SORT BY NAME:");
        Hotel.sortByName();
        Collections.sort(hotels);
        printHotelData(hotels);
        System.out.println();
    }
 
    // Sort Hotels by rating
    public static void sortHotelByRating(ArrayList<Hotel> hotels) {
        System.out.println("SORT BY A RATING:");
        Hotel.sortByRate();
        Collections.sort(hotels);
        printHotelData(hotels);
        System.out.println();
    }
 
    // Print Hotels for any city Location.
    public static void printHotelByCity(String s, ArrayList<Hotel> hotels) {
        System.out.println("HOTELS FOR " + s + " LOCATION ARE:");
        ArrayList<Hotel> hotelsByLoc = new ArrayList<>();
        for (Hotel h : hotels) {
            if (h.location.equals(s)) {
                hotelsByLoc.add(h);
            }
        }
        printHotelData(hotelsByLoc);
        System.out.println();
    }
 
    // Sort hotels by room Available.
    public static void sortByRoomAvailable(ArrayList<Hotel> hotels) {
        System.out.println("SORT BY ROOM AVAILABLE:");
        Hotel.sortByRoomAvailable();
        Collections.sort(hotels);
        printHotelData(hotels);
        System.out.println();
    }
 
    // Print the user's data
    public static void printUserData(String[] userName, int[] userId, int[] bookingCost, ArrayList<Hotel> hotels) {
        ArrayList<User> users = new ArrayList<>();
        // Access user data.
        for (int i = 0; i < 3; i++) {
            User u = new User(userName[i], userId[i], bookingCost[i]);
            users.add(u);
        }
 
        for (int i = 0; i < users.size(); i++) {
            System.out.println(users.get(i) + "\tHotel name:" + hotels.get(i).name);
        }
    }
 
    // Function to solve Hotel Management problem
    public static void hotelManagement(String[] userName, int[] userId, String[] hotelName, int[] bookingCost, int[] rooms, String[] locations, int[] ratings, int[] prices) {
        // Initialize array that stores hotel data
        ArrayList<Hotel> hotels = new ArrayList<>();
 
        // Initialise the data
        for (int i = 0; i < 3; i++) {
            Hotel h = new Hotel(hotelName[i], rooms[i], locations[i], ratings[i], prices[i]);
            hotels.add(h);
        }
 
        System.out.println();
 
        // Call the various operations
        printHotelData(hotels);
        sortHotelByName(hotels);
        sortHotelByRating(hotels);
        printHotelByCity("Bangalore", hotels);
        sortByRoomAvailable(hotels);
        printUserData(userName, userId, bookingCost, hotels);
    }
 
    // Driver Code.
    public static void main(String[] args) {
        // Initialize variables to stores hotels data and user data.
        String[] userName = {"U1", "U2", "U3"};
        int[] userId = {2, 3, 4};
        String[] hotelName = {"H1", "H2", "H3"};
        int[] bookingCost = {1000, 1200, 1100};
        int[] rooms = {4, 5, 6};
        String[] locations = {"Bangalore", "Bangalore", "Mumbai"};
        int[] ratings = {5, 5, 3};
        int[] prices = {100, 200, 100};
 
        // Function to perform operations
        hotelManagement(userName, userId, hotelName, bookingCost, rooms, locations, ratings, prices);
    }
}


C#




using System;
using System.Collections.Generic;
using System.Linq;
 
// Create class for hotel data.
public class Hotel
{
    public string Name { get; set; }
    public int RoomAvl { get; set; }
    public string Location { get; set; }
    public int Rating { get; set; }
    public int PricePr { get; set; }
}
 
// Create class for user data.
public class User : Hotel
{
    public string Uname { get; set; }
    public int UId { get; set; }
    public int Cost { get; set; }
}
 
public class Program
{
    // Function to Sort Hotels by Bangalore location
    static int SortByBan(Hotel A, Hotel B)
    {
        return A.Name.CompareTo(B.Name);
    }
 
    // Function to sort hotels by rating.
    static int SortByr(Hotel A, Hotel B)
    {
        return B.Rating.CompareTo(A.Rating);
    }
 
    // Function to sort hotels by rooms availability.
    static int SortByRoomAvailable(Hotel A, Hotel B)
    {
        return A.RoomAvl.CompareTo(B.RoomAvl);
    }
 
    // Print hotels data.
    static void PrintHotelData(List<Hotel> hotels)
    {
        Console.WriteLine("PRINT HOTELS DATA:");
        Console.WriteLine("HotelName   Room Available    Location    Rating    PricePer Room:");
 
        for (int i = 0; i < 3; i++)
        {
            Console.WriteLine($"{hotels[i].Name}          {hotels[i].RoomAvl}              {hotels[i].Location}       {hotels[i].Rating}            {hotels[i].PricePr}");
        }
        Console.WriteLine();
    }
 
    // Sort Hotels data by name.
    static void SortHotelByName(List<Hotel> hotels)
    {
        Console.WriteLine("SORT BY NAME:");
 
        hotels.Sort(SortByBan);
 
        foreach (var hotel in hotels)
        {
            Console.WriteLine($"{hotel.Name} {hotel.RoomAvl} {hotel.Location} {hotel.Rating} {hotel.PricePr}");
        }
        Console.WriteLine();
    }
 
    // Sort Hotels by rating
    static void SortHotelByRating(List<Hotel> hotels)
    {
        Console.WriteLine("SORT BY A RATING:");
 
        hotels.Sort(SortByr);
 
        foreach (var hotel in hotels)
        {
            Console.WriteLine($"{hotel.Name} {hotel.RoomAvl} {hotel.Location} {hotel.Rating} {hotel.PricePr}");
        }
        Console.WriteLine();
    }
 
    // Print Hotels for any city Location.
    static void PrintHotelBycity(string s, List<Hotel> hotels)
    {
        Console.WriteLine($"HOTELS FOR {s} LOCATION IS:");
 
        foreach (var hotel in hotels)
        {
            if (hotel.Location == s)
            {
                Console.WriteLine($"{hotel.Name} {hotel.RoomAvl} {hotel.Location} {hotel.Rating} {hotel.PricePr}");
            }
        }
        Console.WriteLine();
    }
 
    // Sort hotels by room Available.
    static void SortByRoomAvailable(List<Hotel> hotels)
    {
        Console.WriteLine("SORT BY ROOM AVAILABLE:");
 
        hotels.Sort(SortByRoomAvailable);
 
        for (int i = hotels.Count - 1; i >= 0; i--)
        {
            Console.WriteLine($"{hotels[i].Name} {hotels[i].RoomAvl} {hotels[i].Location} {hotels[i].Rating} {hotels[i].PricePr}");
        }
        Console.WriteLine();
    }
 
    // Print the user's data
    static void PrintUserData(string[] userName, int[] userId, int[] bookingCost, List<Hotel> hotels)
    {
        List<User> user = new List<User>();
 
        // Access user data.
        for (int i = 0; i < 3; i++)
        {
            User u = new User
            {
                Uname = userName[i],
                UId = userId[i],
                Cost = bookingCost[i]
            };
            user.Add(u);
        }
 
        // Print User data.
        Console.WriteLine("PRINT USER BOOKING DATA:");
        Console.WriteLine("UserName   UserID   HotelName   BookingCost");
 
        for (int i = 0; i < user.Count; i++)
        {
            Console.WriteLine($"{user[i].Uname}         {user[i].UId}        {hotels[i].Name}         {user[i].Cost}");
        }
    }
 
    // Function to solve Hotel Management problem
    static void HotelManagement(string[] userName, int[] userId, string[] hotelName, int[] bookingCost, int[] rooms, string[] locations, int[] ratings, int[] prices)
    {
        // Initialize arrays that stores hotel data and user data
        List<Hotel> hotels = new List<Hotel>();
 
        // Initialise the data
        for (int i = 0; i < 3; i++)
        {
            Hotel h = new Hotel
            {
                Name = hotelName[i],
                RoomAvl = rooms[i],
                Location = locations[i],
                Rating = ratings[i],
                PricePr = prices[i]
            };
            hotels.Add(h);
        }
        Console.WriteLine();
 
        // Call the various operations
        PrintHotelData(hotels);
        SortHotelByName(hotels);
        SortHotelByRating(hotels);
        PrintHotelBycity("Bangalore", hotels);
        SortByRoomAvailable(hotels);
        PrintUserData(userName, userId, bookingCost, hotels);
    }
 
    // Driver Code.
    public static void Main()
    {
        // Initialize variables to stores hotels data and user data.
        string[] userName = { "U1", "U2", "U3" };
        int[] userId = { 2, 3, 4 };
        string[] hotelName = { "H1", "H2", "H3" };
        int[] bookingCost = { 1000, 1200, 1100 };
        int[] rooms = { 4, 5, 6 };
        string[] locations = { "Bangalore", "Bangalore", "Mumbai" };
        int[] ratings = { 5, 5, 3 };
        int[] prices = { 100, 200, 100 };
 
        // Function to perform operations
        HotelManagement(userName, userId, hotelName, bookingCost, rooms, locations, ratings, prices);
    }
}


Javascript




// javascript program to solve
// the given question
 
// Create class for hotel data.
class Hotel {
     
    constructor(){
        this.name = "";
        this.roomAvl = 0;
        this.location = "";
        this.rating = 0;
        this.pricePr = 0;
    }
}
 
// Create class for user data.
class User{
 
    constructor(){
        this.uname = "";
        this.uId = 0;
        this.cost = 0;
    }
}
 
// Function to Sort Hotels by
// Bangalore location
function sortByBan(A, B)
{
    return B.name.localeCompare(A.name);
}
 
// Function to sort hotels
// by rating.
function sortByr(A, B)
{
    return A.rating > B.rating;
}
 
// Function to sort hotels
// by rooms availability.
function sortByRoomAvailable(A, B)
{
    return A.roomAvl < B.roomAvl;
}
 
// Print hotels data.
function PrintHotelData(hotels)
{
    console.log("PRINT HOTELS DATA:");
    console.log("HotelName"
         + "   "
         + "Room Available"
         + "    "
         + "Location"
         + "    "
         + "Rating"
         + "    "
         + "PricePer Room:");
 
    for (let i = 0; i < 3; i++) {
        console.log(hotels[i].name
             + "          "
             + hotels[i].roomAvl
             + "              "
             + hotels[i].location
             + "       "
             + hotels[i].rating
             + "            "
             + hotels[i].pricePr);
    }
    console.log();
}
 
// Sort Hotels data by name.
function SortHotelByName(hotels)
{
    console.log("SORT BY NAME:");
 
    hotels.sort(sortByBan);
    // console.log("h9");
    // console.log(hotels);
    for (let i = 0; i < hotels.length; i++) {
        console.log(hotels[i].name + " " + hotels[i].roomAvl + " "
             + hotels[i].location + " "
             + hotels[i].rating + " "
             + " " + hotels[i].pricePr);
    }
    console.log();
}
 
// Sort Hotels by rating
function SortHotelByRating(hotels)
{
    console.log("SORT BY A RATING:");
 
    hotels.sort(sortByr);
 
    for (let i = 0; i < hotels.length; i++) {
        console.log(hotels[i].name + " "
             + hotels[i].roomAvl + " "
             + hotels[i].location + " "
             + hotels[i].rating + " "
             + " " + hotels[i].pricePr);
    }
    console.log();
}
 
// Print Hotels for any city Location.
function PrintHotelBycity(s, hotels)
{
    console.log("HOTELS FOR " + s + " LOCATION IS:");
 
    for (let i = 0; i < hotels.length; i++) {
 
        if (hotels[i].location == s) {
 
            console.log(hotels[i].name + " "
                 + hotels[i].roomAvl + " "
                 + hotels[i].location + " "
                 + hotels[i].rating + " "
                 + " " + hotels[i].pricePr);
        }
    }
    console.log();
}
 
// Sort hotels by room Available.
function SortByRoomAvailable(hotels)
{
    console.log("SORT BY ROOM AVAILABLE:");
 
    hotels.sort(sortByRoomAvailable);
    for (let i = hotels.length - 1; i >= 0; i--) {
 
        console.log(hotels[i].name + " " + hotels[i].roomAvl + " " + hotels[i].location + " " + hotels[i].rating + " " +hotels[i].pricePr);
    }
    console.log();
}
 
// Print the user's data
function PrintUserData(userName,
                   userId,
                   bookingCost, hotels)
{
 
    let user = [];
     
 
    // Access user data.
    for (let i = 0; i < 3; i++) {
        let u = new User();
        u.uname = userName[i];
        u.uId = userId[i];
        u.cost = bookingCost[i];
        user.push(u);
    }
 
    // Print User data.
    console.log("PRINT USER BOOKING DATA:")
    console.log("UserName UserID HotelName BookingCost")
 
    for (let i = 0; i < user.length; i++) {
        console.log(user[i].uname + "         " + user[i].uId + "        " + hotels[i].name + "         " + user[i].cost);
    }
}
 
// Functiont to solve
// Hotel Management problem
function HotelManagement(userName,userId, hotelName,
bookingCost, rooms, locations, ratings, prices)
{
    // Initialize arrays that stores
    // hotel data and user data
    let hotels = [];
 
    // Create Objects for
    // hotel and user.
     
 
    // Initialise the data
    for (let i = 0; i < 3; i++) {
        let h = new Hotel();
        h.name = hotelName[i];
        h.roomAvl = rooms[i];
        h.location = locations[i];
        h.rating = ratings[i];
        h.pricePr = prices[i];
        hotels.push(h);
    }
    console.log();
     
    // Call the various operations
    PrintHotelData(hotels);
    SortHotelByName(hotels);
    SortHotelByRating(hotels);
    PrintHotelBycity("Bangalore", hotels);
    SortByRoomAvailable(hotels);
    PrintUserData(userName, userId, bookingCost, hotels);
}
 
// Driver Code.
// Initialize variables to stores
// hotels data and user data.
let userName = ["U1", "U2", "U3"];
let userId = [2, 3, 4];
let hotelName = ["H1", "H2", "H3" ];
let bookingCost = [1000, 1200, 1100 ];
let rooms = [4, 5, 6 ];
let locations = ["Bangalore", "Bangalore", "Mumbai" ];
let ratings = [5, 5, 3 ];
let prices = [100, 200, 100 ];
 
// Function to perform operations
HotelManagement(userName, userId, hotelName, bookingCost,
rooms, locations, ratings, prices);
 
// the code is contributed by Nidhi goel.


Python3




# Python program to solve
# the given question
 
# Create class for hotel data.
class Hotel :
    sortParam='name'
    def __init__(self) -> None:
        self.name=''
        self.roomAvl=0
        self.location=''
        self.rating=int
        self.pricePr=0
     
    def __lt__(self,other):
        getattr(self,Hotel.sortParam)<getattr(other,Hotel.sortParam)
     
    # Function to change sort parameter to
    # name
    @classmethod
    def sortByName(cls):
        cls.sortParam='name'
 
    # Function to change sort parameter to
    # rating.
    @classmethod
    def sortByRate(cls):
        cls.sortParam='rating'
 
    # Function to change sort parameter to
    # room availability.
    @classmethod
    def sortByRoomAvailable(cls)    :
        cls.sortParam='roomAvl'
     
    def __repr__(self) -> str:
        return "PRHOTELS DATA:\nHotelName:{}\tRoom Available:{}\tLocation:{}\tRating:{}\tPricePer Room:{}".format(self.name,self.roomAvl,self.location,self.rating,self.pricePr)
 
 
# Create class for user data.
class User:
    def __init__(self) -> None:
        self.uname=''
        self.uId=0
        self.cost=0
 
    def __repr__(self) -> str:
        return "UserName:{}\tUserId:{}\tBooking Cost:{}".format(self.uname,self.uId,self.cost)
 
 
 
 
# Print hotels data.
def PrintHotelData(hotels):
    for h in hotels:
        print(h)
 
 
# Sort Hotels data by name.
def SortHotelByName(hotels):
    print("SORT BY NAME:")
 
    Hotel.sortByName()
    hotels.sort()
 
    PrintHotelData(hotels)
    print()
 
 
# Sort Hotels by rating
def SortHotelByRating(hotels):
    print("SORT BY A RATING:")
 
    Hotel.sortByRate()
    hotels.sort()
     
    PrintHotelData(hotels)
    print()
 
 
# Print Hotels for any city Location.
def PrintHotelBycity(s,hotels):
    print("HOTELS FOR {} LOCATION ARE:".format(s))
    hotelsByLoc=[h for h in hotels if h.location==s]
     
    PrintHotelData(hotelsByLoc)
    print()
 
 
 
# Sort hotels by room Available.
def SortByRoomAvailable(hotels):
    print("SORT BY ROOM AVAILABLE:")
    Hotel.sortByRoomAvailable()
    hotels.sort()
    PrintHotelData(hotels)
    print()
 
 
# Print the user's data
def PrintUserData(userName, userId, bookingCost, hotels):
    users=[]
    # Access user data.
    for i in range(3) :
        u=User()
        u.uname = userName[i]
        u.uId = userId[i]
        u.cost = bookingCost[i]
        users.append(u)
 
    for i in range(len(users)) :
        print(users[i],"\tHotel name:",hotels[i].name)
     
 
 
# Functiont to solve
# Hotel Management problem
def HotelManagement(userName,
                     userId,
                     hotelName,
                     bookingCost,
                     rooms,
                     locations,
                     ratings,
                     prices):
    # Initialize arrays that stores
    # hotel data and user data
    hotels=[]
 
    # Create Objects for
    # hotel and user.
 
    # Initialise the data
    for i in range(3) :
        h=Hotel()
        h.name = hotelName[i]
        h.roomAvl = rooms[i]
        h.location = locations[i]
        h.rating = ratings[i]
        h.pricePr = prices[i]
        hotels.append(h)
     
    print()
 
    # Call the various operations
    PrintHotelData(hotels)
    SortHotelByName(hotels)
    SortHotelByRating(hotels)
    PrintHotelBycity("Bangalore",
                     hotels)
    SortByRoomAvailable(hotels)
    PrintUserData(userName,
                  userId,
                  bookingCost,
                  hotels)
 
 
# Driver Code.
if __name__ == '__main__':
 
    # Initialize variables to stores
    # hotels data and user data.
    userName = ["U1", "U2", "U3"]
    userId = [2, 3, 4]
    hotelName = ["H1", "H2", "H3"]
    bookingCost = [1000, 1200, 1100]
    rooms = [4, 5, 6]
    locations = ["Bangalore",
                           "Bangalore",
                           "Mumbai"]
    ratings = [5, 5, 3]
    prices = [100, 200, 100]
 
    # Function to perform operations
    HotelManagement(userName, userId,
                    hotelName, bookingCost,
                    rooms, locations,
                    ratings, prices)


Output

PRINT HOTELS DATA:
HotelName   Room Available    Location    Rating    PricePer Room:
H1          4              Bangalore       5            100
H2          5              Bangalore       5            200
H3          6              Mumbai       3            100

SORT BY NAME:
H3 6 Mumbai 3  100
H2 5 Bangalore 5  200
H1 4 Bangalore 5  100

SORT BY A RATING:
H1 4 Bangalore 5  100
H2 5 Bangalore 5  200
H3 6 Mumbai 3  100

HOTELS FOR Bangalore LOCATION IS:
H1 4 Bangalore 5  100
H2 5 Bangalore 5  200

SORT BY ROOM AVAILABLE:
H3 6 Mumbai 3  100
H2 5 Bangalore 5  200
H1 4 Bangalore 5  100

PRINT USER BOOKING DATA:
UserName UserID HotelName BookingCost
U1         2        H1         1000
U2         3        H2         1200
U3         4        H3         1100





Previous Article
Next Article

Similar Reads

UI Design of a Hotel Booking Website
In the modern age of digital technology, the effectiveness of a hotel booking website greatly depends on how well its user interface (UI) is designed. Every detail, from the choice of colors to the inclusion of interactive features, contributes significantly to improving the overall user experience. Design Principles Used to Create the DesignSelect
6 min read
Personal Hotel web UI
Designing UI (User Interface) for a Personal Hotel Website needs designing pages that are based on Principles of UI and functionality. The UI should highlight the hotel images, ratings, prices and availability of the Hotels. In this article, we will explore the important concepts needed to design an effective Personal Hotel Web UI. Designing the We
3 min read
Menu-Driven Program for Bank Management System
Prerequisite: Switch Case in C/C++Problem Statement: Write a program to build a simple Bank Management System using C++ which can perform the following operations: Open accountDeposit MoneyWithdraw MoneyDisplay Account Approach: Below is the approach to do the above operations: Open Account: This method takes details from the customer like name, ad
10 min read
Student Information Management System
Prerequisites: Switch Case in C/C++ Problem Statement: Write a program to build a simple Software for Student Information Management System which can perform the following operations: Store the First name of the student.Store the Last name of the student.Store the unique Roll number for every student.Store the CGPA of every student.Store the course
14 min read
Project Idea | Water Management System
Introduction: Water is one of the most important basic needs for living beings. But with the modernization and development of human lifestyles, consumption of water has been at the peak. The shortage of water has been thus increasing at a very rapid rate. States like Kerala and Chennai which had once ample of water is now running out of it. Wastage
5 min read
Health Management System using Python
Sometimes we are so busy that we are not even able to care for our body and by caring we mean fitness, food, exercises and much more, and then we think that we need to make our diet plan or exercise plan to maintain our body. So let's make a Python script to maintain this record for us. In this program, we add our diet and exercises that we need to
7 min read
CRUD Operations in Student Management System in Java
CRUD stands for Create, Read/Retrieve, Update and Delete and these are the four basic operations that we perform on persistence storage. CRUD is data-oriented and the standardized use of HTTP methods. HTTP has a few methods which work as CRUD operations and do note they are very vital from a developmental point perspective in programming that also
7 min read
Department Store Management System(DSMS) using C++
A Department Store Management System (DSMS) in C++ is a software tool used to manage the inventory and sales of items in a department store. In this article, we will be discussing the implementation of a DSMS on a command-line user interface using C++. The system allows various features to admin such as add, view, update, and delete items in the st
8 min read
Project Idea | Smart Waste Management System
INTRODUCTION: Brief presentation of the project (MUST SEE before reading further) The Internet of Things (IoT) is a concept in which surrounding objects are connected through wired and wireless networks without user intervention. In the field of IoT, the objects communicate and exchange information to provide advanced intelligent services for users
9 min read
E -Library Management System
In this article, we will discuss the approach to creating an E-Library Management System where the user has the following options: Add book information.Display book information.To list all books of a given author.To list the count of books in the library. Functionalities Required:If the user tries to add a book then the user must have to provide th
10 min read
Document Management System with React and Express.js
This project is a Document Management System (DMS) developed with a combination of NodeJS, ExpressJS for the server side and React for the client side. The system allows users to view, add, and filter documents. The server provides a basic API to retrieve document data, while the React application offers an intuitive user interface for interacting
7 min read
Content Management System (CMS) using React and Express.js
This project is a Content Management System (CMS) Admin Panel developed using React for the frontend and NodeJS and ExpressJS for the backend. The Admin Panel allows administrators to manage content, including viewing and editing posts, approving pending posts, and adding new content. It features real-time updates, allowing administrators to collab
8 min read
Expense Management System using MERN Stack
In this article, we’ll walk through the step-by-step process of creating a Expense Management System using the MERN (MongoDB, ExpressJS, React, NodeJS) stack. This project will showcase how to set up a full-stack web application where users can add their budget and put daily expenses that get deducted from the budget. Output Preview: Let us have a
14 min read
Document Management System using NextJS
The Document Management System is a web application developed using Next.js, that allows users to efficiently manage their documents. The system provides features for uploading, organizing, and retrieving documents. Users can upload documents through the web interface, which are then stored in local storage. Output Preview: Let us have a look at ho
5 min read
Customer Relationship Management (CRM) System with Node.js and Express.js
CRM systems are important tools for businesses to manage their customer interactions, both with existing and potential clients. In this article, we will demonstrate how to create a CRM system using Node.js and Express. We will cover the key functionalities, prerequisites, approach, and steps required to create the project. Output Preview: Prerequis
15+ min read
Hospital Management System using MEAN Stack
The Hospital Management App is an important application that ensures seamless coordination to revolutionize healthcare administration. In this article, we will be creating a Hospital Management Website using the MEAN stack – i.e. MongoDB, Express, Angular, and Node.js, with step by step process for easy understanding. Project Preview: Prerequisite:
15+ min read
Subscription Management System with NodeJS and ExpressJS
In this article, we’ll walk through the step-by-step process of creating a Subscription Management System with NodeJS and ExpressJS. This application will provide users with the ability to subscribe to various plans, manage their subscriptions, and include features like user authentication and authorization using JWT (JSON Web Tokens). We'll use Mo
5 min read
Volunteer Management System using MERN Stack
In this article, we will explore the development of a Volunteer Management System using NodeJS and ExpressJS and MongoDB as a database for storing data and performing operations . This project will involve performing basic and advanced calculations to streamline the volunteer management process. Output Preview: Let us have a look at how the final o
7 min read
Task Management System using Node and Express.js
Task Management System is one of the most important tools when you want to organize your tasks. NodeJS and ExpressJS are used in this article to create a REST API for performing all CRUD operations on task. It has two models User and Task. ReactJS and Tailwind CSS are used to create a frontend interface part in which we can add, delete, and update
15+ min read
User Management System Backend
User Management System Backend includes numerous endpoints for performing user-dealing tasks. The backend could be constructed with the use of NodeJS and MongoDB with ExpressJS . The software will offer an endpoint for consumer management. API will be capable of registering, authenticating, and controlling customers. In this article we will be buil
4 min read
Appointment Management System using React
The Appointment Management System is a web application that allows users to schedule, manage, and view appointments. It provides an easy-to-use interface for clients to book and keep track of appointments. Below is a simplified outline for creating an Appointment Management System using React JS. Preview of final output: Let us have a look at how t
5 min read
Student Management System using Express.js and EJS Templating Engine
In this article, we build a student management student which will have features like adding students to a record, removing students, and updating students. We will be using popular web tools NodeJS, Express JS, and MongoDB for the backend. We will use HTML, CSS, and JavaScript for the front end. We'll go through every step to create this applicatio
5 min read
College Management System using Django - Python Project
In this article, we are going to build College Management System using Django and will be using dbsqlite database. In the times of covid, when education has totally become digital, there comes a need for a system that can connect teachers, students, and HOD and that was the motivation behind building this project. This project allows HOD, staff, an
15+ min read
Create Task Management System using Django
Task management systems are essential tools for individuals and organizations to organize, track, and prioritize tasks efficiently. In this article, we'll explore how to build a task management system using django in Python. Task Management System using DjangoBelow, are the implementations of the Task Management System using Django in Python. Start
15+ min read
Convert the number from Indian system to International system
Given an input string N consisting of numerals and separators (, ) in the Indian Numeric System, the task is to print the string after placing separators(, ) based on International Numeric System. Examples: Input: N = "12, 34, 56, 789" Output: 123, 456, 789 Input: N = "90, 05, 00, 00, 000" Output: 90, 050, 000, 000 Approach: Remove all the separato
5 min read
Convert the number from International system to Indian system
Given string str which represents a number with separators(,) in the International number system, the task is to convert this string representation into the Indian Numeric System. Examples: Input: str = "123,456,789" Output: 12,34,56,789 Explanation: The given string represents a number in the international system. It is converted to the Indian sys
13 min read
Project Idea | Smart Waste Management Systems
Project Title: Smart Waste Management System Introduction: One of the essential components of a smart city is a Clean and Green Environment and the crux of it is a Smart, Intelligent, and Connected Waste Management System. In Espha, I have developed a System where the Waste bins are equipped with a Compactor and a Bin Level Detection System. Basic
3 min read
Perl | Database management using DBI
Prerequisites: Introduction to Perl Database Systems Creating database programs is one of the most common uses of Perl. Using Perl, we can create robust web applications along with a database to manage all the data. It provides excellent support for interfacing and a broad range of database formats. For connecting to and querying a database, Perl p
7 min read
First Fit algorithm in Memory Management using Linked List
First Fit Algorithm for Memory Management: The first memory partition which is sufficient to accommodate the process is allocated.We have already discussed first fit algorithm using arrays in this article. However, here we are going to look into another approach using a linked list where the deletion of allocated nodes is also possible.Examples: In
15+ min read
Program for Best Fit algorithm in Memory Management using Linked List
Best fit algorithm for memory management: The memory partition in which there is a minimum loss on the allocation of the process is the best-fit memory partition that is allocated to the process.We have already discussed one best-fit algorithm using arrays in this article. However, here we are going to look into another approach using a linked list
15+ min read
Article Tags :
Practice Tags :