itp 100 l.
Download
Skip this Video
Loading SlideShow in 5 Seconds..
ITP 100 PowerPoint Presentation
Download Presentation
ITP 100

Loading in 2 Seconds...

play fullscreen
1 / 122

ITP 100 - PowerPoint PPT Presentation


  • 236 Views
  • Uploaded on

ITP 100 . ITP 100 SOFTWARE DESIGN UNDERSTANDING STRUCTURE and PROGRAMMING LANGUAGES . Programming Logic and Design Comprehensive by Joyce Farrell. Chapter 2 Understanding Structure. Objectives. Learn about the features of unstructured spaghetti code

loader
I am the owner, or an agent authorized to act on behalf of the owner, of the copyrighted work described.
capcha
Download Presentation

PowerPoint Slideshow about 'ITP 100' - dyre


An Image/Link below is provided (as is) to download presentation

Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.


- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript
itp 100
ITP 100

ITP 100 SOFTWARE DESIGN

UNDERSTANDING STRUCTURE

and

PROGRAMMING LANGUAGES

Programming Logic and Design, Seventh Edition, Comprehensive

programming logic and design comprehensive by joyce farrell

Programming Logic and DesignComprehensiveby Joyce Farrell

Chapter 2

Understanding Structure

Programming Logic and Design, Seventh Edition, Comprehensive

objectives
Objectives

Learn about the features of unstructured spaghetti code

Understand the three basic structures: sequence, selection, and loop

Use a priming read

Appreciate the need for structure

Recognize structure

Learn about three special structures: case, do-while, and do-until

Programming Logic and Design, Fifth Edition, Comprehensive

Programming Logic and Design, Seventh Edition, Comprehensive

3

understanding unstructured spaghetti code
Understanding Unstructured (Spaghetti) Code

Spaghetticode: logically snarled program statements

Can be the result of poor program design

Spaghetti code programs often work, but are difficult to read and maintain

Convoluted logic usually requires more code

Programming Logic and Design, Fifth Edition, Comprehensive

Programming Logic and Design, Seventh Edition, Comprehensive

4

understanding unstructured spaghetti code continued
Understanding Unstructured Spaghetti Code (continued)

Example: College Admissions

Admit students who score >= 90 on admissions test if upper 75 percent of high-school graduating class

Admit students who score >= 80 on test if upper 50 percent of high-school graduating class

Admit students who score >= 70 on admission test if upper 25 percent of high-school graduating class

Programming Logic and Design, Fifth Edition, Comprehensive

Programming Logic and Design, Seventh Edition, Comprehensive

5

understanding unstructured spaghetti code continued6
Understanding Unstructured Spaghetti Code (continued)

Figure 2-2 Spaghetti code example

Programming Logic and Design, Fifth Edition, Comprehensive

Programming Logic and Design, Seventh Edition, Comprehensive

6

understanding the 3 basic structures
Understanding the 3 Basic Structures

Structure: basic unit of programming logic

Any program can be constructed from only three basic types of structures

Sequence

Perform actions in order

No branching or skipping any task

Selection (decision) IF-THEN-ELSE

Ask a question, take one of two actions

Dual-alternative or single-alternative

Loop (iteration)

Repeat actions based on answer to a question

Programming Logic and Design, Fifth Edition, Comprehensive

Programming Logic and Design, Seventh Edition, Comprehensive

7

understanding the three basic control structures cont d
Understanding the Three Basic Control Structures (cont’d)

Sequence structure

Figure 2-3 Sequence structure

Programming Logic and Design, Fifth Edition, Comprehensive

Programming Logic and Design, Seventh Edition, Comprehensive

8

understanding the three basic structures continued
Understanding the Three Basic Structures (continued)

Selection structure (IF-THEN-ELSE)

Figure 2-4 Selection structure

Programming Logic and Design, Fifth Edition, Comprehensive

Programming Logic and Design, Seventh Edition, Comprehensive

9

understanding the three basic structures continued10
Understanding the Three Basic Structures (continued)

Dual-alternative if: contains two alternatives

if someCondition is true then

do oneProcess

else

do theOtherProcess

Programming Logic and Design, Fifth Edition, Comprehensive

Programming Logic and Design, Seventh Edition, Comprehensive

10

understanding the three basic structures continued11
Understanding the Three Basic Structures (continued)

Single-alternative if: contains one alternative

Figure 2-5 Single-alternative selection structure

Programming Logic and Design, Fifth Edition, Comprehensive

Programming Logic and Design, Seventh Edition, Comprehensive

11

understanding the three basic structures continued12
Understanding the Three Basic Structures (continued)

Single-alternative if

Else clause is not required

Null case: situation where nothing is done

if employee belongs to dentalPlan then

deduct $40 from employeeGrossPay

Programming Logic and Design, Fifth Edition, Comprehensive

Programming Logic and Design, Seventh Edition, Comprehensive

12

understanding the three basic structures continued13
Understanding the Three Basic Structures (continued)

Loop structure (repetition or iteration)

Repeats a set of actions based on the answer to a question

Also called repetition or iteration

Question is asked first in the most common form of loop

Figure 2-6 Loop structure

Programming Logic and Design, Fifth Edition, Comprehensive

Programming Logic and Design, Seventh Edition, Comprehensive

13

understanding the three basic structures continued14
Understanding the Three Basic Structures (continued)

Loop structure

while testCondition continues to be true

do someProcess

while quantityInInventory remains low

continue to orderItems

Programming Logic and Design, Fifth Edition, Comprehensive

Programming Logic and Design, Seventh Edition, Comprehensive

14

understanding the three basic structures continued15
Understanding the Three Basic Structures (continued)

