![]() |
![]() |
![]() |
![]() |
![]() |
|
Because you have told C++ that the capacity function
returns a floating-point number, C++ can determine how to
handle capacity in output statements. Accordingly, you can
rewrite the for loop as follows:
for (n = 0; n < car_count; ++n) {
// Display short name, such as eng, box, tnk, or cab:
train[n] -> display_short_name ( );
// Display spaces:
cout << " ";
// Display load capacity, and terminate the line:
cout << train[n] -> capacity ( ) << endl;
}