cpts121-3-1 - CptS 121 Spring 09 Lecture 3-1 HK Chapter 3:...

Info iconThis preview shows pages 1–6. Sign up to view the full content.

View Full Document Right Arrow Icon
1 CptS 121 L3-1 – 9/9/09 Prof. Chris Hundhausen CptS 121 Spring ‘09 Lecture 3-1 HK Chapter 3: Functions Lecture Outline I. Another Example II. Test Drivers III. Common Errors
Background image of page 1

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

View Full DocumentRight Arrow Icon
2 CptS 121 L3-1 – 9/9/09 Prof. Chris Hundhausen Another Example Problem Statement: Vehicles crossing the Hiawatha bridge must pay a toll. Write a tollbooth application that computes a vehicle's toll. A vehicle is charged $1.00 per axle, plus a surcharge based on its weight. The surcharge is $.50 per ton or fraction thereof. Write a program that computes the tolls of three vehicles crossing the bridge. You should prompt the user for the name of the file containing the data on the three vehicles. Read in the data from that file, and display the toll that is due for each vehicle. Note that one ton is equivalent to 2000 pounds. Inputs: infile_name num_axles weight Outputs toll_due Relevant formula: toll = (num_axles * 1.00) + (0.5 * ceil(weight/2000.0))
Background image of page 2
3 CptS 121 L3-1 – 9/9/09 Prof. Chris Hundhausen Another Example (cont.) Initial algorithm Get name of the file containing the vehicle data and open the file Compute the tolls of the three vehicles Display the results Refined algorithm Get the name of the file containing the vehicle data and open the file Read in the number of axles and weight of each of the three vehicles Compute the tolls of the three vehicles toll = (num_axles * 1.00) + (0.5 * ceil(weight/2000.0)) Display the results
Background image of page 3

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

View Full DocumentRight Arrow Icon
4 CptS 121 L3-1 – 9/9/09 Prof. Chris Hundhausen Another Example (cont.) Structure chart Compute tolls of three vehicles Get the file name and open the file Read data from file Compute toll get_and_open_file() read_num_axles() read_weight() compute_toll() Display results display_toll()
Background image of page 4
5 CptS 121 L3-1 – 9/9/09 Prof. Chris Hundhausen Another Example (cont.) Implementation /* * Computes the tolls of three vehicles. */ #include <stdio.h> /* printf, scanf defs */
Background image of page 5

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

View Full DocumentRight Arrow Icon
Image of page 6
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 01/25/2011 for the course CPTS 121 taught by Professor Hundhaus during the Spring '09 term at Washington State University .

Page1 / 18

cpts121-3-1 - CptS 121 Spring 09 Lecture 3-1 HK Chapter 3:...

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

View Full Document Right Arrow Icon
Ask a homework question - tutors are online