All logic problems can be solved using only these three structures

Structures can be combined in an infinite number of ways

Stacking: attaching structures end-to-end

End-structure statements: indicate the end of a structure

Theendifstatement ends an if-then-else structure

Theendwhile ends a loop structure

Programming Logic and Design, Fifth Edition, Comprehensive

Programming Logic and Design, Seventh Edition, Comprehensive

15

understanding the three basic structures continued16
Understanding the Three Basic Structures (continued)

Figure 2-7 Structured flowchart and pseudocode

Programming Logic and Design, Fifth Edition, Comprehensive

Programming Logic and Design, Seventh Edition, Comprehensive

16

understanding the three basic structures continued17
Understanding the Three Basic Structures (continued)

Any individual task or step in a structure can be replaced by a structure

Nesting: placing one structure within another

Indent the nested structure’s statements

Block: group of statements that execute as a single unit

Programming Logic and Design, Fifth Edition, Comprehensive

Programming Logic and Design, Seventh Edition, Comprehensive

17

understanding the three basic structures continued18
Understanding the Three Basic Structures (continued)

Figure 2-8 Flowchart and pseudocode showing a sequence nested within a selection

Programming Logic and Design, Fifth Edition, Comprehensive

Programming Logic and Design, Seventh Edition, Comprehensive

18

understanding the three basic structures continued19
Understanding the Three Basic Structures (continued)

Figure 2-9 Selection in a sequence within a selection

Programming Logic and Design, Fifth Edition, Comprehensive

Programming Logic and Design, Seventh Edition, Comprehensive

19

understanding the three basic structures continued20
Understanding the Three Basic Structures (continued)

Figure 2-10 Flowchart and pseudocode for loop within selection within sequence within selection

Programming Logic and Design, Fifth Edition, Comprehensive

Programming Logic and Design, Seventh Edition, Comprehensive

20

understanding the three basic structures continued21
Understanding the Three Basic Structures (continued)

Each structure has one entry and one exit point

Structures attach to others only at entry or exit points

Figure 2-11 The three structures

Programming Logic and Design, Fifth Edition, Comprehensive

Programming Logic and Design, Seventh Edition, Comprehensive

21

using the priming read
Using the Priming Read

Priming read (or priming input):

Reads the first input data record before the loop

The loop that follows reads the rest of the records

Helps keep the program structured

Analyze a flowchart for structure one step at a time

Watch for unstructured loops that do not follow this order:

First ask a question

Take action based on the answer

Return to ask the question again

Programming Logic and Design, Fifth Edition, Comprehensive

Programming Logic and Design, Seventh Edition, Comprehensive

22

using the priming read continued
Using the Priming Read (continued)

Unstructured loop

Figure 2-12 Unstructured flowchart of a number-doubling program

Programming Logic and Design, Fifth Edition, Comprehensive

Programming Logic and Design, Seventh Edition, Comprehensive

23

using the priming read continued24
Using the Priming Read (continued)

Structured but nonfunctional loop

Figure 2-15 Structured, but nonfunctional, flowchart of number-doubling problem

Programming Logic and Design, Fifth Edition, Comprehensive

Programming Logic and Design, Seventh Edition, Comprehensive

24

using the priming read continued25
Using the Priming Read (continued)

Functional, but nonstructured loop

Figure 2-16 Functional, but nonstructured, flowchart

Programming Logic and Design, Fifth Edition, Comprehensive

Programming Logic and Design, Seventh Edition, Comprehensive

25

using the priming read continued26
Using the Priming Read (continued)

Functional and structured loop (Best !)

Figure 2-17 Functional, structured flowchart and pseudocode for the number-doubling problem

Programming Logic and Design, Fifth Edition, Comprehensive

Programming Logic and Design, Seventh Edition, Comprehensive

26

using the priming read continued27
Using the Priming Read (continued)

Priming read sets up the process so the loop can be structured

To analyze a flowchart’s structure, try writing pseudocode for it

DoubleNumber

read inputNumber

while not at eof

calculatedAnswer = inputNumber * 2

print calculatedAnswer

read inputNumber

end while

End DoubleNumber

Programming Logic and Design, Fifth Edition, Comprehensive

Programming Logic and Design, Seventh Edition, Comprehensive

27

using the priming read continued28
Using the Priming Read (continued)

What is wrong with this design? (It should read first, then check for an EOF)

Figure 2-18 Structured but incorrect solution to the number-doubling problem

Programming Logic and Design, Fifth Edition, Comprehensive

Programming Logic and Design, Seventh Edition, Comprehensive

28

understanding the reasons for structure
Understanding the Reasons for Structure

Provides clarity

Professionalism

Efficiency

Ease of maintenance

Supports modularity

Programming Logic and Design, Fifth Edition, Comprehensive

Programming Logic and Design, Seventh Edition, Comprehensive

29

recognizing structure
Recognizing Structure

Any set of instructions can be expressed in structured format

Any task to which you can apply rules can be expressed logically using sequence, selection, loop

It can be difficult to detect whether a flowchart is structured

Programming Logic and Design, Fifth Edition, Comprehensive

Programming Logic and Design, Seventh Edition, Comprehensive

30

slide31

Recognizing Structure (continued)

  • Is this flowchart structured?

Figure 2-22 Example 2

Programming Logic and Design, Fifth Edition, Comprehensive

Programming Logic and Design, Seventh Edition, Comprehensive

31

recognizing structure continued
Recognizing Structure (continued)

Is this flowchart structured?

Figure 2-23 Example 3

Programming Logic and Design, Fifth Edition, Comprehensive

