lec17 - Lecture 17 Arrays (Savitch 6.1) CS125 Course Notes...

Info iconThis preview shows pages 1–6. Sign up to view the full content.

View Full Document Right Arrow Icon
CS125 Course Notes Lecture 17, Slide 1 Lecture 17 •Arrays (Savitch 6.1)
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
CS125 Course Notes Lecture 17, Slide 2 Motivating arrays • You have a list of your friends’ birthdays and want to determine how many were born in September. • Later in the program, you need to determine how many were born in a different month.
Background image of page 2
CS125 Course Notes Lecture 17, Slide 3 First approach Set septCounter to 0 for each friend { get friend’s birth date; if birthday is in September update septCount; } Any problems?
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
CS125 Course Notes Lecture 17, Slide 4 Second approach Assume 4 friends. Initialize variables friend1, friend2, friend3, friend4 to birth dates; Set septCounter to 0 if friend1 born in September update count; if friend2 born in September update count; if friend3 born in September update count; if friend4 born in September update count; Any problems?
Background image of page 4
Course Notes Lecture 17, Slide 5 Arrays • A special kind of structure that stores a collection of variables. • All variables are of the same type. • The number of entries is fixed when the array is created. • Individual elements can be accessed
Background image of page 5

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 6
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 22

lec17 - Lecture 17 Arrays (Savitch 6.1) CS125 Course Notes...

This preview shows document pages 1 - 6. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online