writing a new class that is derived from another class. You will be given the co
ID: 3534528 • Letter: W
Question
writing a new class that is derived from another class.You will be given the code for a Car class. Your job is to write a CustomCar class that is derived from Car and adds new features to it.The existing Car class will allow you to create a specific model of a car, but that car will always be the color black and have no features.
create a CustomCar class. Put the specification for it in the CustomCar.h file and the implementation for it in theCustomCar.cpp file. The CustomCar class should extend the Car class and have the following new features:
Test 1 checks for the output of the Red color Work on getting this working first.
Test 2 checks for the output of the features. Work on getting this working next.
// YOUR NAME HERE
#include <iostream>
#include <string>
#include "Car.h"
#include "CustomCar.h"
using namespace std;
Car *theCars[100];
int theCarsCount = 0;
void AddCarToList(Car* car){
theCars[theCarsCount] = car;
theCarsCount++;
}
void PrintCarList(){
for(int i=0; i<theCarsCount; i++)
theCars[i]->PrintInfo();
}
void main()
{
// Use this code as is:
cout << "Hello World!" << endl;
Car *carA = new Car("Basic");
Car *carB = new Car("Model-T");
CustomCar *carC = new CustomCar("Sporty");
carC->SetColor("Red");
carC->SetFeatures("Sun-Roof & Leather Seats");
AddCarToList(carA);
AddCarToList(carB);
AddCarToList(carC);
PrintCarList();
}
Here is the standard car.h class:
#include <iostream>
#include <string>
using namespace std;
class Car {
public:
Car(string model);virtual void PrintInfo();
protected:
string Model;string Color;};
Here is standard car.cpp:
#include "Car.h"
Car::Car(string model) {
Model = model;
Color = "Black";
}
void Car::PrintInfo() {
cout << "CAR INFO" << endl;
cout << " Model: " << Model << endl;
cout << " Color: " << Color << endl;
}
Explanation / Answer
please rate:
http://ideone.com/kazyDD
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.