Programming Logic and Design, Seventh Edition, Comprehensive

32

recognizing structure continued33
Recognizing Structure (continued)

Single process like A is part of an unacceptable structure

At least the beginning of a sequence structure

Figure 2-24 Untangling Example 3, first step

Programming Logic and Design, Fifth Edition, Comprehensive

Programming Logic and Design, Seventh Edition, Comprehensive

33

recognizing structure continued34
Recognizing Structure (continued)

B begins a selection structure

Sequences never have decisions in them

Logic never returns to B

Figure 2-25 Untangling Example 3, second step

Programming Logic and Design, Fifth Edition, Comprehensive

Programming Logic and Design, Seventh Edition, Comprehensive

34

recognizing structure continued35
Recognizing Structure (continued)

Pull up on the flowline from the left side of B

Figure 2-26 Untangling Example 3, third step

Programming Logic and Design, Fifth Edition, Comprehensive

Programming Logic and Design, Seventh Edition, Comprehensive

35

recognizing structure continued36
Recognizing Structure (continued)

Next, pull up the flowline on the right side of B

Figure 2-27 Untangling Example 3, fourth step

Programming Logic and Design, Fifth Edition, Comprehensive

Programming Logic and Design, Seventh Edition, Comprehensive

36

recognizing structure continued37
Recognizing Structure (continued)

Pull up the flowline on the left side of D and untangle it from the B selection by repeating C

Figure 2-28 Untangling Example 3, fifth step

Programming Logic and Design, Fifth Edition, Comprehensive

Programming Logic and Design, Seventh Edition, Comprehensive

37

recognizing structure continued38
Recognizing Structure (continued)

Now pull up the flowline on the right side of D

Figure 2-29 Untangling Example 3, sixth step

Programming Logic and Design, Fifth Edition, Comprehensive

Programming Logic and Design, Seventh Edition, Comprehensive

38

recognizing structure continued39
Recognizing Structure (continued)

Bring together the loose ends of D and of B

Figure 2-30 Finished flowchart and pseudocode for untangling Example 3

Programming Logic and Design, Fifth Edition, Comprehensive

Programming Logic and Design, Seventh Edition, Comprehensive

39

three special structures case do while and do until
Three Special Structures – CASE, DO-WHILE, and DO-UNTIL

Many languages allow three additional structures:

Thecase structure

The do-while structure

The do-until structure

CASE Structure:

Decisions with more than two alternatives

Tests a variable against a series of values and takes action based on a match

Nested if-then-else statements will do what a case structure does

Programming Logic and Design, Fifth Edition, Comprehensive

Programming Logic and Design, Seventh Edition, Comprehensive

40

three special structures case do while and do until continued
Three Special Structures – Case, DoWhile, and DoUntil (continued)

Using nested if-then-else for multiple alternatives

Figure 2-31 Flowchart and pseudocode of tuition decisions

Programming Logic and Design, Fifth Edition, Comprehensive

Programming Logic and Design, Seventh Edition, Comprehensive

41

three special structures case do while and do until continued42
Three Special Structures – Case, DoWhile, and DoUntil (continued)

Using a case structure for multiple alternatives

Figure 2-32 Flowchart and pseudocode of case structure

Programming Logic and Design, Fifth Edition, Comprehensive

Programming Logic and Design, Seventh Edition, Comprehensive

42

three special structures case do while and do until continued43
Three Special Structures – Case, DoWhile, and DoUntil (continued)

do-while and do-until loops

Question is asked at the end of the loop structure

Loop statements always used at least once

Figure 2-33 The while loop, which is a pretest loop

Figure 2-34 Structure of a do-while or do-until loop, which are posttest loops

Programming Logic and Design, Fifth Edition, Comprehensive

Programming Logic and Design, Seventh Edition, Comprehensive

43

three special structures case do while and do until continued44
Three Special Structures – Case, DoWhile, and DoUntil (continued)

do-while: executes as long as the question’s answer is Yes or True

do-until: executes as long as the question’s answer is No or False

do

wash a dish

until all dishes are washed

do

wash a dish

while more dishes remain to be washed

Programming Logic and Design, Fifth Edition, Comprehensive

Programming Logic and Design, Seventh Edition, Comprehensive

44

three special structures case do while and do until continued45
Three Special Structures – Case, DoWhile, and DoUntil (continued)

while loop with question at beginning is called a pretest loop

do-while and do-until with question at end are called posttest loops

Posttest loop can be replaced with a sequence followed by a pretest while loop

pay a bill

while there are more bills to pay

pay a bill

endwhile

Programming Logic and Design, Fifth Edition, Comprehensive

Programming Logic and Design, Seventh Edition, Comprehensive

45

three special structures case do while and do until continued46
Three Special Structures – Case, DoWhile, and DoUntil (continued)

Figure 2-35 Flowchart and pseudocode for do-while loop

Programming Logic and Design, Fifth Edition, Comprehensive

Programming Logic and Design, Seventh Edition, Comprehensive

46

three special structures case do while and do until continued47
Three Special Structures – Case, DoWhile, and DoUntil (continued)

Figure 2-36 Flowchart and pseudocode for sequence followed by while loop

Programming Logic and Design, Fifth Edition, Comprehensive

Programming Logic and Design, Seventh Edition, Comprehensive

47

three special structures case do while and do until continued48
Three Special Structures – Case, DoWhile, and DoUntil (continued)

How can this design be made structured?

Figure 2-37 Unstructured loop

Programming Logic and Design, Fifth Edition, Comprehensive

Programming Logic and Design, Seventh Edition, Comprehensive

48

