Download presentation
Presentation is loading. Please wait.
Published byRosamund Dorsey Modified over 9 years ago
1
General Algorithms for Common Business Problems
2
Simple Program Design, Fourth Edition Chapter 10
Objectives In this chapter you will be able to: Provide general pseudocode algorithms to four common business applications. Topics covered are: Report generation with page break Single-level control break Multiple-level control break Sequential file update Simple Program Design, Fourth Edition Chapter 10
3
Simple Program Design, Fourth Edition Chapter 10
Program Structure The aim of this chapter is to present a number of general pseudocode solutions for typical programming problems This basic solution algorithm forms the framework for most commercial business programs It does not include processing for page headings, control breaks, total lines, or special calculations Examine the hierarchy chart and pseudocode shown on pages 161 and 162 of the textbook Simple Program Design, Fourth Edition Chapter 10
4
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 a predetermined number of detail lines have been printed Examine the typical report on page 162 of the textbook along with the hierarchy chart and pseudocode of the solution algorithm on pages 162 through 164 of the textbook Simple Program Design, Fourth Edition Chapter 10
5
Single-Level Control Break
A control break total line is a summary line for a group of records that contain the same record key There are two things you must consider when designing a control break program: The file to be processed must have been sorted into control field sequence Each time a record is read from the input file, the control field on the current record must be compared with the control field on the previous record Simple Program Design, Fourth Edition Chapter 10
6
Single-Level Control Break
A Hierarchy Chart (shown on page 165) All control break report programs will require the following variables: A variable named this_control_field which will hold the control field of the record just read A variable named prev_control_field which will hold the control field of the previous record One or more variables to accumulate the control break totals One or more variables to accumulate the report totals Simple Program Design, Fourth Edition Chapter 10
7
Single-Level Control Break
B Solution Algorithm (shown on page 166 and 167) There are four points in this mainline algorithm that are essential for a control break program to function correctly: Each time a new record is read from the file, the new control field is assigned to the variable this_control_field When the first record is read, the new control field is assigned to both the variables this_control_field and prev_control_field The variable prev_control_field is updated as soon as a change in the control field is detected After the end of the file has been detected, the module Print_control_total_line will print the control break totals for the last record or set of records Simple Program Design, Fourth Edition Chapter 10
8
Multiple-Level Control Break
Often reports are required to produce multiple-level control break totals The concepts that applied to a single-level control break program also apply to a multiple-level control break program The general solution algorithm that was developed for a single-level control break program can be extended by the addition of two new modules to incorporate a two-level control break A Hierarchy Chart (shown on page 169) Simple Program Design, Fourth Edition Chapter 10
9
Multiple-Level Control Break
B Solution Algorithm (shown on pages 170 through 172) The points to be noted in this mainline are: Each time a new record is read from the input file, the new control fields are assigned to the variables this_minor_control_field and this_major_control_field When the first record is read, the new control fields are assigned to both the current and previous control field variables After the end of the input file has been detected, the two modules Print_minor_control_totals and Print_major_control_totals will print control totals for the last minor control field record, or set of records, and the last major control field or set of records Simple Program Design, Fourth Edition Chapter 10
10
Sequential File Update
Sequential file updating involves updating a master file by applying update transactions on a transaction file Both files are sequential A new master file that incorporates the update transaction is produced A system flowchart of a sequential update program is illustrated on page 173 of the textbook Simple Program Design, Fourth Edition Chapter 10
11
Simple Program Design, Fourth Edition Chapter 10
System Concepts Master File A master file is a file that contains permanent and semi-permanent information about the data entities it contains Transaction File A transaction file contains all the data and activities that are included on the master file If the transaction file has been designed specifically to update a master file, there are usually three types of update transactions on this file Simple Program Design, Fourth Edition Chapter 10
12
Simple Program Design, Fourth Edition Chapter 10
System Concepts These are transactions to: Add a new record Update or change an existing record Delete an existing record Audit Report An audit report is a detailed list of all the transactions that were applied to the master file Error Report An error report is a detailed list of errors that occurred during the processing of the update Simple Program Design, Fourth Edition Chapter 10
13
Sequential Update Logic
Processing involves reading a record from each of the input files and comparing the keys of the two records As a result of this comparison, processing falls generally into three categories: If the key on the transaction record is less than the key on the old master record, the transaction is probably an add transaction If the key on the transaction record is equal to the key on the old master record, the transaction is probably an update or delete transaction If the key on the transaction record is greater than the key on the old master record, there is no matching transaction for that master record Simple Program Design, Fourth Edition Chapter 10
14
Sequential Update Logic
Sequential update programs also need to include logic that will handle multiple transaction records for the same master record, and the possibility of transaction records that are in error The types of transaction record errors that can occur are: An attempt to add a new master record when a record with that key already exists on the master file An attempt to update a master record when there is no record with that key on the master file An attempt to delete a master record when there is no record with that key on the master file An attempt to delete a master record when the current balance is not equal to zero Simple Program Design, Fourth Edition Chapter 10
15
Balance Line Algorithm
A good general solution algorithm written in pseudocode was presented by Barry Dwyer in a paper entitled ‘One More Time – How to Update a Master File’1 This algorithm has been referred to as the balance line algorithm It handles multiple transaction records for the one master record, as well as the possibility of transaction record errors 1 Barry Dwyer, ‘One More Time- How to Update a Master File’, Comm. ACM, Vol. 124, No. 1, January Simple Program Design, Fourth Edition Chapter 10
16
Balance Line Algorithm
A modularized version of the balance line algorithm is presented in this chapter A Hierarchy Chart (shown on page 176) B Solution Algorithm Refer to the mainline and subordinate modules shown on pages 176 through 179 of the textbook Simple Program Design, Fourth Edition Chapter 10
17
Simple Program Design, Fourth Edition Chapter 10
Summary The aim of this chapter was to develop general pseudocode algorithms to four common business applications The applications covered were: Report generation with page break Single-level control break Multiple-level control break Sequential file update Simple Program Design, Fourth Edition Chapter 10
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.