Click to like/follow us on:
You have just graduated and employed in an organization where you will practice what you have studied in the higher institution, however, you where posted to the computing department in this organization. The first day you resumed work, you where asked as a matter of urgency by the director of  this department to write an algorithm that will request for the number of hours worked, pay rate using the age of a staff in the organization. The algorithm will calculate and display the pay as follows:
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...::

0 comments:

Leave a Reply

All Posts

Access all posts here!

Categories

Unordered List

Sample Text

Lists of Jobs in the United States

List of Courses & Outlines For UNN Students

Popular Posts

Like us on Facebook

Recent Posts

    Text Widget