CSC115 Introduction to Computer Programming - PowerPoint PPT Presentation

1 / 26
About This Presentation
Title:

CSC115 Introduction to Computer Programming

Description:

CSC115 Introduction to Computer Programming Zhen Jiang Dept. of Computer Science West Chester University West Chester, PA 19383 zjiang_at_wcupa.edu – PowerPoint PPT presentation

Number of Views:55
Avg rating:3.0/5.0
Slides: 27
Provided by: PCUs103
Learn more at: https://www.cs.wcupa.edu
Category:

less

Transcript and Presenter's Notes

Title: CSC115 Introduction to Computer Programming


1
CSC115 Introduction to Computer Programming
  • Zhen Jiang
  • Dept. of Computer Science
  • West Chester University
  • West Chester, PA 19383
  • zjiang_at_wcupa.edu

2
Table of Contents
  • Structure
  • Selection (Decision)
  • Loop
  • Array and Function

3
Selection (Decision)
  • Price is right.
  • Sample execution (click on this link to try)

4
No
Yes
Condition
Action 1
Action 2
Action 3
5
Yes
No
Boolean Expression
Action 1 If controlled
Action 2 else controlled
Action 3
6
  • If block
  • if condition then
  • action 1 (statements 1)
  • else
  • action 2 (statements 2)
  • end if
  • action 3 (statement 3)

7
  • Legal age to have drivers license

?
8
  • Condition
  • Simple condition
  • Format
  • ltValuegt ltrelational operatorsgt ltValuegt
  • Number value relational operators
  • , ltgt, lt, gt, lt, gt
  • String value relational operators
  • , ltgt
  • Complex condition
  • And, or, not
  • Truth table, table 4, p121

9
  • Relational operators have lower precedence than
    math operators.
  • (7 - 1) 5 3 gt 7 5
  • 6 5 3 gt 35
  • 30 3 gt 35
  • 33 gt 35
  • False
  • Relational operators cannot be chained (unlike
    math operators)
  • 2 lt x lt 10
  • error!

10
Development Process
  • 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!

11
(No Transcript)
12
  • Multiple selection
  • Nested if block
  • Example letter grade

13
  • Comments
  • Nested if block for multiple section problem
  • If then
  • case 1
  • Else
  • if then
  • case 2
  • else
  • end if
  • End if

14
  • If block, extension without else
  • if condition then
  • action 1 (statements 1)
  • end if
  • action 3 (statement 3)

15
Are they different, how much?
Dim x as integer, y as integer x
text1.text y0 if x gt 3 then y 1 if x gt10
then y 2 else y 3 End if End
if Listbox1.Items.Add( y )
Dim x as integer, y as integer x
text1.text y0 if x gt 3 then y 1 if x gt 10
then y 2 End if else y 3 End
if Listbox1.Items.Add( y )
16
Try 0, 4, 11 and see the results!
Dim x as integer, y as integer x
text1.text y0 if x gt 3 then y 1 if x gt10
then y 2 else y 3 End if End
if Listbox1.Items.Add( y )
Dim x as integer, y as integer x
text1.text y0 if x gt 3 then y 1 if x gt 10
then y 2 End if else y 3 End
if Listbox1.Items.Add( y )
17
Try 0, 4, 11 and see a worse situation!
Dim x as integer, y as integer x
text1.text y0 if x gt 3 then y 1 if x lt10
then y 2 else y 3 End if End
if Listbox1.Items.Add( y )
Dim x as integer, y as integer x
text1.text y0 if x gt 3 then y 1 if x lt 10
then y 2 End if else y 3 End
if Listbox1.Items.Add( y )
18
  • 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

19
  • Select block
  • Select case
  • A constant
  • A variable
  • An expression
  • Is
  • To range
  • Else
  • And and or

20
Loop
  • Do while Loop
  • do while condition
  • statements
  • loop
  • statements2

21
No
Yes
condition
statements1
Action 2
Action 3
22
No
Yes
condition
Statements1
Statements2
23
  • Other loops

24
  • Clock

25
  • Function and procedure

26
  • Array
Write a Comment
User Comments (0)
About PowerShow.com