three special structures case do while and do until continued49
Three Special Structures – Case, DoWhile, and DoUntil (continued)

Repeat the needed step to enforce structure

Figure 2-38 Sequence and structured loop that accomplish the same tasks as Figure 2-37

Programming Logic and Design, Fifth Edition, Comprehensive

Programming Logic and Design, Seventh Edition, Comprehensive

49

summary
Summary

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

Programming Logic and Design, Seventh Edition, Comprehensive

50

summary continued
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: posttest loops that ask the question last

do-while and do-until loop statements are always executed at least once

Posttest loop can be replaced by a sequence followed by a while loop

Programming Logic and Design, Fifth Edition, Comprehensive

Programming Logic and Design, Seventh Edition, Comprehensive

51

computer programs and programming languages
Computer Programs and Programming Languages

Next

What is a computer program?

  • Set of instructions that directs computer to perform an array of tasks.
  • Programming language: Provides the syntax, rules and coding needed to write the instructions in a computer program.

Programming Logic and Design, Seventh Edition, Comprehensive

p. 13.02 Fig. 13-1

the program development cycle 6 steps
The Program Development Cycle: 6 Steps

Next

What is the program development cycle?

  • Steps programmers use to build computer programs
  • Programming team—Group of programmers working on program
  • The Program Development Cycle is Step 4 in the System Development Cycle

Programming Logic and Design, Seventh Edition, Comprehensive

p. 13.24 Fig. 13-25

step 1 analyze requirements
Step 1 — Analyze Requirements

IPO chart

Next

What is involved in analyzing the requirements?

  • Review requirements
  • Meet with systems analyst and users
  • Identify input, output, processing, and data components
  • IPO chart—Identifies program’s inputs, outputs, and processing steps

Programming Logic and Design, Seventh Edition, Comprehensive

p. 13.25 Fig. 13-26

step 2 design the solution
Step 2 — Design the Solution

Object-oriented design

Structured design, sometimes called top-down design

Programmer begins with general design and moves toward detailed design

Next

What is involved in designing the solution?

Devise solution algorithm, step-by-step procedure to solve problem

Two approaches

Programming Logic and Design, Seventh Edition, Comprehensive

p. 13.26

step 2 design the solution56
Step 2 — Design the Solution

Next

What is a hierarchy chart?

  • Shows program modules graphically
  • Also called Structure Chart or VTOC: Visual Table of Contents

Programming Logic and Design, Seventh Edition, Comprehensive

p. 13.26 Fig. 13-27

step 2 design the solution57
Step 2 — Design the Solution

Next

What is object-oriented design (OOD) ?

  • Programmer packages data and procedures into a single unit, called an object
  • Objects are grouped into classes
  • A Class Diagram represents hierarchical relationships of classes graphically

Programming Logic and Design, Seventh Edition, Comprehensive

p. 13.27 Fig. 13-28

step 3 validate the design
Step 3 — Validate the Design

Next

Check program design for accuracy

Programmer checks logic for correctness and attempts to uncover logic errors

What is involved in validating the design?

Desk checkprogrammers use test data to step through logic

Logic errordesign flaw that causes inaccurate results

Structured walkthroughprogrammer explains logic of algorithm while programming team steps through program logic

Test datasample data that mimics real data that program will process

Programming Logic and Design, Seventh Edition, Comprehensive

p. 13.32

step 4 implement the design
Step 4 — Implement the Design

Next

What is implementation?

  • Writing the code that translates the design into a program
  • Syntax—rules that specify how to write instructions
  • Comments—program documentation
  • Extreme programming (XP)—coding and testing as soon as requirements are defined

Programming Logic and Design, Seventh Edition, Comprehensive

p. 13.33 Fig. 13-38

step 5 test the solution
Step 5 — Test the Solution

Next

What is involved in testing the solution?

Ensure program runs correctly and is error free

Debugging—locating and correcting syntax and logic errors, orbugs

Test copy of program, called beta, sometimes used to find bugs

Programming Logic and Design, Seventh Edition, Comprehensive

p. 13.34

step 6 document the solution
Step 6 — Document the Solution

Next

What is involved in documenting the solution?

  • Programmers should perform two activities:

Reviews program code—removes dead code, program instructions that program never executes

Reviews documentation

Programming Logic and Design, Seventh Edition, Comprehensive

p. 13.36

what is an algorithm
What is an Algorithm ?
  • Algorithm: a step-by-step procedure to solve a problem.
  • The problem to be solved does NOT have to pertain to a computer program.
  • A procedure to change a flat tire on a car is an algorithm.
  • So is assembling a bicycle or making a cake.
  • Building a house.

Programming Logic and Design, Seventh Edition, Comprehensive

the structured walkthrough
What is a structured walkthrough?

A more formal technique for checking the solution algorithm

The programmer explains the logic of the algorithm while members of the programming team step through the program logic

Purpose is to identify errors in the program logic and check for possible improvements in program design

The Structured Walkthrough

Detecting errors and making improvements early reduces the overall time and cost of program development

Next

p.15.12

Programming Logic and Design, Seventh Edition, Comprehensive

coding computer programs
What is involved in coding programs?

Two steps:

1. Translating the solution algorithm into a programming language

2. Entering the programming language code into the computer

Each of the many programming languages has a very specific syntax

Coding Computer Programs

Syntax

The set of grammar and rules that specifies how to write instructions for a solution algorithm

Next

p.15.13

Programming Logic and Design, Seventh Edition, Comprehensive

documenting computer programs
How are programs documented?

A programmer should take time to document the program code thoroughly

Comments or remarks are included in a program as documentation

Global comments explain the program’s purpose and identify the program name, its author, and the date written

