Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

can someone complete this C++ please Subtask class Schedule: Define a class with name Schedule for a rental reservation schedule for a vehicle with a

can someone complete this C++ please 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.

a 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 Rental:

Define a class for a rental with name Rental with following members:

a private constant integer attribute with name no storing a unique reservation number for the rental.

a private attribute with name from of above type DayOfYear storing the starting day of a rental.

a private integer attribute with name days storing the number of rental days.

a private C++ string attribute with name customer storing the renting person.

a private static integer class variable with name last_no to generate a sequence of reservation numbers, which gets incremented each time a new object of this class is generated by the constructor and therefore can be used to automatically take care that all reservations/rentals get a unique identifying number. This class variable shall be defined and initialised outside of the class.

a public constructor with a first string parameter for the renting person, a second parameter of type DayOfYear for the starting day of the rental and an integer default parameter for the number of rental days with a default value 1. Beside the initialisation of the attributes related to the respective parameters the attribute no shall get a new unique sequential number using last_no (starting with rental number 1).

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

two public methods with names get_from and get_untilwithout parameters returning the start and end/return date of the rental of type DayOfYear. (Hint: in the body call/use above defined increment operator ++ of class DayOfYear in a loop days times.)

a public method with name print without parameter and without return type writing like in the examples below the start day of the rental, string "to", the end day of the rental, string ", rental no" and the reservation number as well as "for" and the renting person onto the standard character output stream.

#include #include

#include #include #include #include #include //Changed this one from string to cstring using namespace std; class DayOfYear { private: unsigned short dayOfYear; unsigned short year; const unsigned static short days[]; //12 months + 0 for the 1st January

public:

DayOfYear(short dayOfYear =1,short year=365) { this->dayOfYear = dayOfYear; this->year = year; }

DayOfYear(int day, int month, int year) { this->dayOfYear = getDayOfYear(day,month); this->year = year; }

short getDayOfYear(int day, int month) { short dayOfYear=0 ; for(int i=0;i

short get_dayOfYear() { return this->dayOfYear; }

DayOfYear operator++() { short newYear; short newDayOfYear; if(this->dayOfYear%365 == 0) { newYear = this->year+1; newDayOfYear = 1; } newDayOfYear = this->dayOfYear + 1; return DayOfYear(newDayOfYear,newYear); }

string getDayAndMonth() //////// { int prevDay; int day = this->dayOfYear; int month=-1; while(day >0) { month++; prevDay = day; day -= days[month]; } return string(prevDay+"/"+month); }

ostream& operator<<(ostream& os) ////////// { os <getDayAndMonth() << '/' << this->year; return os; } }; const unsigned short DayOfYear::days[31]={0,31,59,90,120,151,181,212,243,273,304,335,366};

class Vehicle { public: int no; string model; float price24h;

public: Vehicle(int no,string model,float price24h) { this->no = no; this->model = model; this-> price24h = price24h; } Vehicle() { } int get_no() { return this->no; } string get_model() { return this->model; } float get_price(int rentalDays) { return this->price24h*rentalDays; } virtual void print()=0; //a public pure virtual virtual ~Vehicle() { }; };

class Bike:public Vehicle { public:

Bike(int no, string model) { this->no = no; this->model = model; this->price24h = 9.99; } virtual void print() { cout<<"(BIKE) no : "<no<<", model : "<model<

class EMotorVehicle: public Vehicle { public: EMotorVehicle(int no,string model,float price24h) { this->no = no; this->model = model;

} EMotorVehicle() {

}

virtual bool is_streetLegal()=0;

virtual void print() { if(!this->is_streetLegal()) cout<<"(not street legal)"<no<<", model : "<model<

class EBike: public EMotorVehicle { public: EBike(int no,string model,float price24h = 29.99) { this->no = no; this->model = model; this->price24h = price24h; } bool is_streetLegal() { return true; }

void print() { cout<<"(EBkie) "; EMotorVehicle::print(); }

};

class EScooter: public EMotorVehicle { private: bool streetLegal; public: EScooter(int no,string model,float price24h = 19.99,bool streeLegal=false) { this->no = no; this->model = model; this->price24h = price24h; this->streetLegal = streetLegal; } bool is_streetLegal() { return this->streetLegal; }

void print() { cout<<"EScooter) "; EMotorVehicle::print(); } };

class Rental { private: const int no = 478; DayOfYear from; // starting day of rental int days; // no. rental days string customer; //renting person name static int last_no;

public: Rental(string customer, DayOfYear from, int days = 1) : no(Rental::last_no++) { this->from = from; this->days = days; this->customer = customer;

}

int get_days() { return this->days; } DayOfYear get_from() { return this->from; } DayOfYear get_until() { DayOfYear until(this->from); // Creating a new Object of DayOfYear int rentalDays = this->days; while(rentalDays--) { until = ++until; } return until; } void print() { cout<from.getDayAndMonth()<<" to "<get_until().getDayAndMonth()<<" with rental no. "<no<<" for "<customer<vehicle = vehicle; this->next = NULL; for (int i = 0; i < 365; i++) { this->year[i] = NULL; } } Vehicle* get_vehicle() { return this->vehicle; }

Schedule* get_next() { return this->next; }

void set_next(Schedule* next) { this->next = next; }

bool isFree(DayOfYear date, int days) {

for (int i = date.get_dayOfYear() - 1; i < date.get_dayOfYear() - 1 + days; i++) { if (this->year[i] != NULL) { return false; } } return true; } float book(string person, DayOfYear date, int days) { Rental* rental = new Rental(person, date, days); for (int i = 0; i < days; i++) { this->year[date.get_dayOfYear() - 1 + i] = rental; }

return this->vehicle->get_price(days); }

void print(DayOfYear date) { this->vehicle->print();

if (this->year[date.get_dayOfYear() - 1] != NULL) { cout << endl; this->year[date.get_dayOfYear() - 1]->print(); } } void print() { cout << "SCHEDULE FOR "; vehicle->print(); for (int i = 0; i < 365; i++) { if (this->year[i] != NULL && this->year[i]->get_from().get_dayOfYear() == i+1) { cout << endl; this->year[i]->print(); cout << ", total: " << this->get_vehicle()->get_price(this->year[i]->get_days()) << " EUR"; } } }

};

int main() { 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

Machine Learning And Knowledge Discovery In Databases European Conference Ecml Pkdd 2014 Nancy France September 15 19 2014 Proceedings Part 3 Lnai 8726

Authors: Toon Calders ,Floriana Esposito ,Eyke Hullermeier ,Rosa Meo

2014th Edition

3662448440, 978-3662448441

More Books

Students also viewed these Databases questions

Question

5. Give examples of binary thinking.

Answered: 1 week ago

Question

How does the concept of hegemony relate to culture?

Answered: 1 week ago

Question

Define Management or What is Management?

Answered: 1 week ago

Question

Perform an Internet search. Discuss a company that uses EPLI.

Answered: 1 week ago

Question

How do you feel about employment-at-will policies? Are they fair?

Answered: 1 week ago