240 likes | 327 Views
Chapter 3 - A Methodology for Program Development. Program Design. Demonstrates understanding of Specifications Answers the question WHAT? Less time Coding and Debugging Program more likely to perform correctly Provides the foundation for GOOD program code.
E N D
Program Design • Demonstrates understanding of Specifications • Answers the question WHAT? • Less time Coding and Debugging • Program more likely to perform correctly • Provides the foundation for GOOD program code
Tuition Billing General Specifications • Print a report showing each student’s tuition amount due • Amount due is the sum of tuition fees less any scholarship awards • Base tuition $ 200 per credit • Fees • If a Union Member Union Fee = $ 25 • Activity Fee - a sliding scale by number of credits • <= 6 Credits $ 25 • 7 - 12 Credit $ 50 • > 12 Credits $ 75
Tuition Billing General Specifications • Scholarship Amount awarded if GPA is > 2.5 • Print Grand totals of each amount Compute the Tuition due for Bill JonesA Union MemberEnrolled for 15 creditsGPA 3.2Scholarship amount $ 395
Tuition Due Tuition 15 * 200 = $ 3000 Union Member Fee $ 25 Activity Fee $ 75 ===== Subtotal $ 3100 Less Scholarship $ 395 ===== Amount Due $ 2705
Input Record Specifications 01 Student-Record. 05 Student-Name. 10 Last-Name Pic X(15). 10 Initials Pic X(2). 05 Credits Pic 9(2). 05 Union-Member Pic X. 05 Scholarship Pic 9(4). 05 GPA Pix 9v99.
ANY COBOL PROGRAM INITIALIZATION PROCESSING TERMINATION Figure 3.2 Overall COBOL Hierarchy Chart
Structured Development • Top - Down • Begin with generalization of function to be performed • Subdivided into less generalization of functions - at lower levels • Continue until lowest level of functions define a single understandable process
Tuition Billing Program 100-Prepare-Tuition-Report
Tuition Billing Program 100-Prepare-Tuition-Report 200-Initialize-Program 210-Process-Student-Records 220-Finalize-Program
Tuition Billing Program 100-Prepare-Tuition-Report 200-Initialize-Program 210-Process-Student-Records 220-Finalize-Program 900-Read- Student-File 300-Compute-Tuition 310-Compute- Fees 330-Compute- Balance-Due 350-Print- Detail-Line 900-Read- Student-File 320-Compute- Scholarship 340-Accumulate- Totals
Completeness • Provides for every function of as called for in the Program Specifications
CONDITION? A B A B (a) Sequence (b) Selection A A ENTRY B EXIT CONDITION? :: TRUE N (c) Iteration (d) Case FALSE Figure 3.4 The Building Blocks of Structured Programming
CONDITION? A C CONDITION2? B TRUE FALSE Figure 3.5 Sufficiency of the Basic Structures
Figure 3.6 Flowchart for Tuition Billing Program PROCESSSTUDENT START COMPUTETUITION OPENFILES COMPUTEUNION FEE READSTUDENTRECORD COMPUTEACTIVITYFEE COMPUTESCHOLARSHIP DATAREMAINS? PROCESSSTUDENT TRUE FALSE INCREMENTUNIVERSITYTOTALS WRITEUNIVERSITYTOTALS WRITEDETAILLINE CLOSEFILES READSTUDENTRECORD STOP STOP (b) Detail of PROCESS-STUDENT (a) Overall Flowchart
Statement AStatement B IF condition is true Statement AELSE Statement BENDIF DO WHILE condition is true Statement AENDDO DO CASE Case 1 is true Statement A Case 2 is true Statement B . . .ENDCASE (a) The Sequence Structure (b) The Selection Structure (c) The Iteration Structure (d) The Case Structure Figure 3.7 Pseudocode for Building Blocks
100-Prepare-Tuition-Billing-Report. Do 200-Initialize-Program. Do 210-Process-Student-Records until No More Data D0 220-Finalize-Program Stop 200-Initialize-Program. Open files Write heading line(s) Do 900-Read-Student-File 210-Process-Student-Records. Do 300-Compute-Tuition Do 310-Compute-Fees Do 320-Compute-Scholarship Do 330-Compute-Balance-Due Do 340-Accumulate-Totals Do 350-Print-Detail-Line Do 900-Read-Student-Fi;e 220-Finalize-Program. Write university totals Close files Stop run Figure 3.8 Pseudocode for Tuition Billing Program (b) Detailed pseudocode
300-Compute-Tuition. Compute tuition = 200 * credits 310-Compute-Fees. IF union member union fee = $25 ELSE union fee = 0 ENDIF DO CASE CASE credits <= 6 Activity fee = 25 CASE credits > 6 and <= 12 Activity fee = 50 CASE credits > 12 Activity fee = 75 ENDCASE 320-Compute-Scholarship. IF gpa > 2.5 Scholarship = Scholarship amount ELSE (no scholarship) Scholarship = 0 ENDIF Figure 3.8 Pseudocode for Tuition Billing Program (b) Detailed pseudocode
Figure 3.8 Pseudocode for Tuition Billing Program 330-Compute-Balance-Due. Compute bill = Tuition + Union fee + Activity fee - Scholarship 340-Accumulate-Totals Increment university totals 350-Print-Detail-Line. Write detail line 900-Read-Student-File. Read STUDENT-FILE at end indicate no more data
Statement A Statement B (a) The Sequence Structure Statement A Statement B Condition Condition + (b) The Selection Structure (0, End) Statement A (c) The Iteration Structure Figure 3.9Warnier-Orr Diagrams for Building Blocks
Open filesWrite-heading-lineRead-student-file(1) Compute-tuition (1) Compute-union-fee (1) Compute-activity-fee (1) Compute-scholarship (1) Compute-individual-bill (1) Increment-university-totals (1) Write-detail-line (1) Read-student-file (1) Tuition-Billing Program Process-record(0, End) Write-university-totals (1)Close filesStop run Figure 3.10Warnier-Orr Diagram for Tuition Billing Program
Last-minute panic Amount of testing Amount of testing Time Time (a) Traditional Mode (b) Top-Down Mode Figure 3.13Advantages of Top-Down Testing