Internal comments explain the purpose of the code statements within the program

Documenting Computer Programs

global comments

internal comments

Next

p.15.13 Fig. 15-16

Programming Logic and Design, Seventh Edition, Comprehensive

payroll program calculations example
Payroll Program Calculations (Example)

Read hours; regularRate = 20.00; overtimeRate=30.00;

fedTaxRate = .28; stTaxRte = .0575; ovRate = 1.5;

if (hours > 80 ) // Biweekly payroll: compute overtime pay

regularPay = 80 * regularRate; // Compute regular pay for 80 hours

overtimePay = (hours – 80) * ovRate * overtimeRate;

else

regularPay = hours * regularRate; // Compute regular pay (<= 80 hours)

overtimePay = 0;

fedTax = grossPay * fedTaxRate;

stateTax = grossPay * stTaxRate;

deductions = fedTax + sttateTax;

grossPay = regularPay + overtimePay;

netPay = grossPay – deductions;

print Name, SSN, regularPay, overtimePay, grossPay, netPay,deductions

Programming Logic and Design, Seventh Edition, Comprehensive

assembly language instructions
Assembly Language Instructions

High-Level Language statement:

overtimePay = 0; // Set overtimePay to zero

Equivalent Assembly Language statements:

LR R1, 0 // Load Register R1 with zero

SR R1, overtimePay // Store zero from R1 into

// memory variable overtimePay

Programming Logic and Design, Seventh Edition, Comprehensive

testing removing syntax logic errors
What is involved in testing programs?

Goal is to ensure the program runs correctly and is error free.

Two types of errors:

Syntax errors

Logic errors

Testing: Removing Syntax & Logic Errors

Syntax errors

Occur when the code violates the syntax, or grammar, of the programming language

Usually discovered the first time a program code is executed on the computer

Logic errors (Semantic errors)

Flaw in the design that generates inaccurate results

Systems analyst develops test data including both valid and invalid input data

Next

p.15.13

Programming Logic and Design, Seventh Edition, Comprehensive

testing programs and run time errors
What is a run time error?

A program failure occurring while a program is being executed (run).

Programmers use test data (good, bad, none) to deliberately cause a run time error in order to test the program.

Examples of run time errors:

Input file not found

Division by zero

Array Index out of bounds

Testing Programs and Run time Errors

Next

p.15.13

Programming Logic and Design, Seventh Edition, Comprehensive

debugging computer programs
What is debugging?

The process of locating and correcting the syntax and logic errors in a program

Errors themselves are the bugs

The first bug was said to be a moth lodged in a computer's electronic relay components during the development of the COBOL language (1959)

Debugging Computer Programs

Next

p.15.14 Fig. 15-17

Programming Logic and Design, Seventh Edition, Comprehensive

slide71
Breaks down the original set of program specifications into smaller, more manageable sections

These sections are called modules

What is top-down design?

Identify the the major functions of a program, called the main routine or the main module

Decompose (break down) the main routine into smaller sections called subroutines

Analyze each subroutine to determine if it can be decomposed further

Continue decomposing subroutines until each one performs a single function

A section of a program that performs a single function is a module

Next

Designing Computer Programs

p.15.5

Programming Logic and Design, Seventh Edition, Comprehensive

structured computer program design
What is structured design?

A technique that builds all program logic from a combination of three basic control structures

A control structure is a design that determines the logical order of program instructions

Each module typically contains more than one control structure

Structured Computer Program Design

Sequence control structure

Selection control structure

Repetition control structure

Next

p.15.6

Programming Logic and Design, Seventh Edition, Comprehensive

sequence control structure
What is a sequence control structure?

Shows one or more actions following each other in order.

Actions:

Inputs

Processes

Outputs

Sequence Control Structure

Next

p.15.7 Fig. 15-5

Programming Logic and Design, Seventh Edition, Comprehensive

selection control structure if then else
What is a Selection Control Structure?

Tells the program which action to take, based on a certain condition

Two common types of selection control structures

Selection Control Structure (IF-THEN-ELSE)

if-then-else control structure

case control structure

Next

p.15.7

Programming Logic and Design, Seventh Edition, Comprehensive

selection control structure if then else75
What is an IF-THEN-ELSE control structure?

Allows a program to evaluate the condition and yields one of two possibilities: true or false

If the result of the condition is true, the program performs one action

If the result is false, the program performs a different (or possibly no) action

Selection Control Structure (IF-THEN-ELSE)

Next

p.15.7 Fig. 15-6

Programming Logic and Design, Seventh Edition, Comprehensive

selection control structure if then else76
Selection Control Structure (IF-THEN-ELSE)

A = 120 // Assign 120 to integer variable A

B = 65 // Assign 65 to integer variable B

IF ( A > B ) // The true condition, if A greater than B

PRINT “The Internet is a great source of info!”

PRINT “Have a nice day !”

ELSE // The false condition: means A <= B

PRINT “This is the false condition”

PRINT “Please study for the final exam !”

Programming Logic and Design, Seventh Edition, Comprehensive

nested if structure
NESTED IF STRUCTURE

IF (SCORE >= 90) // Nested IF “ladder”

GRADE = ‘A’; // Assign letter grade of ‘A’

ELSE

IF (SCORE >= 80)

GRADE = ‘B’;

ELSE

IF (SCORE >= 70)

GRADE = ‘C’;

ELSE

IF(SCORE >= 60)

GRADE = ‘D’;

ELSE

GRADE = ‘F’;

Programming Logic and Design, Seventh Edition, Comprehensive

case entry structure
CASE ENTRY STRUCTURE

