Quantcast
Channel: Learn Online Computer Language Programming
Viewing all articles
Browse latest Browse all 24

Learn C++ programming online free Chapter 7 - Programming exercise 3(1-2) Part

$
0
0
 Chapter 7 - Programming exercise 3
File format : CH07_1A.H.CPP,Save That.
#include "vehicle.hpp"

class truck : public vehicle {
   int passenger_load;
   float payload;
public:
   void init_truck(int how_many = 2, float max_load = 24000.0);
   float efficiency(void);
   int passengers(void);
   int total_weight(void);
};




// Result of execution
//
// (this file cannot be executed)



Chapter 7 - Programming exercise 3
File format : CH07_2B.CPP,Save That.
 
 
#include <ch07_3a.h>         // This is actually TRUCK.H

void truck::init_truck(int how_many = 2, float max_load = 24000.0)
{
   passenger_load = how_many;
   payload = max_load;
}


float truck::efficiency(void)
{
   return payload / (payload + get_weight());
}


int truck::passengers(void)
{
   return passenger_load;
}


int truck::total_weight(void)
{
   return (payload + get_weight());
}



// Result of execution
//
// (this file cannot be executed)

Viewing all articles
Browse latest Browse all 24

Trending Articles