The following program is stripped down to a few essentials so as to illustrate the speed-up and argument-altering properties of call-by-reference parameters without the complexity involved in reading information and producing a report:
#include// Class definitions; container class includes percent_loaded // Define ordinary functions: double slow_floor_space_function (box_car b) { return b.width * b.length; } double fast_floor_space_function (box_car& b) { return b.width * b.length; } void defective_loading_function (box_car b) { b.percent_loaded = 100; return; } void working_loading_function (box_car& b) { b.percent_loaded = 100; return; } main ( ) { box_car typical_box_car; cout << " Slow Fast" << endl << "Area computations: " << slow_floor_space_function (typical_box_car) << " " << fast_floor_space_function (typical_box_car) << endl; typical_box_car.percent_loaded = 0; cout << " Percent Loaded" << endl; cout << "Before calling either loading function: " << typical_box_car.percent_loaded << endl; defective_loading_function (typical_box_car); cout << "After calling defective_loading_function: " << typical_box_car.percent_loaded << endl; working_loading_function (typical_box_car); cout << "After calling working_loading_function: " << typical_box_car.percent_loaded << endl; } --- Result --- Slow Fast Area computations: 380 380 Percent Loaded Before calling either loading function: 0 After calling defective_loading_function: 0 After calling working_loading_function: 100