SCORE = SCORE / 10; // Make score between ( 0 <= SCORE <= 10)

SWITCH (SCORE) // Case Entry is more efficient than a Nested-IF ladder

BEGIN SWITCH

BEGIN CASE

CASE 10: GRADE = ‘A’;

BREAK;

CASE 9: GRADE = ‘A’;

BREAK;

CASE 8: GRADE = ‘B’;

BREAK;

CASE 7: GRADE = ‘C’;

BREAK;

CASE 6: GRADE = ‘D’;

BREAK;

DEFAULT: GRADE = ‘F’;

END CASE

END SWITCH

Programming Logic and Design, Seventh Edition, Comprehensive

the case control structure
What is a case control structure?

A condition can yield one of four or more possibilities; the last condition is usually the default or error condition.

The CASE Control Structure

Next

p.15.7 Fig. 15-7

Programming Logic and Design, Seventh Edition, Comprehensive

repetition control structure looping
What is a repetition control structure?

Also called the iteration control structure or a loop

Used when a program performs one or more actions repeatedly as long as a certain condition is met

Two forms: 

Repetition Control Structure (Looping)

Do While control structure

Do Until control structure

Next

p.15.8

Programming Logic and Design, Seventh Edition, Comprehensive

do while control structure looping
What is a Do While control structure?

Repeats one or more times as long as a condition is true

Tests a condition at the beginning of the loop

If the result is true, the program executes the action(s) inside the loop

Program loops back and tests the condition again

Looping continues until the condition becomes false

Do While Control Structure (Looping)

Next

p.15.8 Fig. 15-8

Programming Logic and Design, Seventh Edition, Comprehensive

do while loop example
DO WHILE LOOP: EXAMPLE

3000-READ-A-RECORD // Read a record from input file

FLAG = 0 // Set loop control flag to zero

DO WHILE (FLAG = 0) // Loop as long as FLAG is zero

2000-COMPUTE-PAY

2500-PRINT-PAY-RECORD

3000-READ-A-RECORD // Read next record in file

IF END-OF-FILE // If End-Of-File (EOF) is detected

FLAG = 1

ELSE

NULL

ENDIF

END DO WHILE

Programming Logic and Design, Seventh Edition, Comprehensive

do until control structure looping
What is a Do Until control structure?

Tests the condition at the the end of the loop

The action(s) will always execute at least once

Continues looping until the condition is true, and then stops

Do Until Control Structure (Looping)

Next

p.15.8 Fig. 15-9

Programming Logic and Design, Seventh Edition, Comprehensive

do until loop
DO UNTIL LOOP

FLAG = 0

3000-READ-A-RECORD // Read first record from input file

DO // Start of DO UNTIL loop

2000-COMPUTE-PAY // Invoke COMPUTE-PAY module

2500-PRINT-PAY-RECORD

3000-READ-A-RECORD // Read next record from file

IF END-OF-FILE

FLAG = 1

ELSE

NULL

ENDIF

UNTIL (FLAG = 1) // If FLAG is 1, exit the DO-UNTIL Loop

END DO // End of DO UNTIL loop

Programming Logic and Design, Seventh Edition, Comprehensive

count controlled loops
COUNT CONTROLLED LOOPS

SUM = 0

FOR I = 1 TO 10

SUM = SUM + I // 1 + 2 + 3 + … + 10

NEXT I

// Handy formula for this series: SUM = N (N + 1) /2

PRINT SUM // 55 is the printed SUM

Programming Logic and Design, Seventh Edition, Comprehensive

program design guidelines
The program, each of its modules, and each of its control structures must have:

No dead code

No infinite loops

One entry point

One exit point

What are the guidelines of a proper program?

Program Design Guidelines

Dead code

Any code, or program instruction, that a program never executes

Infinite loop

A set of instructions that repeats continuously

Entry point

The location where a program, a module, or a control structure begins

Exit point

The location where it ends

Next

p.15.8

Programming Logic and Design, Seventh Edition, Comprehensive

program design guidelines87
How are entry and exit points are shown?

Program modules often have control structures nested inside one another

Each control structure should have one entry point and one exit point

Program Design Guidelines

Next

p.15.9 Fig. 15-10

Programming Logic and Design, Seventh Edition, Comprehensive

solution algorithms for computer programs
What is a solution algorithm? (3 common tools)

Also called program logic.

A graphical or written description of the step-by-step procedures in a module.

To help develop a solution algorithm, programmers use design tools.

Solution Algorithms for Computer Programs

Program flowchart

Nassi-Schneiderman charts

Pseudocode

Next

p.15.9

Programming Logic and Design, Seventh Edition, Comprehensive

flowcharting computer programs
What is a Program Flowchart?

Graphically shows the logic in a solution algorithm

Follows a set of standards published by the American National Standards Institute (ANSI) in the early 1960s

Flowcharting Computer Programs

Next

p.15.9 Fig. 15-11

Programming Logic and Design, Seventh Edition, Comprehensive

flowcharting computer programs90
How is a program flowchart drawn?

Most symbols connect with solid lines showing the direction of the program

Dotted lines connect comment symbols

Flowcharting Computer Programs

A comment symbol or annotation symbol

Explains or clarifies logic

Next

p.15.10 Fig. 15-12

Programming Logic and Design, Seventh Edition, Comprehensive

flowcharting computer programs software
What is flowcharting software? (Visio, SmartDraw)

Used to develop flowcharts

Makes it easy to modify and update flowcharts

Flowcharting Computer Programs: Software

Next

p.15.10 Fig. 15-13

Programming Logic and Design, Seventh Edition, Comprehensive

nassi schneiderman flowcharts
What is a Nassi-Schneiderman (N-S) chart?

