Transcript FinalReview

Summary - 1
• Four major computer operations:
–
–
–
–
Input
Processing
Output
Storage
• Six programming phases:
–
–
–
–
–
–
Understand the problem
Plan the logic
Code the program
Translate the program to machine language
Test the program
Deploy the program
Programming Logic and Design, Fifth Edition, Comprehensive
1
Summary (continued)
• Data hierarchy:
–
–
–
–
–
Character
Field
Record
File
Database
• Flowchart: pictorial representation of program logic
• Variables: named memory locations that contain values
Programming Logic and Design, Fifth Edition, Comprehensive
2
Summary (continued)
• Testing a value involves making a decision
• Assignment statements: store a value into a variable
• Assignment operator: the equal (=) sign in most
languages
Programming Logic and Design, Fifth Edition, Comprehensive
3
Summary (continued)
• Two major data types: text (string) and numeric
• Procedural programming: focuses on actions performed
on data
• Object-oriented programming: focuses on representing
and manipulating objects
Programming Logic and Design, Fifth Edition, Comprehensive
4
Summary - 2
• Spaghetti code: snarled program logic
• Three basic structures: sequence, selection, loop
– Combined by stacking and nesting
• Priming read: statement that reads the first input data
record
• Structured techniques promote:
– clarity, professionalism, efficiency, and modularity
• Flowchart can be made structured by untangling
Programming Logic and Design, Fifth Edition, Comprehensive
5
Summary (continued)
• case structure: questions with multiple alternatives
• while loop: a pretest loop asks the question first
• while loop statements never execute if the answer is No
• do-while and do-until loops: post-test loops that ask
the question last
• do-while and do-until loop statements are always
executed at least once
– Post-test loop can be replaced by a sequence followed by a
while loop
Programming Logic and Design, Fifth Edition, Comprehensive
6
Summary - 3
• Documentation: all supporting material for a program
• Output documentation: includes report designs
• File description: details data types and lengths of each
field of data in the file
• User documentation: manuals and instructional materials,
and operating instructions
• Modules: small, reasonable units of code that provide
reusability ( perform a specific task )
– subroutines, procedures, functions, methods
Programming Logic and Design, Fifth Edition, Comprehensive
7
Summary (continued)
• Modularization:
– Provides abstraction
– Allows multiple programmers to work on a problem
– Makes it easy to reuse work and identify structures
• Modules can call other modules
– Flowchart symbol is a rectangle with a bar across the top
• Variable declarations define the name and type of the data
to be stored
• Hierarchy chart illustrates modules’ relationships
Programming Logic and Design, Fifth Edition, Comprehensive
8
Summary (continued)
• Common structure for procedural programs:
– Housekeeping tasks
– Main loop
– End-of-job tasks
• Hierarchy chart illustrates modules’ relationships
• As programs become larger, need for good planning
increases
– Store program components in separate files
– Use meaningful names
– Avoid confusing line breaks, long statements
Programming Logic and Design, Fifth Edition, Comprehensive
9
Summary - 4
• Decisions involve evaluating Boolean expressions
• Use relational operators to compare values
• AND decision requires that both conditions be true to
produce a true result
• In an AND decision, first ask the question that is less likely to
be true
• OR decision requires that either of the conditions be true to
produce a true result
Programming Logic and Design, Fifth Edition, Comprehensive
10
Summary (continued)
• In an OR decision, first ask the question that is more likely to be
true
• For a range check, make comparisons with the highest or lowest
values in each range
• Eliminate unnecessary or previously answered questions
• Case structure allows a series of alternative actions based on the
value in a single variable
• Decision table aids in program design analysis to manage
multiple conditions and decisions
Programming Logic and Design, Fifth Edition, Comprehensive
11
Summary - 5
• When using a loop, write one set of instructions that
operates on multiple, separate data
• Three steps must occur in every loop:
– Initialize loop control variable
– Compare variable to some value
– Alter the variable that controls the loop
• Nested loops: loops within loops
• Nested loops maintain two individual loop control variables
– Alter each at the appropriate time
Programming Logic and Design, Fifth Edition, Comprehensive
12
Summary (continued)
• Common mistakes made by programmers:
–
–
–
–
Neglecting to initialize loop control variable
Neglecting to alter loop control variable
Using wrong comparison with loop control variable
Including statements inside the loop that belong outside
the loop
• Most computer languages support a for statement
• for loop used with definite loops
– When number of iterations is known
Programming Logic and Design, Fifth Edition, Comprehensive
13
Summary (continued)
• for loop automatically:
– Initializes
– Evaluates
– Increments
• Use posttest loop when loop body must execute at least
one time
– Control variable evaluated after loop body executes
Programming Logic and Design, Fifth Edition, Comprehensive
14
Summary (continued)
• Characteristics of all structured loops:
– Loop-controlling question provides entry or exit from
repeating structure
– Loop-controlling question provides the only entry or exit
from repeating structure
• Accumulator: variable that gathers values
• Loops used to ensure user data is valid by reprompting
the user
Programming Logic and Design, Fifth Edition, Comprehensive
15
Summary - 6
• Array: series or list of variables in memory
– Same name and type
– Different subscript
• Use a variable as a subscript to the array to replace multiple
nested decisions
• Declare and initialize all elements in an array with a single
statement
• Initialize array values within an initialization loop
• Some array values determined during program execution
– Other arrays have hard-coded values
Programming Logic and Design, Fifth Edition, Comprehensive
16
Summary (continued)
• Search an array:
– Initialize the subscript
– Test each array element value in a loop
– Set a flag when a match is found
• Parallel arrays: each element in one array is associated
with the element in second array
– Elements have same relative position
• For range comparisons, store either the low- or highend value of each range
Programming Logic and Design, Fifth Edition, Comprehensive
17
Summary (continued)
• Access data in an array
– Use subscript containing a value that accesses memory
occupied by the array
• Subscript is out of bounds if not within defined range of
acceptable subscripts
• for loop convenient tool for working with arrays
– Process each element of an array from beginning to end
Programming Logic and Design, Fifth Edition, Comprehensive
18
Summary - 7
• Method contains statements to carry out a task
• Variables and constants declared in a method only have
scope in that method
• Calling method sends argument to called method
– Multiple arguments: comma-separated list in header
• Method has a return type or void
Programming Logic and Design, Fifth Edition, Comprehensive
19
Summary (continued)
• All modern programming languages have prewritten
methods
• IPO chart: identifies and categorizes each item
pertaining to input, processing, or output
• Strive to achieve loose coupling and high cohesion
Programming Logic and Design, Fifth Edition, Comprehensive
20
Summary - 8
• Control break:
– a change in a variable’s value causes special actions to
occur
• Control break field:
– holds data from a previous record to compare to the
current record
• Control data can be used in a heading or footer
• Control break report print summary lines and optionally
detail lines
Programming Logic and Design, Fifth Edition, Comprehensive
21
Summary (continued)
• For multiple-level control breaks, test for a major-level
break before a minor-level break
• In a control break, check if lower-level breaks need to
be processed
• Page breaks can be handled based on line counters
Programming Logic and Design, Fifth Edition, Comprehensive
22