ICT159 Foundations of Programming
Lab Practice 3
LEARNING OBJECTIVES
Understand the basic requirements of a selective algorithm.
Be able to construct a simple and efficient series of conditions in
order to solve
...
ICT159 Foundations of Programming
Lab Practice 3
LEARNING OBJECTIVES
Understand the basic requirements of a selective algorithm.
Be able to construct a simple and efficient series of conditions in
order to solve a selective problem.
Apply the nested if-else structure to solve a selective problem.
Understand how to select test data in order to maximise the
effectiveness of algorithm and program testing.
Learn how to identify when to use constants in your program in
order to simplify and enhance the readability of your code.
FOR THIS LAB YOU MUST SUBMIT…
Your algorithm from part 1.
Your test table from part 2.
Your source code and executable for part 3.
1. (Design/Problem Solving exercise 1)
Create an algorithm for a program that simulates the fines issued to
drivers based on speeds recorded by a police radar gun.
The algorithm should read the recorded automobile speed (in km/h) as an
integer and print the message “Speeding” if the speed exceeds 60 km/h or
“Not Speeding” if the speed 60 km/h or less.
The algorithm should then calculate the appropriate fine (if applicable). If
the speed is 5 km/h or less over this limit, only issue a warning. If the
speed is more than 5 and no more than 10 km/h above the limit, the fine
is $80. For a speed of more than 10 but no more than 20 km/h above the
limit, the fine is $150. For a speed of more than 20 km/h above the limit,
the fine is $500.
You should give some thought as to the type of data you are working
with before beginning to design your solution. You should also consider
what to do if a negative number is input. Speed cameras do not register
negative numbers, so they should not be accepted as input.
- 1 -ICT159 Foundations of Programming
Note: data type is assumed to be int (i.e. and integer); for the purpose of
this exercise, DO NOT use floating point numbers.
Also, 60 or less means the speed can be 60 but no more; this is not
speeding. Exceeds 60 means the speed is over 60 and therefore speeding.
This same logic applies when considering the other speed categories and
can be viewed as follows:
61-65 inclusive = warning
66-70 inclusive = $80
71-80 inclusive = $150
81 or more = $500
- 2 -ICT159 Foundations of Programming
2. (Design/Problem Solving exercise 2)
Please read the notes at the end of this worksheet before working on this
exercise; it discusses how to create and apply test data.
Use the test table template below and the test descriptions as hints to
define suitable test data to test your algorithm for question 1 and the
program you will write for question 3. You should enter values into the
last four columns for each test (i.e. row). Do not write the program yet!
Once you identify suitable inputs and have filled in that column, then you
should identify what outputs you expect. Read the information at the end
of this lab about selecting suitable test data.
Test
#
[Show More]