Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

c++ Subtask class Schedule Define a class with name Schedule for a rental reservation schedule for a vehicle with a maximum of one year ahead

c++

Subtask class Schedule Define a class with name Schedule for a rental reservation schedule for a vehicle with a maximum of one year ahead with following members:

a private attribute with name vehicle of type pointer to Vehicle this schedule belongs to.

  • a private array of 365 pointers of class Rental with name year used to store a pointer to an object of type Rental for every day a rental exists maximum one year ahead (from today; e.g. on September 25th a rental starting at August 2nd of the following year can be booked; the year can be ignored; rentals are not allowed longing more than 28 days).
  • a private attribute with name next of type pointer to Schedule to set up a list of several to rent vehicles.
  • a public constructor with a single parameter of type pointer to a Vehicle. to initialise the respective attribute. Pointer next and all pointers in array year shall be set to null pointers (no rentals ahead).
  • a public method with name get_vehicle without parameter returning a pointer to the vehicle as function value.
  • .public method with name get_next without parameter returning a pointer to the next schedule as function value.
  • a public method with name set_next with a pointer of type Schedule as parameter assigning the respective attribute.
  • a public method with name isFree with a date of type DayOfYear as first parameter as start day of a planned rental, an integer number of days as second parameter, how long the rental is planned, and a Boolen return value. In the body it shall be checked whether the whole time period will be free (return value true) or not (return value false).
  • a public method with name book with a string for the renting person as first parameter, a date of type DayOfYear as second parameter for the start day of the rental, an integer number of days as third parameters, how long the rental is planned, and a floating point return value. In the body a new object of type Rental on the heap shall be generated and its address being stored in array year for each rental day in a loop (the index into the array for the start day of the rental can be calculated by sending a message get_dayOfYear() to the date object - don't forget to subtract 1). Return value shall be the price for this rental determined by a message get_price sent to the vehicle.
  • a public method with name print with a date of type DayOfYear as parameter without return type, sending a message print to the vehicle and afterwards a message print to the reservation object - if it exists, i.e. it is not a null pointer - for this day in the respective array element (see examples below).
  • a public method with name print without parameter and without return type, writing like in the example below a title "SCHEDULE", then sending a message print to the vehicle and afterwards printing all rentals for the vehicle stored in array year together with their prices- each rental for several days shall be written only once, not again und again for each rental day.
  • /Subtask class Agency
  • Define a class for the renting agency with name Agency with following members:

    a private attribute profitPercent of type float for the profit percentage of the agency for each rental.

    a private attribute profit of type float for the summed up profit of the agency.

    two private pointer attributes with name head and last of type Schedule as pointers to the first and the last element of a list of schedules for all the vehicles of the agency

    a public standard constructor initialising the percentage of the profit to 20%, the profit to 0.00 EUR and the two pointers to null pointers.

    a public method with name get_profit without parameter returning the value of the respective attribute.

    a public method with name set_profitPercentage with a float parameter without return type assigning the value of the parameter to the respective attribute.

    a public method with name add with a pointer of type Vehicle as parameter without return type allocating a new object of type Schedule on heap for this vehicle and appending it at the end of the list.

    a protected method with name searchFor with an integer parameter and a pointer of type Schedule as return type searching in the list of schedules for the vehicle with the number given by the parameter and returning it.

  • a public method with name isFree with a first integer parameter for a vehicle number, a date of type DayOfYear as second parameter as start day of a planned rental, an integer number of days as third parameter, how long the rental is planned, and a Boolen return type. The method shall check whether the vehicle will be free at the desired time period or not. Therefore send to the object of type Schedule, which is returned by the search function in the previous item, a message isFree and return its value

    a public method with name book with a first integer parameter for a vehicle number, a string for the customer as second parameter, a date of type DayOfYear as third parameter as start day of a planned rental, an integer number of days as forth parameter, how long the rental is planned, and a float as return type. The method shall book the vehicle for the customer. Therefore send to the object of type Schedule, which is returned by the search function in the previous item, a message book. Calculate the profit by the profit percentage and the returned price value and add it to profit. Afterwards return the price.

  • a public method with name chooseVehicle without parameter and an integer return type. In the body a list of the vehicles of all schedules shall be written onto standard character output stream, a vehicle number read from input and returned (see examples below). This functionality you can use later in function main in menue entry C.
  • a public method with name print with a date of type DayOfYear as parameter without return type. It shall output all reservations of all schedules at this date (see examples below).
  • a public method with name print without a parameter and without return type. It shall output all reservations of all schedules in the list as well as the value of profit (see examples below).
  • Subtask main

  • Define an object of class Agency and program a small menue inside a loop with in the example shown functionalities A to K for this object as given below. Define your classes and the functionalities of the menue entries step by step. Start for example with class DayOfYear, define two variables today and tomorrow and program first functionalities B, D and E (only output), then maybe G, H and I with the related classes, following e.g. C and F, and so on

  • hier the first classes and the output:

  • -------------------------------------------------

  • MENUE A end of simulation B set new simulation date C new rental manually D print rental of today 2021-01-01 E print rental of tomorrow 2021-01-02 F print all rentals G print agency profit H set agency profit percent I add bikes J add E-bikes K add E-scooters L new rental simulation your choice: b input date of today: 2021-01-08
  • -------------------------------------------------

  • class DayOfYear { private: unsigned short int dayOfYear, year; static const int days []; public: DayOfYear(int d=1,int y=365):dayOfYear(d),year(y){} DayOfYear(int day,int monat,int year) { int t =0; for (int i=1;i t+=days[i-1]; t+=day; dayOfYear=t; year=year;

    } short unsigned int get_dayOfYear () { return dayOfYear; }

    DayOfYear &operator++(int) { if(dayOfYear==365) { dayOfYear =1; year++; }

    } friend istream & operator>>(istream & in, DayOfYear & D) { short d, m, y; in >> y; in.get(); in >> m; in.get(); in >> d; D = DayOfYear(d, m, y); return in; } friend ostream & operator<<(ostream & output, const DayOfYear & D) { output << D.year<<"-"; int d = D.dayOfYear,i=1; while (d > D.days[i-1]) { d -= D.days[i-1]; i++; } output << (i) << "-" << d< return output; } }; const int DayOfYear::days[] = {0,31,59,90,120,151,181,212,243,273,304,330,365}; class Vehicle { private: const int no;string modle;float price24h; public: Vehicle(int no,string modle,float price24h):no(no),modle(modle),price24h(price24h){} virtual ~ Vehicle() { cout << "destructor of Vehicle done" << endl; } int get_no() {return no;} string get_modle() {return modle;} float get_price(int p) { return p*price24h; } virtual void print()=0;

    }; class Bike: public Vehicle {

    public: Bike(int a,string b,float c):Vehicle (a,b,c=9.99){} virtual void print() { Vehicle::print(); cout< } }; class EMotorVehicle:public Vehicle{ public: EMotorVehicle(int a,string b,float c):Vehicle(a,b,c=9.99){} virtual bool is_streetLegal()=0; virtual void print() { if(this->is_streetLegal()) { cout<<"(not street legal)"< } else cout<<"(not street legal)"< } }; class EBike: public EMotorVehicle{ public:

    EBike (int a,string ,float c):EMotorVehicle(a,"",c=29.99){}

    virtual bool is_streetLegal() { return true; } virtual void print() { cout<<"(EBike)"< EMotorVehicle::print();

    }

    }; class EScooter:public EMotorVehicle { private: bool streetlegal; public: EScooter (int a,string b ,float c,bool):EMotorVehicle(a,b,c=19.99),streetlegal(false) {} virtual bool is_streetLegal() { return streetlegal; } virtual void print() { EMotorVehicle::print(); cout<<"(EScooter)"< }

    }; class Rental { private: string customer;//renting person DayOfYear from;//start day int days;// rental day const int no;//number of rental static int last_no; public: Rental(string c,DayOfYear b, int d=1 ):customer(c),from(b), days(d),no(Rental::last_no++){} int get_days() {return days;} DayOfYear get_from() {return from;} DayOfYear get_until() { for(int i=0;i { Rental::from++; } return from; } void print() { cout< < } }; int Rental::last_no=0; class schedule:public Rental { private:

    Vehicle*vehicle;

    };

    int main(void) { cout << "0" << endl; return 0; }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Big Data Systems A 360-degree Approach

Authors: Jawwad ShamsiMuhammad Khojaye

1st Edition

0429531575, 9780429531576

More Books

Students also viewed these Databases questions

Question

What is Change Control and how does it operate?

Answered: 1 week ago

Question

How do Data Requirements relate to Functional Requirements?

Answered: 1 week ago