Home Segments Index Top Previous Next

531: Mainline

At this point, you have a working train-describing program, but you may decide to take another look at the for loop where displaying is done:

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 capacities: 
  train[n] -> display_capacity ( ); 
  // Terminate the line: 
  cout << endl; 
} 

This for loop works, but you may not like to have the actual displaying distributed all over the place in functions such as display_short_name and display_capacity. By bringing to one place all the output statements, you make them easier to control.