CST 180 - Function Lab 6 (Choose One)

PART A:  Safest Driving Area Program
Write a program that uses functions and determines which of 5 geographic regions within a major city (north, south, east, west, and central) had the highest reported automobile accidents last year. It should have the following two functions, which are called by main().

  • int getNumAccidents() is passed the five regions as reference variables. It asks the user for the number of automobile accidents reported in each region during the last year, validates the input. It should be called once and collect input for all regions.
  • void findHighest() is passed the five accident totals. It determines which is the largest and prints the name of the region, along with its accident figure.

Input Validation: Do not accept an accident number that is less than 0.

Test Data:

North
South
East
West
Central
Run 1
17
12
14
-6, 6
8
Run 2
0
18
6
0
9
Run 3
12
21
9
11
16

You may want to use a main processing loop to enable multiple program runs. Have the user indicate when done by entering some value of your choosing.

Submit:

  • A single document with source code and screenshot of program execution.


PART B:  Lower Score Drop Program

Write a program that uses functions and calculates the average of a group of test scores, where the lowest score in the group is dropped. It should use the following functions:

  • void getScore() should ask the user for a test score, store in a reference parameter variable, and validate it. This function should be called by main() once for each of the five scores to be entered.
  • void calcAverage() should calculate and display the average of the four highest scores. This function should be called just once by main(), and should be passed the five scores.
  • int findLowest() should find and return the lowest of the five scores passed to it. It should be called by calcAverage, who uses the function to determine which of the five scores to drop.

Input Validation: Make sure test scores are between 0 and 100.

Test Data:

Score 1
Score 2
Score 3
Score 4
Score 5
Run 1
87 65 92 76 100
Run 2
75 102, 92 58 59 81
Run 3
-91, 91 94 88 90 78

Like before, you might want to incorporate a main processing loop to enable multiple runs.

Submit:

  • A single document with source code and screenshot of program execution.

 

Return to TOP

! You are using a version 4 browser or older. If you are experiencing any problems with scrolling, please reload the page.