Home Segments Index Top Previous Next

154: Mainline

With volume redefined to operate on box_car objects—instead of on a height, width, and length combination—you can rewrite the program in Segment 151 as follows:

#include   
class box_car { 
  public: double height, width, length; 
}; 
double volume (box_car b) { 
  return b.height * b.width * b.length; 
} 
main ( ) { 
  box_car x; 
  x.height = 10.5; x.width = 9.5; x.length = 40.0; 
  cout << "The volume of the box_car is " 
       << volume (x) << endl; 
} 
--- Result --- 
The volume of the box_car is 3990