Discussion - PowerPoint PPT Presentation

1 / 19
About This Presentation
Title:

Discussion

Description:

What if Name had 10,000 characters? CS 100. Discussion #4 Loops and Trees. 14 ... 'Fred Flintstone' Name. Student.GPA = 3.6; Student.Address = 'West Cobblestone' ... – PowerPoint PPT presentation

Number of Views:41
Avg rating:3.0/5.0
Slides: 20
Provided by: danrol
Category:

less

Transcript and Presenter's Notes

Title: Discussion


1
Discussion 4 Loops and Trees
2
Three Programming Constructs
3
Programming Constructs (continued)
  • Do instructions in sequence
  • Fred 27
  • Jane 16
  • Fred Jane - Fred
  • Jane Fred/2

4
Programming Constructs (continued)
  • Choose task A (True) or task B (False)
  • IF (Score gt 93)
  • Grade 'A'
  • ELSE
  • Grade 'E'

5
Programming Constructs (continued)
  • Repeatedly execute tasks
  • FOR (init limit increment)
  • FOR (i0 ilt10 i)
  • Answer Answeri

6
Scope
  • Scope binds a block of instructions together
  • Braces define scope

FOR (i1 ilt8 i)
IF (i lt 3)
A i i B i i
4
  • What is the final value of B?

7
Scope
  • Scope binds a block of instructions together
  • Braces define scope

FOR (i1 ilt8 i)
IF (i lt 3) B i i
A i i
14
  • What is the final value of B?

8
Scope
  • Scope binds a block of instructions together
  • Braces define scope

FOR (i1 ilt8 i) B i i
IF (i lt 5)
A i i
16
  • What is the final value of B?

9
Loops and Trees
10
Review Arrays
What if AA had 10,000 items?
i 0 AAi0 i1 AAi0 i2 AAi0 i3 A
Ai0 i4 AAi0
i
?
0
1
2
3
4
AA
?
0
0
?
1
0
2
?
0
?
3
0
?
4
0
11
2D Arrays (images)
What if the image was 1024 x 1024?
Img
X1 Y1 P ImgX,Y ImgX,Y
0 Y2 ImgX,Y128 X2 ImgX,Y255
1
2
0 Black 128 Gray 255 White
2
1
255
12
Strings
i
0
1
2
i 0 NameiNamei 32 i
1 NameiNamei 32 i 2 NameiNamei
32
Name
66 (B)
79 (O)
34 (")
13
FOR Loop
What if Name had 10,000 characters?
i
0
3
1
2
FOR (i0 iltlength(Name) ii1) C
Namei IF (Cgt'a' Clt'z')
Namei Namei 32
C
98
111
66
Name
66 (B)
79 (O)
14
Records (a collection of named things)
Student
3.6
West Cobblestone
Student.GPA 3.6 Student.Address West
Cobblestone
15
An Array of Students
Students
Betty Rubble
F
16
Trees
BYU
BioAg
Business
PhysSci
Stat
Zoology
Acnt
Market
CS
Math
Botany
CS100
CS235
CS142
17
BYU.PhysSci.CS.CS1000.GPA2.9
BYU
BioAg
Business
PhysSci
Stat
Zoology
Acnt
Market
CS
Math
Botany
CS100
CS235
CS142
2.9
18
Review of Information
  • Binary
  • Numbers - Integer, Floating Point
  • Characters
  • Arrays, Strings
  • Records (named things)
  • Trees

19
Review of programs
  • Expressions
  • Variables
  • Assignment
  • Sequence
  • If
  • For loop
Write a Comment
User Comments (0)
About PowerShow.com