If the age of a staff is less than 20, 2/3 of the hourly pay rate will apply; otherwise the normal pay rate will apply.
Premise:
Here
our algorithm will be selective. Why? So that we can have the room to
filter some age group as the question required.Let’s jump to the solution and see how it goes. Hey stay back, first pick a rough paper and a pencil an give it a try. When you have finished then check the solution below.
Solution:
Major Steps
1. Request Data
2. Calculate pay
3. Display pay
Stepwise Refinement
1. Request Data
1.1 Request age
1.2 Request hours
1.3 Request hourlyRate
2. Calculate pay
2.1 If age < 20 THEN
2.1.1 pay = 2/3 * hourlyRate * hours
Else
2.1.2 pay = hourlyRate * hours
3. Display pay
Explanation/Discussion:
Having requested for the age, hours worked and
hourly rate of a certain staff in this origination, Step 2.1 will now
test if the age of the staff is less than 20. If the test is true; that
the age of the staff is less than 20; then step 2.1.1 will execute, by
paying the worker 2/3 of the hourly pay.Suppose during the test, (in step 2.1) that the age of the staff is not less than 20, step 2.1.1 will not executed/followed. The step that will be executed is step 2.1.2. Why? Because the age of the staff is greater than 20, therefore making step 2.1 to be false.
This algorithm belong to the class of algorithm called Selective control structure algorithm.
Test:
The test is as shown in the tables below. Table 1 and 2 below make use of 17 and 20 years as the age of the staff respectively.Table 1.
Variable
|
Result/Information/Data
|
Request age
|
17
|
Request hours
|
2
|
Request hourlyRate
|
100
|
Is age < 20:? “Is 17 < 20”?
|
yes
|
pay
|
2/3 * 100 * 2
|
Display pay
|
133.33
|
Table 2.
Variable
|
Result/Information/Data
|
Request age
|
20
|
Request hours
|
2
|
Request hourlyRate
|
100
|
Is age < 20? “ Is 20 < 20”?
|
no
|
pay
|
100 * 2
|
Display pay
|
200
|
SHARE THIS POST WITH YOUR FRIENDS...::
Tweet
0 comments:
Leave a Reply