CS141: Topics for Sept 16, 18 & 20, 2013
- Exam Reminder: An exam is coming up in 2 weeks. Now is a good time to take stock of all that we have
covered. Please look over the material we have covered and make a list of
questions or programs you don't understand. Ask about these in class. Chances are there are others who also
are struggling with the same things. The best way to study is to 1) review vocabulary and 2) practice programming.
- Beware - Everything is Cumulative! Everything we learn builds on what has been done before. If you don't feel you understand earler material, it is
important that you seek some help. Resources are listed at Seeking Help
- Shared network drive: We now have a shared network drive - directions for accessing it are on the links page.
Please try accessing it!
In the news ...
ACM Technews Archive
Homework and Reading
The reading and homework for this week can be found here: Lab 4: Loops
For practice, check out the WileyPlus Chapter 4 Flash Cards!
unwinding and hand tracing
Loop variable, initialization, condition, update; loop body
counter, running total
Monte Carlo Method
Topics: Chp 3 - if-else (review from last time)
- Practice Boolean Operators: Try writing a boolean expression for the examples here
(you will need to
add variable declarations that are consistent with what is being asked):
The above are modified from notes
(see Selection Statements lecture and Boolean Operator section.)
- The temperature is above 90 or the humidity equals 90. (assume these are doubles)
- The mathematical expression a > b > c. (assume doubles)
- It is not true that a and b are both 0. (assume ints)
- a divided by b is equal to 2 (and not infinite!) (assume doubles)
- The personís hair color is not red and their age is less than 21 (assume String and int)
- Neither x nor y are bigger than 10 (assume ints)
- x is larger than y but smaller than 2y (assume ints)
- c is equal to the ascii letter q (assume char)
- The character c is a letter of the alphabet. (hint: You will need to look up the ascii characters)
- Questions on reading assignment?
- On Wed, talk about chp 3 programming assignment: Finding the smallest - lots of ways of doing this.
- Lexicagraphic ordering and the String compareTo method.
Topics: Chp 4 - Loops
- Why do we have loop structures?
Repetition - print the numbers from 1 to 5. What about 10 to 1000?
Repetition more generally - print the numbers starting at n1 and ending at n2.
- Components of any loop:
- Loop variable - the variable that controls the looping
- Loop variable initialization - the starting value of the loop variable.
- Loop condition - this must be true for loop to continue
- Loop variable update - how does loop variable change after each loop
- Loop body - sequence of statements that are executed in the loop
- Types of loops:
- while-loops - used when the number of repetitions can't be predicted ahead of time (indefinite)
- for-loops - when you know precisely how many times you will loop (definite). Loop
variable only defined within loop.
- do-while-loops - checks condition at end; always executes the body at least once
- Figuring out what is going on - Hand tracing, unraveling the loop
- Common Errors: infinite loops, off-by-one
- Sentinel values - the user controls when to stop
- Checking for correct user input and break statements
- Common applications: Basic Looping Problems (pdf)
- Book examples: computing sums, averages, all matches, first match, max values, min values, comparing adjacent values
- Nested loops. See Nested Loop Problems (pdf)
- Random numbers and games- rolling a die, picking a card.
- Monte Carlo method
In Class Practice Activities