Home Segments Index Top Previous Next

117: Mainline

Still another virtue of procedure abstraction is that you easily can augment repetitive computations. For example, you have seen the floating-point version of box_car_volume defined this way:

double box_car_volume (double h, double w, double l) { 
  return h * w * l; 
} 

You easily can add a line that displays the volume every time that the volume is computed:

double box_car_volume (double h, double w, double l) {
  cout << "The volume is " << h * w * l << endl;  
  return h * w * l; 
} 

Thus, you do not need even to bother to find all the places where a volume is computed, because you need only to change the box_car_volume function's definition.