20180728112849D1526 - Session 04 First Steps in Modularisation and General Algorithms For Common Business Problems L
20180728112849D1526 - Session 04 First Steps in Modularisation and General Algorithms For Common Business Problems L
Session 04
(Lecture)
Acknowledgement
Perform_initial_processing
8 print ‘CUSTOMER USAGE FIGURES’ heading
9 set total_Customer to zero
10 set total_amount_owing to zero
END
Calculate_amount_owing
11 IF usage <= 60 THEN
amount_owing = usage * $2.00
ELSE
amount_owing=(60*1.75)+((usage - 60)*$1.50)
ENDIF
12 add amount_owing to total_amount_owing
END
Example
E. Develop the pseudocode for each successive module
in the hierarchy chart
Print_customer_details
13 print customer_number, name, address,
gas_usage, amount_owing
14 add 1 to total_customers
END
Print_gas_totals
15 print total_customers
16 print total_amount_owing
END
Example
F. Desk Check the solution algorithm
• The desk checking of an algorithm with modules is
not different from the method developed for
previous examples
1. Create some valid input test data
2. List the output that the input data is expected
to produce
3. Use a desk check table to walk the data
through the mainline of the algorithm to
ensure that the expected output is achieved.
When a sub module is called, walk the data
through each line of that module as well and
then return to the calling module
Example
F. Desk Check the solution algorithm
1. Input data
three test cases will be used to test the algorithm
1,8 print
9,10 0 0
2 customer1 40
3 TRUE
4,11 $80.00
12 $80.00
5,13,14 print print print 1
6 customer2 61
3 TRUE
4,11 $106.50
12 $186.50
5,13,14 print print print 2
6 customer3 80
3 TRUE
4,11 $135.00
12 $321.50
5,13,14 print print print 3
6 EOF
3 FALSE
7,15,16 print print
Program Structure
Program Structure
• The general solution algorithm consisted of a
mainline module and three subordinate modules.
These are :
– An initial processing module, containing the steps
to be performed at the beginning of the
algorithm, before the loop begins
– A processing module inside the loop containing all
steps necessary to process one record or piece of
data
– A final processing module, containing the steps to
be performed at the end of the algorithm, outside
the loop
Hierarchy Chart
• The hierarchy chart looked like this
Report Generation with Page Break
Report generation
with page break
• Most reports require page heading lines,
column heading lines, detail lines and total
lines. Reports are also required to skip to a
new page after pre-determined number of
detail lines have been printed
Example
• A typical report might look like this :
CUSTOMER ACCOUNT
NUMBER CUSTOMER NAME CUSTOMER ADDRESS BALANCE
12121 Fresh's Boutique Mall of Jakarta $300.00
12122 Cutest's Boutique Jakarta Shops Center $400.00
Total Customers on File 150
Total customers with balance owing 100
Total Balance owing $5,000.00
Report generation
with page break
• Hierarchy Chart
– The general solution algorithm for processing a
sequential file can be extended by the addition of three
new modules to cater for these report requirements
these new modules are Print_page_heading,
Print_detail_line, and Accumulate_total_fields
Single Level Control Break
Single level control break
• A control break total line is a summary line
for a group of records that contain the
same record key. this record key is referred
as the control field.
• This control field is used to identify a record
or a group of records within a file. A control
break occurs each time there is a change in
value of the control field. Thus, control
break total lines are printed each time a
control break is detected
Single level control break
• The sample of single level control break
GOLDEN COMPUTER COMPANY