Question: 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

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 an input. Speed cameras do not register negative numbers, so they should not be accepted as input.

Note: data type is assumed to be int (i.e. an 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. (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 #

Test Description

Inputs

Expected

Outputs

Algorithm Outputs

Program

Success/Failure

1

Not speeding but very close.

2

Speeding but only just (a warning).

3

Still speeding, but only just (a warning).

4

$80 fine, but only just.

5

Still an $80 fine, but only just.

6

$150 fine, but only just.

7

Still a $150 fine but only just.

8

$500 fine, but only just.

9

Null input

10

Zero input

Test #

Test Description

Inputs

Expected

Outputs

Algorithm Outputs

Program

Success/Failure

11

Negative speed (this has no meaning, but needs testing)

12

Invalid input

IMPORTANT:

Once the program has been written you should apply the test values from your test table above to your program and compare the actual results against your predicted results to verify that the program works correctly. Note that this only applies for tests 1-10.

IMPORTANT NOTE:

Test data and applying the test values to your program accounts for a quarter of your marks in the assignments.

3. (Programming exercise)

Implement your algorithm from question 1 into a C program. When developing your program pay particular attention to the use of constant values in your program. Identify what values for this problem should be constants and define them using the const keyword. Ideally you should find that you have very few actual numbers (called literal values) in your program apart from when defining constants. (The obvious exception to this is the use of zero to initialize variables etc.)

Run the program and test it by applying the test data from your test table, and fill in the remainder of the test table (i.e. last column).

4. Write a simple program that reads in an integer between 1 and 7 inclusive and prints out the corresponding day of the week, assuming Monday is 1, Tuesday is 2, etc. You should use a switch-case statement. Provide a default case for when the entered number is outside the required range.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!