+ All Categories
Home > Documents > Introduction to Computing Dr. Nadeem A Khan. Lecture 2.

Introduction to Computing Dr. Nadeem A Khan. Lecture 2.

Date post: 18-Jan-2016
Category:
Upload: beverly-barker
View: 218 times
Download: 0 times
Share this document with a friend
31
Introduction to Introduction to Computing Computing Dr. Nadeem A Khan Dr. Nadeem A Khan
Transcript
Page 1: Introduction to Computing Dr. Nadeem A Khan. Lecture 2.

Introduction to Introduction to ComputingComputing

Dr. Nadeem A KhanDr. Nadeem A Khan

Page 2: Introduction to Computing Dr. Nadeem A Khan. Lecture 2.

Lecture 2Lecture 2

Page 3: Introduction to Computing Dr. Nadeem A Khan. Lecture 2.

Read Chapter 3Read Chapter 3

Page 4: Introduction to Computing Dr. Nadeem A Khan. Lecture 2.

Program PlanningProgram Planning

1.1. AnalyzeAnalyze

2.2. DesignDesign

3.3. Choose the Choose the InterfaceInterface

4.4. CodeCode

5.5. Test and DebugTest and Debug

6.6. Complete the Complete the DocumentationDocumentation

Page 5: Introduction to Computing Dr. Nadeem A Khan. Lecture 2.

The Problem-Solving Process The Problem-Solving Process

Input

Processing

Output

Page 6: Introduction to Computing Dr. Nadeem A Khan. Lecture 2.

Program Design ToolsProgram Design Tools

►Pseudo-codePseudo-code

►Flow ChartsFlow Charts

►Hierarchy Hierarchy ChartsCharts

Page 7: Introduction to Computing Dr. Nadeem A Khan. Lecture 2.

Postage stamp problem:Postage stamp problem:

How many stamps to put on a How many stamps to put on a envelop given one stamp is envelop given one stamp is needed for every five sheets of needed for every five sheets of paper or a fraction thereofpaper or a fraction thereof

Page 8: Introduction to Computing Dr. Nadeem A Khan. Lecture 2.

PseudocodePseudocode

►Abbreviated version of actual Abbreviated version of actual computer code in English-like computer code in English-like statementsstatements

Page 9: Introduction to Computing Dr. Nadeem A Khan. Lecture 2.

Pseudo code: Postage Stamp Pseudo code: Postage Stamp ProblemProblem

►Program – Determine the number of Program – Determine the number of stamps for a letterstamps for a letter

Read SheetsRead Sheets

Set the number of stamps to sheets / 5Set the number of stamps to sheets / 5

Round the number of stamps Round the number of stamps

Display the number of stamps Display the number of stamps

Page 10: Introduction to Computing Dr. Nadeem A Khan. Lecture 2.

FlowchartsFlowcharts

►Special geometric symbols Special geometric symbols connected by arrows connected by arrows

Page 11: Introduction to Computing Dr. Nadeem A Khan. Lecture 2.

Postage Postage stamp stamp

problemproblem

Start

Read sheets

Set stamps = sheets/ 5

Display stamps

Round stamps up to next

whole number

End

input

processing

output

processing

Page 12: Introduction to Computing Dr. Nadeem A Khan. Lecture 2.

Elements of FlowchartsElements of Flowcharts

Symbol Name

Flowline

Terminal

Input/Output

Processing

Decision

Page 13: Introduction to Computing Dr. Nadeem A Khan. Lecture 2.

Continued…Continued…

Symbol Name

Connector

Off page Connector

Predefined process

Annotation

Page 14: Introduction to Computing Dr. Nadeem A Khan. Lecture 2.

Hierarchy chartHierarchy chart

►Shows overall program structureShows overall program structure

Page 15: Introduction to Computing Dr. Nadeem A Khan. Lecture 2.

Hierarchy Charts: Postage Hierarchy Charts: Postage Stamp ProblemStamp Problem

Postage Stamp

Problem

Read

Sheets

Calculate

stamps

Display

stamps

Set stamps = sheets/5

Round stamps to next whole

number

Page 16: Introduction to Computing Dr. Nadeem A Khan. Lecture 2.

Another problem:Another problem:

Given a street number of one-way Given a street number of one-way street in New York, decide the street in New York, decide the direction of the street, either direction of the street, either eastbound or westboundeastbound or westbound

