You are in the rental car business. Create a class called RentalCar that include
ID: 3769717 • Letter: Y
Question
You are in the rental car business. Create a class called RentalCar that includes a string type for the car type (e.g., passenger car, van, truck, etc.) and a double field for the rental rate per day. Include get methods for these fields and a constructor that requires a string argument representing the car type. The constructor sets the room rate as follows – cars $49.99 per day, vans $69.99 per day, trucks $89.99 per day. Create an extended class, Luxury, whose constructor requires a car type and adds $20 per day to the appropriate rental rate for each type of vehicle. Write an application named UseRentalCar which creates an object of each class. Demonstrate that all methods work as they should.
Answer in C++
Explanation / Answer
Hi,
Below is the program that you are looking for:
program:
#include <iostream>
using namespace std;
// Base class
class RentalCar
{
protected:
string car_type;
double rental_pay;
public:
RentalCar() {}
RentalCar(string c) :car_type(c)
{
if (c =="car"){
rental_pay=49.99;
}
else if(c=="vans"){
rental_pay=69.99;
}
else if(c=="trucks"){
rental_pay=89.99;
}
else{
cout<<"Invalid car type"<<endl;
}
}
public:
void get_cartype ()
{
return car_type;
}
void get_rentalpay()
{
return rental_pay;
}
class Luxury : public RentalCar{
public:
Luxury():RentalCar(string c){
for_each(c){
rental_pay=rental_pay+20;//Adding 20$ for each of the car type
cout<<"Rental pay is"<<rental_pay<<endl;
}
Luxury(string c,double r) :car_type(c),rental_pay(r)
}
}
#include <iostream>
using namespace std;
class UseRentalCar{
int main(){
RentalCar rcar;
Luxury lux;
rcar.RentalCar("car");
rcar.get_cartype();
rcar.get_rentalpay();
rcar.RentalCar("vans");
rcar.get_cartype();
rcar.get_rentalpay();
rcar.RentalCar("trucks");
rcar.get_cartype();
rcar.get_rentalpay();
lux.Luxury("car");
lux.get_cartype();
lux.get_rentalpay();
lux.Luxury("vans");
rcar.get_cartype();
rcar.get_rentalpay();
lux.Luxury("trucks");
rcar.get_cartype();
rcar.get_rentalpay();
}
}
Hope that helps...HAPPY ANSWERING!!!!!!!!!
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.