In the following program, a box_car
object is created, values are assigned to the member variables, and the
box_car
object's volume is computed by an ordinary
function named box_car_volume
.
#includeclass box_car { public: double height, width, length; }; double box_car_volume (double h, double w, double l) { return h * w * l; } main ( ) { box_car x; x.height = 10.5; x.width = 9.5; x.length = 40.0; cout << "The volume of the box_car is " << box_car_volume (x.height, x.width, x.length) << endl; } --- Result --- The volume of the box_car is 3990