One reason to use inheritance is that it permits you to reuse code from a previous project, but gives you the flexibility to slightly modify it if the old code doesn't do exactly what you need for the new project. It doesn't make sense to start every new project from scratch since some code will certainly be repeated in several programs and you should strive to build on what you did previously. Moreover, it is easy to make an error if you try to modify the original class. You are less likely to make an error if you leave the original alone and only add to it. Another reason for using inheritance is if the project requires the use of several classes which are very similar but slightly different.
A Simple Class
Examine the
file named vehicle.h for a simple class. There is nothing unusual about this class header,
it has been kept very simple. It consists of four simple methods which can be used to manipulate data pertaining
to our vehicle.
The Implementation for Vehicle
One of the classes you will implement is the file named vehicle.cpp. The initialize() method assigns the values input as parameters to the wheels and weight variables. We have methods to return the number of wheels and the weight, and finally, we have one that does a trivial calculation to return the loading on each wheel.
The First Derived Class
Examine the file named car.h for our first example of the use of a derived class or child class. The vehicle class is inherited due to the ": public vehicle". This derived class named car is composed of all of the information included in the base class vehicle, and all of its own additional information. Even though we did nothing to the class named vehicle, we made it into a base class because of the way we are using it here.
A discussion of terminology is needed here. When discussing object oriented programming in general, a class that inherits another is often called a derived class or a child class, but the most proper term as defined for C++, is a derived class. Since these terms are very descriptive, and most writers tend to use the terms interchangeably. Likewise the proper C++ terminology for the inherited class is to call it a base class, but parent class and super class are sometimes used also.
In this case, the vehicle base class can be used to declare objects that represent trucks, cars, bicycles, or any number of other vehicles you can think up. The class named car however can only be used to declare an object that is of type car because we have limited the kinds of data that can be intelligently used with it. The car class is therefore more restrictive and specific than the vehicle class. The vehicle class is more general than the car class.
If we wished to get even more specific, we could define a derived class using car as the base class, name it sports_car, and include such information as red_line_limit for the tachometer which would be silly for the family station wagon. The car class would therefore be used as a derived class and a base class at the same time, so it should be clear that these names refer to how a class is used.
How do we Declare a Derived Class?
A derived class is defined by including the header file for the base class as is done in line 5, then the name of the base class is given following the name of the derived class separated by a colon as is illustrated in line 7. All objects declared as being of class car therefore are composed of the two variables from the class vehicle because they inherit those variables, and the single variable declared in the class car named passenger_load.

An object of this class will have three of the four methods of vehicle and the two new ones declared here. The method named initialize() which is part of the vehicle class will not be available here because it is hidden by the local version of initialize() which is a part of the car class. The local method will be used if the name is repeated allowing you to customize your new class. The figure above is a graphical representation of an object of this class.
Note once again that the implementation for the base class only needs to be supplied in its compiled form. The source code for the implementation can be hidden for economic reasons to aid software developers. Hiding the source code also allows the practice of information hiding. The header for the base class must be available as a text file since the class definitions are required in order to use the class.
The Car Class Implementation
You will create the implementation file for the car class.
Another Derived Class
Examine the file named truck.h for an example of another class that uses the vehicle class and adds to it. Of course, it adds different things to it, because it will specialize in those things that pertain to trucks. In fact, it adds two more variables and three more methods. See the figure below for a graphical representation of the truck class.

A very important point that must be made is that the car class and the truck class have absolutely nothing to do with each other, they only happen to be derived classes of the same base class or parent class as it is sometimes called.
Note that both the car and the truck classes have methods named passengers() but this causes no problems and is perfectly acceptable. If classes are related in some way, and they certainly are if they are both derived classes of a common base class, you would expect them to be doing somewhat similar things. In this situation there is a good possibility that a method name would be repeated in both child classes.
Note: efficiency is defined as: weight/payload.
The Truck Implementation
You will create the implementation file for the truck class.
Using All Three Classes
Examine the program named main.cpp for an example that uses all three of the classes. It uses the parent class vehicle to declare objects and also uses the two child classes to declare objects. This was done to illustrate that all three classes can be used in a single program.
All three of the header files for the classes are included in lines 3 through 5 so the program can use the components of the classes.
In this example program, only one object of each class is declared and used but as many as desired could be declared and used in order to accomplish the programming task at hand. You will notice how clean and uncluttered the source code is for this program. The classes were developed, debugged, and stored away previously, and the interfaces were kept very simple. There is nothing new here so you should have no trouble understanding the operation of this program.
A Summary of what to do
Use WinZip or a simular program and create a .zip archive. Include all .cpp and .h files needed to compile the project. Submit the file mp12.zip to the homework web site.