Note: Note: Even numbered street: EastboundEven numbered street: EastboundOdd numbered street: WestboundOdd numbered street: Westbound

Page 17: Introduction to Computing Dr. Nadeem A Khan. Lecture 2.

DecisionsDecisions

►Sequence StructureSequence Structure – a sequence – a sequence followed without skipping any line.followed without skipping any line.

►Decision StructureDecision Structure – a structure – a structure which requires a decision for any lines which requires a decision for any lines of code to be executed.of code to be executed.

Page 18: Introduction to Computing Dr. Nadeem A Khan. Lecture 2.

Decision Structure: Decision Structure: PseudocodePseudocode

IF condition is TRUE THENIF condition is TRUE THENProcess step(s) 1Process step(s) 1

ELSEELSE Process step(s) 2Process step(s) 2

END IFEND IF

Page 19: Introduction to Computing Dr. Nadeem A Khan. Lecture 2.

Decision Decision Structure:Structure:FlowchartFlowchart Process

Step (s) 2

Is Condition True

Process Step (s)

1

Page 20: Introduction to Computing Dr. Nadeem A Khan. Lecture 2.

Decision Structure: Decision Structure: PseudocodePseudocode

What in case of multiple What in case of multiple conditions?conditions?

Page 21: Introduction to Computing Dr. Nadeem A Khan. Lecture 2.

Decision Structure: Decision Structure: PseudocodePseudocode

IF condition 1 is TRUE THENIF condition 1 is TRUE THENProcess step(s) 1Process step(s) 1

ELSE IF condition 2 is TRUE ELSE IF condition 2 is TRUE THENTHEN Process step(s) 2Process step(s) 2

ELSEELSEProcess step(s) 3Process step(s) 3

END IFEND IF

Page 22: Introduction to Computing Dr. Nadeem A Khan. Lecture 2.

Pseudo-Code: Street Direction Pseudo-Code: Street Direction ProblemProblem

Get Street

IF Street is EVEN

Display Eastbound

ELSE

Display Westbound

END IF

Page 23: Introduction to Computing Dr. Nadeem A Khan. Lecture 2.

Flow Flow Chart: Chart: Street Street DirectioDirectionnProblem Problem

End

Start

Get Street

Is street even?

Display Westbound

Display Eastbound

Page 24: Introduction to Computing Dr. Nadeem A Khan. Lecture 2.

Hierarchy Chart: Street Hierarchy Chart: Street Direction ProblemDirection Problem

Street Directio

n Program

Get Street

Number

Decide whether street

number is odd or even

Display direction

Page 25: Introduction to Computing Dr. Nadeem A Khan. Lecture 2.

Still Another ProblemStill Another Problem

► CCalculate and report the grade-point alculate and report the grade-point average of a class.average of a class.

Page 26: Introduction to Computing Dr. Nadeem A Khan. Lecture 2.

The Loop StructureThe Loop Structure

► A programming structure that A programming structure that executes instructions many times.executes instructions many times.

Page 27: Introduction to Computing Dr. Nadeem A Khan. Lecture 2.

Flow chart: Flow chart: loop structureloop structure No

Process Step(s)

Is condition true ?

Yes

Page 28: Introduction to Computing Dr. Nadeem A Khan. Lecture 2.

Pseudo code: loop structurePseudo code: loop structure

► DO WHILEDO WHILE condition is TRUE condition is TRUE

Process Step(s)Process Step(s)

LOOPLOOP

Page 29: Introduction to Computing Dr. Nadeem A Khan. Lecture 2.

Draw the Flowchart for the class Draw the Flowchart for the class average problemaverage problem

Page 30: Introduction to Computing Dr. Nadeem A Khan. Lecture 2.

Pseudo code: Class Average Pseudo code: Class Average ProblemProblem

INITIALIZE Counter and Sum to 0

DO WHILE there are more data

Get the next Grade

Add the Grade to the Sum

Increment the Counter

LOOP

Compute Average = Sum/Counter

Display Average

Page 31: Introduction to Computing Dr. Nadeem A Khan. Lecture 2.

Hierarchy Chart: Class Average Hierarchy Chart: Class Average ProblemProblem

Class average program

Get grade

Compute sum

Display average

Calculate

average


Recommended