csc115 introduction to computer programming

26
CSC115 Introduction to Computer Programming Zhen Jiang Dept. of Computer Science West Chester University West Chester, PA 19383 [email protected]

Upload: jagger

Post on 25-Feb-2016

70 views

Category:

Documents


0 download

DESCRIPTION

CSC115 Introduction to Computer Programming. Zhen Jiang Dept. of Computer Science West Chester University West Chester, PA 19383 [email protected]. Table of Contents. Structure Selection (Decision) Loop Function Interesting features Graphics Other tools. Selection (Decision). - PowerPoint PPT Presentation

TRANSCRIPT

Page 1: CSC115 Introduction to Computer Programming

CSC115 Introduction to Computer Programming

Zhen JiangDept. of Computer Science

West Chester UniversityWest Chester, PA 19383

[email protected]

Page 2: CSC115 Introduction to Computer Programming

Table of Contents Structure

Selection (Decision) Loop Array and Function

Page 3: CSC115 Introduction to Computer Programming

Price is right. Sample execution (click on this link to

try)

Selection (Decision)

Page 4: CSC115 Introduction to Computer Programming

ConditionYes

Action 1 Action 2

No

Action 3

Page 5: CSC115 Introduction to Computer Programming

Boolean Expression

Yes

Action 1If controlled

Action 2else controlled

No

Action 3

04/22/23 5

Page 6: CSC115 Introduction to Computer Programming

If block if condition then

action 1 (statements 1) elseaction 2 (statements 2) end if

action 3 (statement 3)

Page 7: CSC115 Introduction to Computer Programming

Legal age to have driver’s license

Page 8: CSC115 Introduction to Computer Programming

Condition Simple condition

Format <Value> <relational operators> <Value>

Number value relational operators =, <>, <, >, <=, >=

String value relational operators=, <>

Complex condition And, or, not Truth table, table 4, p121

Page 9: CSC115 Introduction to Computer Programming

Relational operators have lower precedence than math operators.

(7 - 1) * 5 + 3 > 7* 5 6 * 5 + 3 > 35 30 + 3 > 35

33 > 35 False

Relational operators cannot be chained (unlike math operators)

2 <= x <= 10error!

04/22/23 9

Page 10: CSC115 Introduction to Computer Programming

Identify two exclusive options Implement each handling in different action parts Identify the situation (values) for option selection Make a condition so that all the situation value for

option part 1 will lead to this condition true. Verify all the situation value for option part 2 will lead

to this condition false, otherwise, revise the above condition!

Development Process

Page 11: CSC115 Introduction to Computer Programming
Page 12: CSC115 Introduction to Computer Programming

Multiple selection Nested if block Example: letter grade

Page 13: CSC115 Introduction to Computer Programming

Comments: Nested if block for multiple section

problemIf then

case 1Else

if thencase 2else…end if

End if

Page 14: CSC115 Introduction to Computer Programming

If block, extension without else if condition then

action 1 (statements 1)

end if action 3 (statement 3)

Page 15: CSC115 Introduction to Computer Programming

Dim x as integer, y as integerx = text1.texty=0if x > 3 then

y =1if x >10 then

y = 2else

y = 3End ifEnd ifListbox1.Items.Add( y )

Are they different, how much?

Dim x as integer, y as integerx = text1.texty=0if x > 3 then

y =1if x > 10 then

y = 2End ifelse

y = 3End ifListbox1.Items.Add( y )

Page 16: CSC115 Introduction to Computer Programming

Dim x as integer, y as integerx = text1.texty=0if x > 3 then

y =1if x >10 then

y = 2else

y = 3End if

End ifListbox1.Items.Add( y )

Dim x as integer, y as integerx = text1.texty=0if x > 3 then

y =1if x > 10 then

y = 2End if

elsey = 3

End ifListbox1.Items.Add( y )

Try 0, 4, 11 and see the results!

Page 17: CSC115 Introduction to Computer Programming

Dim x as integer, y as integerx = text1.texty=0if x > 3 then

y =1if x <10 then

y = 2else

y = 3End if

End ifListbox1.Items.Add( y )

Dim x as integer, y as integerx = text1.texty=0if x > 3 then

y =1if x < 10 then

y = 2End if

elsey = 3

End ifListbox1.Items.Add( y )

Try 0, 4, 11 and see a worse situation!

Page 18: CSC115 Introduction to Computer Programming

My point One line in wrong place

Could create the program 99.99% different Structural procedure

Ask yourself where (the next program segment line) the computer execution goes

Before that, ask yourself if you can find the “if” for each “else”

Ex 6

Page 19: CSC115 Introduction to Computer Programming

Select block Select case

A constant A variable An expression Is To range Else And and or

Page 20: CSC115 Introduction to Computer Programming

Loop Do while Loop

do while conditionstatements

loop statements2

Page 21: CSC115 Introduction to Computer Programming

Yes

statements1 Action 2

No

Action 3

condition

Page 22: CSC115 Introduction to Computer Programming

Yes

Statements1

No

Statements2

condition

Page 23: CSC115 Introduction to Computer Programming

Other loops

Page 24: CSC115 Introduction to Computer Programming

Clock

Page 25: CSC115 Introduction to Computer Programming

Function and procedure

Page 26: CSC115 Introduction to Computer Programming

Array