Clas CO Inheritance Define a Car class that has the following protected members:
ID: 3729388 • Letter: C
Question
Clas CO Inheritance Define a Car class that has the following protected members: a string to store the car's id number and an integer to store the car's number of doors. Add appropriate constructors, accessor functions, and mutator functions. Also define a function named getMaxSpeed ( that returns an integer with the value of zero. int getMaxSpeed ); Next, define a RaceCar class that is derived from Car. The RaceCar class should have a private member variable named sponsor that stores the sponsor of the race car as a string. Add appropriate constructors, mutator functions, and accessor functions for the sponsor variable. Redefine the getMaxSpeed () function to return 150 if the race car has more than two doors and 200 if the car has two doors or fewer. Finally, create an application that does the following: Create a Car object and RaceCar pointer. Ask the user for the information to set the data members for the Car object. Print the max speed of the Car. Ask the user for the number of race cars. Create a dynamically-allocated array of RaceCar objects. Ask the user for the information to set the data members for each RaceCar object. Print the max speed for all the race cars. Don't forget to delete your RaceCars! .Explanation / Answer
Please write test code as per your requirement.
I have implemeted all functionality and template for testing.
#include <iostream>
using namespace std;
class Car{
protected:
int id;
int num_doors;
public:
Car(int i, int d){
id = i;
num_doors = d;
}
void setId(int i){
id = i;
}
void setDoors(int d) {
num_doors = d;
}
int getId() {
return id;
}
int getDoors() {
return num_doors;
}
virtual int getMaxSpeed() {
return 0;
}
};
class RaceCar:public Car {
private:
string sponser;
public:
RaceCar(int i, int d, string s):Car(i, d){
sponser = s;
}
void setSponser(string s){
sponser = s;
}
string getSponser(){
return sponser;
}
int getMaxSpeed() {
if(num_doors > 2){
return 150;
}else{
return 200;
}
}
};
int main() {
Car *c;
RaceCar *rc;
int i, d;
string s;
cout<<"Enter id and numbe rof doors: ";
cin>>i>>d;
c = new Car(i, d);
cout<<"Enter sponser name: ";
cin>>s;
rc = new RaceCar(i, d, s);
return 0;
}