csc115 introduction to computer programming
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 PresentationTRANSCRIPT
![Page 1: CSC115 Introduction to Computer Programming](https://reader036.vdocuments.site/reader036/viewer/2022062316/56816807550346895ddd8b7c/html5/thumbnails/1.jpg)
CSC115 Introduction to Computer Programming
Zhen JiangDept. of Computer Science
West Chester UniversityWest Chester, PA 19383
![Page 2: CSC115 Introduction to Computer Programming](https://reader036.vdocuments.site/reader036/viewer/2022062316/56816807550346895ddd8b7c/html5/thumbnails/2.jpg)
Table of Contents Structure
Selection (Decision) Loop Array and Function
![Page 3: CSC115 Introduction to Computer Programming](https://reader036.vdocuments.site/reader036/viewer/2022062316/56816807550346895ddd8b7c/html5/thumbnails/3.jpg)
Price is right. Sample execution (click on this link to
try)
Selection (Decision)
![Page 4: CSC115 Introduction to Computer Programming](https://reader036.vdocuments.site/reader036/viewer/2022062316/56816807550346895ddd8b7c/html5/thumbnails/4.jpg)
ConditionYes
Action 1 Action 2
No
Action 3
![Page 5: CSC115 Introduction to Computer Programming](https://reader036.vdocuments.site/reader036/viewer/2022062316/56816807550346895ddd8b7c/html5/thumbnails/5.jpg)
Boolean Expression
Yes
Action 1If controlled
Action 2else controlled
No
Action 3
04/22/23 5
![Page 6: CSC115 Introduction to Computer Programming](https://reader036.vdocuments.site/reader036/viewer/2022062316/56816807550346895ddd8b7c/html5/thumbnails/6.jpg)
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](https://reader036.vdocuments.site/reader036/viewer/2022062316/56816807550346895ddd8b7c/html5/thumbnails/7.jpg)
Legal age to have driver’s license
![Page 8: CSC115 Introduction to Computer Programming](https://reader036.vdocuments.site/reader036/viewer/2022062316/56816807550346895ddd8b7c/html5/thumbnails/8.jpg)
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](https://reader036.vdocuments.site/reader036/viewer/2022062316/56816807550346895ddd8b7c/html5/thumbnails/9.jpg)
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](https://reader036.vdocuments.site/reader036/viewer/2022062316/56816807550346895ddd8b7c/html5/thumbnails/10.jpg)
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](https://reader036.vdocuments.site/reader036/viewer/2022062316/56816807550346895ddd8b7c/html5/thumbnails/11.jpg)
![Page 12: CSC115 Introduction to Computer Programming](https://reader036.vdocuments.site/reader036/viewer/2022062316/56816807550346895ddd8b7c/html5/thumbnails/12.jpg)
Multiple selection Nested if block Example: letter grade
![Page 13: CSC115 Introduction to Computer Programming](https://reader036.vdocuments.site/reader036/viewer/2022062316/56816807550346895ddd8b7c/html5/thumbnails/13.jpg)
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](https://reader036.vdocuments.site/reader036/viewer/2022062316/56816807550346895ddd8b7c/html5/thumbnails/14.jpg)
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](https://reader036.vdocuments.site/reader036/viewer/2022062316/56816807550346895ddd8b7c/html5/thumbnails/15.jpg)
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](https://reader036.vdocuments.site/reader036/viewer/2022062316/56816807550346895ddd8b7c/html5/thumbnails/16.jpg)
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](https://reader036.vdocuments.site/reader036/viewer/2022062316/56816807550346895ddd8b7c/html5/thumbnails/17.jpg)
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](https://reader036.vdocuments.site/reader036/viewer/2022062316/56816807550346895ddd8b7c/html5/thumbnails/18.jpg)
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](https://reader036.vdocuments.site/reader036/viewer/2022062316/56816807550346895ddd8b7c/html5/thumbnails/19.jpg)
Select block Select case
A constant A variable An expression Is To range Else And and or
![Page 20: CSC115 Introduction to Computer Programming](https://reader036.vdocuments.site/reader036/viewer/2022062316/56816807550346895ddd8b7c/html5/thumbnails/20.jpg)
Loop Do while Loop
do while conditionstatements
loop statements2
![Page 21: CSC115 Introduction to Computer Programming](https://reader036.vdocuments.site/reader036/viewer/2022062316/56816807550346895ddd8b7c/html5/thumbnails/21.jpg)
Yes
statements1 Action 2
No
Action 3
condition
![Page 22: CSC115 Introduction to Computer Programming](https://reader036.vdocuments.site/reader036/viewer/2022062316/56816807550346895ddd8b7c/html5/thumbnails/22.jpg)
Yes
Statements1
No
Statements2
condition
![Page 23: CSC115 Introduction to Computer Programming](https://reader036.vdocuments.site/reader036/viewer/2022062316/56816807550346895ddd8b7c/html5/thumbnails/23.jpg)
Other loops
![Page 24: CSC115 Introduction to Computer Programming](https://reader036.vdocuments.site/reader036/viewer/2022062316/56816807550346895ddd8b7c/html5/thumbnails/24.jpg)
Clock
![Page 25: CSC115 Introduction to Computer Programming](https://reader036.vdocuments.site/reader036/viewer/2022062316/56816807550346895ddd8b7c/html5/thumbnails/25.jpg)
Function and procedure
![Page 26: CSC115 Introduction to Computer Programming](https://reader036.vdocuments.site/reader036/viewer/2022062316/56816807550346895ddd8b7c/html5/thumbnails/26.jpg)
Array