Writing a new class that is derived from another class

Assignment Help Basic Computer Science
Reference no: EM13322349

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.

You need to create a CustomCar class. Put the specification for it in the CustomCar.h file and the implementation for it in the CustomCar.cpp file. The CustomCar class should extend the Car class and have the following new features:

  • It will need to have its own constructor. The constructor should simply call the Car constructor and then set the private features variable to be empty. See the book for an example.
  • It will need a SetColor method. This method should simply set the Car's color. The Car's color is a Protected variable. This means that the derived class can change it.
  • It will need a SetFeatures method. This method should set the features in a private variable of the CustomCar class
  • It will need to have a PrintInfo method. This method should call the existing Car PrintInfo method, and then print the features info after that
  • It will need to have a private features variable to store the text of the 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.

Driver Program: Paste this into your main.cpp

// 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;

}

 

Reference no: EM13322349

Critique of a corporate accounting fraud scandal

Project involves the summary and critique of a corporate accounting fraud scandal. Research paper should be at least 5 typed pages + cited references. Research paper should

Do not use pseudo-instructions

You are to complete the program by writing four functions.  Pay particular attention to the purpose of each function, what registers to use and how the parameters and stack ar

Threat to ships-which manufactures have instituted control

Provide two examples of threats to boats/ships for which manufactures and/or regulators have instituted controls. Describe the vulnerabilities for which the controls were

Write a program in c++ that converts from miles to kilometer

Write a program in C++ that converts from miles to kilometers. Your program should have a reasonable prompt for the user to enter a number of miles. Hint: There are 1.609 ki

Determining the network standards and protocols

List and discuss at least three major ways your life has been impacted due to the ability to communicate over the Internet? What specific network standards and protocols do yo

Find a bad set for different values of nhash

Our hash function is an excellent general-purpose hash for strings. Nonetheless, peculiar data might cause poor behavior. Construct a data set that causes our hash function

Create a flowchart psuedocode and desk check

The members of the board of a small university are considering voting for a pay increase for their 25 faculty members. They are considering a pay increase of 8%. However, befo

Fit a multiple regression model to these data

The brake horsepower developed by an automobile engine on a dynamometer is thought to be a function of the engine speed in revolutions per minute (rpm), the road octane numb

Reviews

Write a Review

 
Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd