Multiple inheritance

In order to keep the program as simple as possible, all of the member methods are defined as inline functions.? This puts the code for the methods where it is easy to find and study.? You will also notice that all variables in both classes are declared to be protected so they will be readily available for use in any class which inherits them.? The code for each class is kept very simple
so that we can concentrate on studying the interface to the methods rather than spending time trying to understand complex methods.

/*******************************************************
*     MYCPLUS Sample Code - https://www.mycplus.com     *
*                                                     *
*   This code is made available as a service to our   *
*      visitors and is provided strictly for the      *
*               purpose of illustration.              *
*                                                     *
* Please direct all inquiries to saqib at mycplus.com *
*******************************************************/
#include 

class moving_van {
protected:
   float payload;
   float gross_weight;
   float mpg;
public:
   void initialize(float pl, float gw, float in_mpg) {
     payload = pl;
     gross_weight = gw;
     mpg = in_mpg; };
   float efficiency(void) {
     return(payload / (payload + gross_weight)); };
   float cost_per_ton(float fuel_cost) {
     return(fuel_cost / (payload / 2000.0)); };
};



class driver {
protected:
   float hourly_pay;
public:
   void initialize(float pay) {hourly_pay = pay; };
   float cost_per_mile(void) {return(hourly_pay / 55.0); } ;
};



class driven_truck : public moving_van, public driver {
public:
   void initialize_all(float pl, float gw, float in_mpg, float pay)
     { payload = pl;
       gross_weight = gw;
       mpg = in_mpg;
       hourly_pay = pay; };
   float cost_per_full_day(float cost_of_gas) {
       return(8.0 * hourly_pay +
    8.0 * cost_of_gas * 55.0 / mpg); };
};



main()
{
driven_truck chuck_ford;


   chuck_ford.initialize_all(20000.0, 12000.0, 5.2, 12.50);


   cout 
M. Saqib: Saqib is Master-level Senior Software Engineer with over 14 years of experience in designing and developing large-scale software and web applications. He has more than eight years experience of leading software development teams. Saqib provides consultancy to develop software systems and web services for Fortune 500 companies. He has hands-on experience in C/C++ Java, JavaScript, PHP and .NET Technologies. Saqib owns and write contents on mycplus.com since 2004.
Related Post