understanding the mainline logical flow through a program (continued)
DESCRIPTION
Understanding the Mainline Logical Flow Through a Program (continued). Procedural program: one procedure follows another from beginning to end Mainline logic has three distinct parts: Housekeeping: steps to get ready Main loop: instructions executed for every input record - PowerPoint PPT PresentationTRANSCRIPT
![Page 1: Understanding the Mainline Logical Flow Through a Program (continued)](https://reader030.vdocuments.site/reader030/viewer/2022032805/56813279550346895d991247/html5/thumbnails/1.jpg)
Programming Logic and Design, Introductory, Fourth Edition 1
Understanding the Mainline Logical Flow Through a Program (continued)
• Procedural program: one procedure follows another from beginning to end
• Mainline logic has three distinct parts:– Housekeeping: steps to get ready– Main loop: instructions executed for every input record– End-of-job: steps taken at end of program
• Break the logic down into at least three modules
![Page 2: Understanding the Mainline Logical Flow Through a Program (continued)](https://reader030.vdocuments.site/reader030/viewer/2022032805/56813279550346895d991247/html5/thumbnails/2.jpg)
Programming Logic and Design, Introductory, Fourth Edition 2
Understanding the Mainline Logical Flow Through a Program (continued)
![Page 3: Understanding the Mainline Logical Flow Through a Program (continued)](https://reader030.vdocuments.site/reader030/viewer/2022032805/56813279550346895d991247/html5/thumbnails/3.jpg)
Programming Logic and Design, Introductory, Fourth Edition 3
Understanding the Mainline Logical Flow Through a Program (continued)
• Modularization of the program:– Keeps the job manageable– Allows multiple programmers to work simultaneously– Keeps the program structured
![Page 4: Understanding the Mainline Logical Flow Through a Program (continued)](https://reader030.vdocuments.site/reader030/viewer/2022032805/56813279550346895d991247/html5/thumbnails/4.jpg)
Programming Logic and Design, Introductory, Fourth Edition 4
Housekeeping Tasks
• Housekeeping tasks: include all steps that occur at the beginning of the program– Declare variables– Open files– Perform one-time-only tasks such as printing
headings– Read the first input record
![Page 5: Understanding the Mainline Logical Flow Through a Program (continued)](https://reader030.vdocuments.site/reader030/viewer/2022032805/56813279550346895d991247/html5/thumbnails/5.jpg)
Programming Logic and Design, Introductory, Fourth Edition 5
Declaring Variables
• Assign identifiers to memory locations
• Specify the name and data type
• Use meaningful names and follow standards
• Prefixes may be used to group related variables
• Declare a variable for each field in a data file
![Page 6: Understanding the Mainline Logical Flow Through a Program (continued)](https://reader030.vdocuments.site/reader030/viewer/2022032805/56813279550346895d991247/html5/thumbnails/6.jpg)
Programming Logic and Design, Introductory, Fourth Edition 6
Declaring Variables (continued)
• Initializing (or defining) the variable: providing an initial value
• Some languages provide default initial values
• Other languages leave variables with an unknown or garbage value
• Variables representing data fields in files do not need to be initialized
![Page 7: Understanding the Mainline Logical Flow Through a Program (continued)](https://reader030.vdocuments.site/reader030/viewer/2022032805/56813279550346895d991247/html5/thumbnails/7.jpg)
Programming Logic and Design, Introductory, Fourth Edition 7
Declaring Variables (continued)
• Can use variables for report headings• Embed any required spaces
• Heading can be printed using these variables
![Page 8: Understanding the Mainline Logical Flow Through a Program (continued)](https://reader030.vdocuments.site/reader030/viewer/2022032805/56813279550346895d991247/html5/thumbnails/8.jpg)
Programming Logic and Design, Introductory, Fourth Edition 8
Declaring Variables (continued)
• Local variables: declared within a module
• Global variables: declared at the beginning of the program, and used in all modules
• Annotation box: flowchart symbol containing notes
• Data Dictionary: list of variables used in a program, with their type, size, and description
![Page 9: Understanding the Mainline Logical Flow Through a Program (continued)](https://reader030.vdocuments.site/reader030/viewer/2022032805/56813279550346895d991247/html5/thumbnails/9.jpg)
Programming Logic and Design, Introductory, Fourth Edition 9
Opening Files
• Specify file name and path (location)
• Issue a file open command
• If no input file is opened, input may be accepted from the standard input device (e.g., keyboard)
• You must open both input and output files to be used, including printer output device
• If no output file is opened, standard output device (e.g., monitor) may be used
![Page 10: Understanding the Mainline Logical Flow Through a Program (continued)](https://reader030.vdocuments.site/reader030/viewer/2022032805/56813279550346895d991247/html5/thumbnails/10.jpg)
Programming Logic and Design, Introductory, Fourth Edition 10
Printing Headings
• Printing headings for reports usually is done at beginning of the program or possibly for each new page
![Page 11: Understanding the Mainline Logical Flow Through a Program (continued)](https://reader030.vdocuments.site/reader030/viewer/2022032805/56813279550346895d991247/html5/thumbnails/11.jpg)
Programming Logic and Design, Introductory, Fourth Edition 11
Reading an Input Record
• Reading the first input record is the last housekeeping task
• Interactive application: – Interacts with users via keyboard or mouse input– Program pauses when the read command is
executed until the user enters data• Delimiter: a character designated as a separator
between data values• Prompt: an output statement that asks the user to
enter specific data
![Page 12: Understanding the Mainline Logical Flow Through a Program (continued)](https://reader030.vdocuments.site/reader030/viewer/2022032805/56813279550346895d991247/html5/thumbnails/12.jpg)
Programming Logic and Design, Introductory, Fourth Edition 12
Reading the First Input Record (continued)
• Interactive input: (from a keyboard)
![Page 13: Understanding the Mainline Logical Flow Through a Program (continued)](https://reader030.vdocuments.site/reader030/viewer/2022032805/56813279550346895d991247/html5/thumbnails/13.jpg)
Programming Logic and Design, Introductory, Fourth Edition 13
Reading an Input Record
• Input from a data file:
![Page 14: Understanding the Mainline Logical Flow Through a Program (continued)](https://reader030.vdocuments.site/reader030/viewer/2022032805/56813279550346895d991247/html5/thumbnails/14.jpg)
Programming Logic and Design, Introductory, Fourth Edition 14
Checking for the End of the File
• After reading a file• For an interactive program, EOF may be determined
when:– User enters a predetermined sentinel value– User selects a screen option using a mouse
• For input from a file, the input device recognizes EOF• EOF may occur on the first read• If there is data, each record is processed before the
next read occurs
![Page 15: Understanding the Mainline Logical Flow Through a Program (continued)](https://reader030.vdocuments.site/reader030/viewer/2022032805/56813279550346895d991247/html5/thumbnails/15.jpg)
Programming Logic and Design, Introductory, Fourth Edition 15
Checking for End of File (continued)
![Page 16: Understanding the Mainline Logical Flow Through a Program (continued)](https://reader030.vdocuments.site/reader030/viewer/2022032805/56813279550346895d991247/html5/thumbnails/16.jpg)
Programming Logic and Design, Introductory, Fourth Edition 16
Modules, Subroutines, Procedures, Functions, or Methods
• Module: – Unit of code that performs one small task– Called a subroutine, procedure, function, or method
• Modularization: breaking a large program into modules
![Page 17: Understanding the Mainline Logical Flow Through a Program (continued)](https://reader030.vdocuments.site/reader030/viewer/2022032805/56813279550346895d991247/html5/thumbnails/17.jpg)
Programming Logic and Design, Introductory, Fourth Edition 17
Modules, Subroutines, Procedures, Functions, or Methods (continued)
• Advantages of modularization:– Provides abstraction– Allows multiple programmers to work simultaneously– Allows code reuse– Makes identifying structures easier
![Page 18: Understanding the Mainline Logical Flow Through a Program (continued)](https://reader030.vdocuments.site/reader030/viewer/2022032805/56813279550346895d991247/html5/thumbnails/18.jpg)
Programming Logic and Design, Introductory, Fourth Edition 18
Modularization Provides Abstraction
• Abstraction: – Focusing on important properties while ignoring non-
essential details– Avoids the low-level details and uses a high-level
approach– Makes complex tasks look simple
![Page 19: Understanding the Mainline Logical Flow Through a Program (continued)](https://reader030.vdocuments.site/reader030/viewer/2022032805/56813279550346895d991247/html5/thumbnails/19.jpg)
Programming Logic and Design, Introductory, Fourth Edition 19
Modularization Provides Abstraction (continued)
• A To-Do list
• with abstraction: without abstraction:
![Page 20: Understanding the Mainline Logical Flow Through a Program (continued)](https://reader030.vdocuments.site/reader030/viewer/2022032805/56813279550346895d991247/html5/thumbnails/20.jpg)
Programming Logic and Design, Introductory, Fourth Edition 20
Modularization Allows Multiple Programmers to Work on a Problem
• Large programming projects can be divided into modules
• Modules can be written by different programmers
• Development time is significantly reduced
![Page 21: Understanding the Mainline Logical Flow Through a Program (continued)](https://reader030.vdocuments.site/reader030/viewer/2022032805/56813279550346895d991247/html5/thumbnails/21.jpg)
Programming Logic and Design, Introductory, Fourth Edition 21
Modularization Allows You to Reuse Your Work
• Reusability: the ability to use modules in a variety of applications
• Reliability: assurance that a module has been tested and proven to function correctly
![Page 22: Understanding the Mainline Logical Flow Through a Program (continued)](https://reader030.vdocuments.site/reader030/viewer/2022032805/56813279550346895d991247/html5/thumbnails/22.jpg)
Programming Logic and Design, Introductory, Fourth Edition 22
Modularizing a Program
• Most programs contain a main module– Contains the mainline logic– Accesses other modules or subroutines
• Rules for module names used here:– Must be one word– Should be meaningful– Are followed by a set of parentheses
![Page 23: Understanding the Mainline Logical Flow Through a Program (continued)](https://reader030.vdocuments.site/reader030/viewer/2022032805/56813279550346895d991247/html5/thumbnails/23.jpg)
Programming Logic and Design, Introductory, Fourth Edition 23
Modularizing a Program (continued)
• Calling program (or calling module): one that uses another module
• Flowchart symbol for calling a module: a rectangle with bar across the top
• Flowchart for the module contains:– Module name in the start symbol– exit or return in the stop symbol
• When a module is called, logic transfers to the model
• When module ends, logic transfers back to the caller
![Page 24: Understanding the Mainline Logical Flow Through a Program (continued)](https://reader030.vdocuments.site/reader030/viewer/2022032805/56813279550346895d991247/html5/thumbnails/24.jpg)
Programming Logic and Design, Introductory, Fourth Edition 24
Modularizing a Program (continued)
![Page 25: Understanding the Mainline Logical Flow Through a Program (continued)](https://reader030.vdocuments.site/reader030/viewer/2022032805/56813279550346895d991247/html5/thumbnails/25.jpg)
Programming Logic and Design, Introductory, Fourth Edition 25
Modules Calling Other Modules
![Page 26: Understanding the Mainline Logical Flow Through a Program (continued)](https://reader030.vdocuments.site/reader030/viewer/2022032805/56813279550346895d991247/html5/thumbnails/26.jpg)
Programming Logic and Design, Introductory, Fourth Edition 26
Understanding Documentation
• Documentation: – All supporting material that goes with a program– Two major categories: for users and for programmers– Usually created by system analysts and/or tech writers– May be printed or electronic (Web or CD)
• End users: people who use computer programs
• Program Documentation:– Internal program documentation: comments within code– External program documentation: supporting paperwork
written before programming begins
![Page 27: Understanding the Mainline Logical Flow Through a Program (continued)](https://reader030.vdocuments.site/reader030/viewer/2022032805/56813279550346895d991247/html5/thumbnails/27.jpg)
Programming Logic and Design, Introductory, Fourth Edition 27
Completing the Documentation
• Program documentation may contain:– Output design– Input description– Flowcharts– Pseudocode– Program code listing
• User documentation may contain– Manuals– Instructional material– Operating instructions