Home Segments Index Top Previous Next

568: Mainline

Suppose that you decide that you want to decorate the capacity report—the one displayed by the analyze_train program—with a simple iconic train, such as the following:

[eng]-[box]-[box]-[tnk]-[cab] 

You could arrange for this display by amending the for loop that does displaying. As it stands, the for loop looks like this:

// Display short names and capacities:  
for (n = 0; n < car_count; ++n) { 
  cout << train[n] -> short_name ( ) 
       << "     " 
       << train[n] -> capacity ( ) 
       << endl; 
} 

As amended to display an iconic train representation, the for loop looks like this:

// Display icon for first car, no hyphen: 
cout << "[" << train[0] -> short_name ( ) << "]"; 
// Display icons for other cars, hyphen included: 
for (n = 1; n < car_count; ++n) { 
  cout << "-[" << train[n] -> short_name ( ); << "]"; 
}