Graphically shows the logic in a solution algorithm

Sometimes called structured flowcharts: Process, Do-While loop, IF, Case

Nassi-Schneiderman Flowcharts

Next

p.15.11 Fig. 15-14

Programming Logic and Design, Seventh Edition, Comprehensive

pseudocode for computer program design
What is pseudocode?

Uses a condensed form of English to convey the logic of a computer program

Also uses indentation to identify the three basic control structures

Often called “A combination of English and your favorite programming language”

Pseudocode for Computer Program Design

Next

p.15.12 Fig. 15-15

Programming Logic and Design, Seventh Edition, Comprehensive

computer programs and programming languages94
Computer Programs and Programming Languages

Next

What are low-level languages and high-level languages?

Low-levellanguage

High-level language

Machine-dependentruns only on one type of computer

Often machine-independentcan run on many different types of computers

Machine and assembly languages are low-level

Programming Logic and Design, Seventh Edition, Comprehensive

p. 13.02

low level languages machine language
Low-Level Languages: Machine Language

Next

What is machine language?

  • Only language computer directly recognizes; May be specific to a type of computer.
  • The machine language for an IBM mainframe computer will differ from the machine language for a PC or a MAC.

Programming Logic and Design, Seventh Edition, Comprehensive

p. 13.03 Fig. 13-2

low level languages assembly
Low-Level Languages: Assembly

Next

What is assembly language?

  • Instructions made up of symbolic instruction codes, meaningful abbreviations and codes called mnemonics.
  • Source program contains code to be converted to machine language

Programming Logic and Design, Seventh Edition, Comprehensive

p. 13.04 Fig. 13-3

procedural languages
Procedural Languages

Next

What is a procedural language? (3GL)

Programmer assigns name to sequence of instructions that tells computer what to accomplish and how to do it

Uses series of English-like words to write instructions

Often called third-generation language (3GL)

Most widely used are BASIC, COBOL, and C

Programming Logic and Design, Seventh Edition, Comprehensive

p. 13.04

procedural languages compilers
Procedural Languages: Compilers

Next

What is a compiler?

  • Program that converts entire source program into machine language before executing it

Programming Logic and Design, Seventh Edition, Comprehensive

p. 13.05 Fig. 13-4

procedural languages interpreters
Procedural Languages: Interpreters

Next

What is an interpreter?

  • Program that translates and executes one program code statement at a time
  • Does not produce an object program (binary code)

Programming Logic and Design, Seventh Edition, Comprehensive

p. 13.05 Fig. 13-5

procedural languages basica qbasic
Procedural Languages: BASICA, QBASIC

Next

What is BASIC? (BASICA, GWBASIC, QBASIC)

  • Designed for use as simple, interactive problem-solving language
  • Beginner’s All-purpose Symbolic Instruction Code

Programming Logic and Design, Seventh Edition, Comprehensive

p. 13.06 Fig. 13-6

procedural languages cobol
Procedural Languages: COBOL

Click to view Web Link,

then click COBOL below Chapter 13

Next

What is COBOL?

  • Designed for business applications
  • English-like statements make code easy to read, write, and maintain
  • COmmon Business-Oriented Language

Programming Logic and Design, Seventh Edition, Comprehensive

p. 13.06 Fig. 13-7

procedural languages c
Procedural Languages: C

Next

What is C? (Developed in early 1970’s)

  • Powerful language originally designed to write system software. Extremely fast as is C++
  • Requires professional programming skills

Programming Logic and Design, Seventh Edition, Comprehensive

p. 13.07 Fig. 13-8

object oriented programming languages
Object-Oriented Programming Languages

Next

What is an object-oriented programming (OOP) language?

Used to implement object-oriented design

Major benefit is ability to reuse existing objects

Event-driven—checks for and responds to set of events

C++ and Java are complete object-oriented languages

Objectis item that contains data and procedures that act on data

Eventis action to which program responds

Programming Logic and Design, Seventh Edition, Comprehensive

p. 13.07

unified modeling language uml
Unified Modeling Language (UML)

Programming Logic and Design, Seventh Edition, Comprehensive

object oriented programming languages105
Object-Oriented Programming Languages

Click to view Web Link,

then click C++ below Chapter 13

Next

What is C++?

  • Includes all elements of C, plus additional features for working with object-oriented concepts
  • Used to develop database and Web applications
  • Java: based on C++

Programming Logic and Design, Seventh Edition, Comprehensive

p. 13.08 Fig. 13-9

object oriented programming languages106
Object-Oriented Programming Languages

Click to view Web Link,

then click Java below Chapter 13

Next

What is Java? (1995)

  • Developed by Sun Microsystems.
  • Java programs are compiled into Bytecode.
  • Similar to C++ but uses just-in-time (JIT) compiler to convert source code into machine code.

Programming Logic and Design, Seventh Edition, Comprehensive

p. 13.08 Fig. 13-10

example of java program oop
Example of Java program: OOP

Defining the circle class:

class Circle

{

double radius = 1.0; // Default radius of circle is 1 unit

double findArea( )

{

return Math.PI * radius * radius;

}

double findPerimeter( ) // Computes circumference of circle

{

return 2 * Math.PI * radius;

}

} // End of class Circle

Programming Logic and Design, Seventh Edition, Comprehensive

example of a java program oop
Example of a Java program: OOP

public class TestCircle // A test class program to test Circle class

