Home Segments Index Top Previous Next

118: Mainline

Another virtue of procedure abstraction is that you easily can improve how a computation is done. You might decide, for example, that it is wasteful for your box_car_volume function to multiply out height, width, and length twice. Accordingly, you might decide to do the computation just once, using a variable, named result, to hold on to the value:

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

Again, you do not need to bother to find all the places where the volume is computed using the box_car_volume function; you need only to change the box_car_volume function's definition.