Example - Functions

Programming project #6 from Chapter 3 of the book

Problem

Four track stars have entered the mile race at the Penn Relays. Write a program that scans in the race time in minutes (minutes) and seconds (seconds) for a runner, and computes and displays the speed in feet per second (fps) and meters per second (mps). Write and call a function that displays instructions to the user. Run the program for each star's data.

MinutesSeconds
352.83
359.83
400.03
416.22

Hint: There are 5,280 feet in one mile, and one kilometer equals 3,282 feet.

Analysis

Structure Chart

Inputs:

Outputs:

Formulas:

Design

Algorithm:

  1. Get the input from the user
  2. Convert input time to common unit (seconds)
  3. Calculate FPS
    1. Calculate number of feet in race distance
    2. Divide race distance in feet by time in seconds to get feet per second
  4. Calculate MPS
    1. Convert race distance to meters
      1. Convert miles to feet
      2. Convert feet to kms
      3. Convert kms to m
    2. Divide race distance in meters by time in seconds to get meters per second
  5. Print out both results

NOTE: this algorithm is for one racer only. It is to be applied 4 times, once for each racer.

Implementation

Download


Back
Last updated: 9:44pm, January 22nd, 2017