{

public static void main(String[ ] args)

{

Circle circle1 = new Circle(5); // circle1 has radius 5

Circle circle2 = new Circle(12); // circle2 has radius 12

Circle circle3 = new Circle(45); // circle3 has radius 45

// Print the radii of the various circles

System.out.println(“The radius of circle1 is “ + circle1.radius );

System.out.println(“The radius of circle2 is “ + circle2.radius );

System.out.println(“The radius of circle3 is “ + circle3.radius );

} // End of main method

} // End of class TestCircle

Programming Logic and Design, Seventh Edition, Comprehensive

object oriented programming languages109
Object-Oriented Programming Languages

Visual programming environment (VPE) allows developers to drag and drop objects to build programs

Programmer writes and implements program in segments

Click to view Web Link,

then click RAD below Chapter 13

Next

What is a Visual Programming Language? (a 5GL)

Provides visual or graphical interface for creating source code

Sometimes calledfifth-generation language

Often used in RAD (rapid application development) environment

Programming Logic and Design, Seventh Edition, Comprehensive

p. 13.09

object oriented programming languages110
Object-Oriented Programming Languages

Step 1. The programmer designs the user interface.

Step 2.The programmer assigns properties to each object on the form.

Step 3.The programmer writes code to define the action of each command button.

Click to view Web Link,

then click Visual Studio .NET below Chapter 13

Step 4.The programmer tests the application.

Next

What is Visual Studio .NET 2003 ?

  • Suite of visual programming languages and RAD tools
  • .NET is set of technologies that allows program to run on Internet
  • Visual Basic .NET 2003 is used to build complex object-based programs

Programming Logic and Design, Seventh Edition, Comprehensive

p. 13.10

object based programming languages
Object-Based Programming Languages
  • Visual Basic .NET 2003 (sometimes called VB .NET) is a visual programming languages that easily allows programmers to develop complex task-oriented object-based programs.
  • VB .NET 2003 is based on the Visual Basic programming language developed by Microsoft in the early 1990’s.
  • VB .NET is a good language for beginning programmers although it really is not that easy!

Programming Logic and Design, Seventh Edition, Comprehensive

object oriented programming languages112
Object-Oriented Programming Languages
  • Also, in the Visual Studio .NET suite are the Visual C++.NET 2003 and Visual C#.NET 2003 (pronounced Visual C sharp) programming languages. Very powerful ! Programmers can develop software for nearly every computer platform.
  • Visual C#.NET 2003 is a visual programming language built on the .NET platform that takes the complexity out of C++

Programming Logic and Design, Seventh Edition, Comprehensive

object oriented programming languages113
Object-Oriented Programming Languages
  • Visual C# .NET 2003 (see – sharp)

is a visual programming language that combines the features of C++ with an easier development environment. The purpose is to take the complexity out of Visual C++ .NET 2003 an still provide an object-oriented language.

Programming Logic and Design, Seventh Edition, Comprehensive

object oriented programming languages114
Object-Oriented Programming Languages
  • Visual J# .NET 2003 (JAY – sharp)

is a visual programming language that allows Java software development in the .NET environment. Programmers familiar with Java or Visual J++ easily can migrate to Visual J# .NET 2003.

  • Colleges often teach Visual J# in their introductory computer programming courses because it is easier to learn than the Visual C family of languages.

Programming Logic and Design, Seventh Edition, Comprehensive

object oriented programming languages115
Object-Oriented Programming Languages

Next

Delphi (from Borland Software)

  • Powerful visual programming tool
  • Ideal for large-scale enterprise and Web applications

Programming Logic and Design, Seventh Edition, Comprehensive

p. 13.11 Fig. 13-12

object oriented programming languages116
Object-Oriented Programming Languages

Next

Delphi

  • Delphi can be used to develop programs quickly for Windows, Linux, and .NET platforms

Programming Logic and Design, Seventh Edition, Comprehensive

p. 13.11 Fig. 13-12

object oriented programming languages117
Object-Oriented Programming Languages

Next

Delphi

  • Delphi has more functionality and features than Visual Basic and is more difficult to learn and use.

Programming Logic and Design, Seventh Edition, Comprehensive

p. 13.11 Fig. 13-12

object oriented programming languages118
Object-Oriented Programming Languages

Next

What is PowerBuilder? (from Sybase Corp.)

  • Another powerful visual programming tool
  • Best suited for Web-based and large-scale object-oriented applications
  • It is a widely used RAD programming tool

Programming Logic and Design, Seventh Edition, Comprehensive

p. 13.12 Fig. 13-13

nonprocedural languages 4gls sql
Nonprocedural Languages: 4GLs: SQL

Next

What is a fourth-generation language (4GL)?

  • A Nonprocedural language that allows users to access data in a database
  • A popular 4GL is SQL, query language that allows users to manage data in a relational DBMS

Programming Logic and Design, Seventh Edition, Comprehensive

p. 13.13 Fig. 13-15

other programming languages
Other Programming Languages

Next

Other available programming languages:

ADA

ALGOL

APL

FORTH

FORTRAN

HYPERTALK

LISP

LOGO

MODULA-2

PASCAL

PILOT

PL/I

PROLOG

SMALLTALK

Programming Logic and Design, Seventh Edition, Comprehensive

p. 13.22

other programming languages details
Other Programming Languages: Details
  • LISP: LISt Processing– used for artificial intelligence applications.
  • Logo: Used to teach children programming and problem-solving.
  • Pascal: used to teach structured programming.
  • Modula-2: A successor to Pascal; used for developing systems software.
  • PL/I: Combination of FORTRAN & COBOL
  • Smalltalk: Object-oriented programming language

Programming Logic and Design, Seventh Edition, Comprehensive

summary122
Summary

End of ITP 100 Presentation

Programming Logic and Design, Seventh Edition, Comprehensive