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

Questions Cloud

Explain the emission spectrum of helium : In the emission spectrum of helium, there are strong lines at wavelengths of 447.1 nm, 501.6 nm, and 587.6 nm. Using the Balmer-Rydberg equation, determine the values of nf for each emission.
Compute the enthalpy change for the neutralization reaction : Calculate the enthalpy change for the neutralization reaction. Calculate the experimental error compared to the accepted your value in question 2.
The quantity of money in the hands of the public to increase : Why might the Fed find it significantly easier to expand the money stock in a period of prosperity than in a period of recession? What must the Fed be able to do if it wants the quantity of money in the hands of the public to increase?
Find the rms current in the circuit : In a purely inductive circuit of 36 mH, the freq is 71 Hz and the maxium voltage is 317 V. Find the rms current in the circuit
Writing a new class that is derived from another class : 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.
How much oil spills : A copper flask with a volume of 80 cm^3 is filled to the brim with olive oil. If the temp of the system is increased from 8C to 52C, how much oil spills
Simulate the game of yahtzee : After displaying the possible scores for each category, ask the user which score to keep (it might not be the largest). Once the box is filled, it cannot be scored again.
Find how much work is done on the system : A cylnder holds .5 moles of an ideal gas at temp 334K. The gas expands isothermally from an initail volume of .03 m^3 to a final volume of .4m^3
Compute the after-tax cost : Assuming a 25 percent tax rate, compute the after-tax cost of the following business expenditures.

Reviews

Write a Review

 

Basic Computer Science Questions & Answers

  Why should a company implement a csr program

3. How does the CSR program apply to today's trends and current issues in the global marketplace? 4. Whom is the company responsible to? 5. Why should a company implement a CSR program?

  Explain bindings which are required to determine semantics

Write simple assignment statement with one arithmetic operator in some language you know. For each component of statement, write various bindings which are needed to determine semantics.

  Briefly describe how you could achieve this

Suppose you would like to have most of your program variables residing in external RAM while a few time-critical variables should reside in the first 128 bytes of internal RAM. Briefly describe how you could achieve this.

  Write the code of the main part of the program

Write the code of the main part of the program so that the code only uses the operations enqueue, dequeue, size, and isEmpty. Then, show that your program works with both types of queue implementation { as a linked list and as an array.

  Showing how to use the html element

Describe the attributes that you think would be useful with the HTML element. Provide an example code snippet showing how to use the HTML element. !DocType Html

  How much storage will probe require if it is to gather data

The system has a clock that runs at 1GHz. During each cycle of the system clock, the status of these 5 registers how much storage will the probe require if it is to gather data for 2 seconds?

  Determining contents of the register a

The hexadecimal form of a 3-byte instruction for SIC/XE is 010030. The opcode in the instruction is LDA. Indicate the contents of the register A in decimal.

  Write a statement to print the counter value

Write a For loop such that the loop till iterate from 1000 to 1 decrementing the counter by 1 each time through the loop. Inside the loop, write a statement to print the counter's value to the Output window.

  What type of address is stored in the source address field

What type of address is stored in the Source Address field of an Ethernet frame

  Review and discuss methods for it manager

Review and discuss methods for IT managers to maintain their skills while gaining new managerial skills

  Determine the mix of cargo

The load master for a freighter wants to determine the mix of cargo to be carried on the next trip. The ship's volume limit for cargo is 100,000 cubic meters, and its weight capacity is 2,310 tons.

  Comparing accuracies using test options

Compare the accuracies obtained using the three "test options": "Use training set", "cross-validation" and "percentage split".

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