{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

SOLUTION_5

# SOLUTION_5 - CS 31 Introduction to Computer Science I UCLA...

This preview shows pages 1–3. Sign up to view the full content.

CS 31: Introduction to Computer Science I: Winter 2009: Project 5 Solution Page 1 // UCLA Winter 2009 // CS 31 Project 5: C Strings // John A. Rohr // February 20, 2009 // // // The Amtrak Southwest Chief railroad train runs daily between // Chicago and Los Angeles with several intermediate stops. // The train fare between stops depends on the distance between // the stops and the number of intermediate stops. The total fare // is the sum of the fares for each separate leg of the trip, // reduced by one percent for each intermediate stop, not counting // the origin or destination. // // The program computes the distance and cost of trips between // origin stations and destination stations and display the results. // // A file is available that specifies the initial station name on the first // line and the station data for all remaining stations on the route in order // of the stations. Each line specifies a station name followed by a dollar // sign separator followed by an integer dollar cost followed by an integer // distance in miles. // Input to the program consists of an origin station and a destination // station. Empty lines and comment lines may appear anywhere in the input // for readability. Comment lines have an asterisk ('*') in the first position. // Empty lines and comment lines in the input are displayed but not processed. // // A title followed by a blank line is displayed at the beginning and // a blank line and a termination message at the end. // // All numerical data and computation is integer only. // // All strings are C Strings. // // The getline function in the iostream class is used to read input lines. // Each input line is read into a single C String. // // Each output line is written as a single C String with one endline. // // All station data is on the file StationData.In. // // All origin and destination station input is read from the file File5.In // if it can be opened. Otherwise all the origin and destination station // input is read from the keyboard. When an origin station or destination // station input line consists of only the letter 'Q' or 'q' or the // end of input is reached, terminate the program with output of a blank // line and a termination message. // // All output is written to the console and the file File5.Out if it can be // opened. Otherwise all output is written to the console only. // //

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
CS 31: Introduction to Computer Science I: Winter 2009: Project 5 Solution Page 2 // Example Station Data File // // Los Angeles CA // San Bernardino CA \$ 65 72 // Barstow CA \$ 75 84 // Kingman AZ \$ 200 236 // Flagstaff AZ \$ 140 173 // Albuquerque NM \$ 320 359 // Las Vegas NM \$ 90 132 // Dodge City KS \$ 175 418 // Topeka KS \$ 222 279 // Kansas City MO \$ 50 66 // Galesburg IL \$ 210 275 // Chicago IL \$ 148 162 // // // Example Input File // // <Empty Line>
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

### Page1 / 34

SOLUTION_5 - CS 31 Introduction to Computer Science I UCLA...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document
Ask a homework question - tutors are online