Question

In: Computer Science

C++ CLASSES 1. Define a class date that has day, month and year data members. 2....

C++

CLASSES

1. Define a class date that has day, month and year data members.

2. Define a class reservation with following data members:

- An integer counter that generates reservation numbers.

- An integer as a reservation number. The counter is incremented each time a reservation object is created. This value will be assigned as the reservation number.

- Number of beds.

- Reservation date from class date.

3. Define a class rooms with data members:

- Room number

- Number of beds (1 or 2).

- A 2D int array (12 by 30) that show the availability of the room on each day of the year. The rows are the months and columns are days of month. If the room in available on a specific date, the array element value is zero. If the room has been reserved, the array element value has the reservation number.

4. Define a manager class with data member:

- A variable motel_size that indicates the number of rooms of motel.

- An array of pointers to rooms.

- An array of pointers to guests.

Member Functions:

- Function that processes a reservation received as parameter. If unsuccessful the function returns zero. If the reservation is successful (if the a room with requested # of beds is available during the required dates) the function returns reservation number.

- Function that receives reservation number as parameter and outputs the details of reservation.

- Function that receives reservation number and date as parameters and cancels reservation.

- Function that dictates the availability of single and double rooms on a required date.

5. Main function:

Creates manager, and reservation objects. This function calls the manager member function to process reservations.

Solutions

Expert Solution

#include <iostream>
#include "Reservation.cpp"
int main() {
    Manager m;
    reservation r;
    r.reservationNo = 2322;
    r.reservationDate.day=1;
    r.reservationDate.month =2;
    r.numberOfBeds =2;
    m.reserve(&r);
    m.printDetails(r.reservationNo,std::cout);
    std::cout<<"\nIs room available:"<<(m.isAvailable(2,r.reservationDate)>0?"true":"false");
}
#include <ostream>

class date {
public:
    int day;
    int month;
    int year;

    friend std::ostream &operator<<(std::ostream &os, const date &date) {
        os << "day: " << date.day << " month: " << date.month << " year: " << date.year;
        return os;
    }

};

class reservation {
public:
    int countReservationNos;
    int reservationNo;
    int numberOfBeds;
    date reservationDate;

    friend std::ostream &operator<<(std::ostream &os, const reservation &reservation) {
        os << "countReservationNos: " << reservation.countReservationNos << " reservationNo: "
           << reservation.reservationNo << " numberOfBeds: " << reservation.numberOfBeds << " reservationDate: "
           << reservation.reservationDate;
        return os;
    }
};

class room {
public:
    int roomNp;
    int noOfBeds;
    int availability[12][30];

    friend std::ostream &operator<<(std::ostream &os, const room &room) {
        os << "roomNp: " << room.roomNp << " noOfBeds: " << room.noOfBeds << " availability: " << "True";
        return os;
    }

    room() {
        noOfBeds = 2;//by default
        for (int i = 0; i < 12; ++i) {
            for (int j = 0; j < 30; ++j) {
                availability[i][j] = 0;
            }
        }
    }

    room(int beds) {
        if (beds == 1 || beds == 2) {
            noOfBeds = beds;
        } else {
            beds = 2;//default
        }
        for (int i = 0; i < 12; ++i) {
            for (int j = 0; j < 30; ++j) {
                availability[i][j] = 0;
            }
        }
    }
};

class guest {
    char *name;
};

class Manager {
public:
//    int emptyRoomNo = 0;

    int motel_size=10;
    room *rooms;
    guest *guests;

    Manager() {
        rooms = new room[motel_size];
    }

    Manager(int noOfRooms) {
        rooms = new room[noOfRooms];
        motel_size = noOfRooms;
    }

    int reserve(reservation *reserva) {

        bool reserved=false;
        for (int i = 0; i < motel_size; ++i) {
            if((rooms+i)->availability[reserva->reservationDate.day][reserva->reservationDate.month]==0){
                (rooms+i)->availability[reserva->reservationDate.day][reserva->reservationDate.month] = reserva->reservationNo;
                return true;
            }
        }

        return reserved;
    }

    bool isAvailable(int beds, date dat) {
        for (int i = 0; i < motel_size; ++i) {
            if ((rooms + i)->availability[dat.day][dat.month] == 0 && (rooms + i)->noOfBeds >= beds) {
                return true;
            }
        }
        return false;
    }

    bool cancelReservaton(int resNo, date dat) {
        for (int k = 0; k < motel_size; ++k) {
            if ((rooms + k)->availability[dat.day][dat.month] == resNo) {
                (rooms + k)->availability[dat.day][dat.month]=0;
                return true;
            }
        }
        return false;
    }
    void printDetails(int resNo,std::ostream& temp){
        for (int k = 0; k < motel_size; ++k) {
            for (int i = 0; i < 12; ++i) {
                for (int j = 0; j < 30; ++j) {
                    if ((rooms + k)->availability[i][j] == resNo) {
                        temp<<*(rooms+k);
                        return;
                    }
                }
            }
        }

    }
};

Sample out:


Related Solutions

C++ Define a MyDate class to represent a data that has 3 data members: day, month,...
C++ Define a MyDate class to represent a data that has 3 data members: day, month, year. The class should have: A default constructor to initialize the day, month, and year to 0. A constructor that accepts three integers as arguments to initialize the day, month, and year if the three arguments are valid. A copy constructor that accepts a reference to a MyDate object as argument. This constructor use the argument's three data fields to initialize the day, month,...
C++ program: Create a Date class that contains three members: the month, the day of the...
C++ program: Create a Date class that contains three members: the month, the day of the month, and the year, all of type int. The user should enter a date in the format 12/31/2001, store it in an object of type Date, then retrieve the object and print it out in the same format. Next create an employee class. The member data should comprise an employee number (type int) and the employee’s compensation (in dollars; type float). Extend the employee...
Create a "Date" class that contains: three private data members: month day year (I leave it...
Create a "Date" class that contains: three private data members: month day year (I leave it to you to decide the type) "setters" and "getters" for each of the data (6 functions in total) One advantage of a "setter" is that it can provide error checking. Add assert statements to the setter to enforce reasonable conditions. For example, day might be restricted to between 1 and 31 inclusive. one default constructor (no arguments) one constructor with three arguments: month, day,...
In c++, define a class with the name BankAccount and the following members: Data Members: accountBalance:...
In c++, define a class with the name BankAccount and the following members: Data Members: accountBalance: balance held in the account interestRate: annual interest rate. accountID: unique 3 digit account number assigned to each BankAccount object. Use a static data member to generate this unique account number for each BankAccount count: A static data member to track the count of the number of BankAccount objects created. Member Functions void withdraw(double amount): function which withdraws an amount from accountBalance void deposit(double...
c++ Design the Weather class that contains the following members: Data members to store: -a day...
c++ Design the Weather class that contains the following members: Data members to store: -a day (an integer) -a month (an integer) -a year (an integer) -a temperature (a float) -a static data member that stores the total of all temperatures (a float) Member functions: -a constructor function that obtains a day, month, year and temperature from the user. This function should also accumulate/calculate the total of all temperatures (i.e., add the newly entered temperature to the total). -a static...
Date - month: int - day: int - year: int +Date() +Date(month: int, day: int, year:...
Date - month: int - day: int - year: int +Date() +Date(month: int, day: int, year: int) +setDate(month: int, day: int, year: int): void -setDay(day: int): void -setMonth(month: int): void -setYear(year: int): void +getMonth():int +getDay():int +getYear():int +isLeapYear(): boolean +determineSeason(): string +printDate():void Create the class Constructor with no arguments sets the date to be January 1, 1900 Constructor with arguments CALLS THE SET FUNCTIONS to set the Month, then set the Year, and then set the Day - IN THAT ORDER...
In C++ Define a base class called Person. The class should have two data members to...
In C++ Define a base class called Person. The class should have two data members to hold the first name and last name of a person, both of type string. The Person class will have a default constructor to initialize both data members to empty strings, a constructor to accept two string parameters and use them to initialize the first and last name, and a copy constructor. Also include appropriate accessor and mutator member functions. Overload the operators == and...
Define the class HotelRoom. The class has the following private data members: the room number (an...
Define the class HotelRoom. The class has the following private data members: the room number (an integer) and daily rate (a double). Include a default constructor as well as a constructor with two parameters to initialize the room number and the room’s daily rate. The class should have get/set functions for all its private data members [20pts]. The constructors and the get/set functions must throw an invalid_argument exception if either one of the parameter values are negative. The exception handler...
Define the class HotelRoom. The class has the following private data members: the room number (an...
Define the class HotelRoom. The class has the following private data members: the room number (an integer) and daily rate (a double). Include a default constructor as well as a constructor with two parameters to initialize the room number and the room’s daily rate. The class should have get/set functions for all its private data members [20pts]. The constructors and the get/set functions must throw an invalid_argument exception if either one of the parameter values are negative. The exception handler...
C++ Define a base class called Person. The class should have two data members to hold...
C++ Define a base class called Person. The class should have two data members to hold the first name and last name of a person, both of type string. The Person class will have a default constructor to initialize both data members to empty strings, a constructor to accept two string parameters and use them to initialize the first and last name, and a copy constructor. Also include appropriate accessor and mutator member functions. Overload the operators == and !=...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT