CS141: Topics for Sept 23, 25 & 27, 2013
In the news ...
ACM Technews Archive
Homework and Reading
The reading and homework for this week can be found here: Lab 5: Loops
For practice, check out the WileyPlus Chapter 5 Flash Cards!
method (function, member function, procedure)
stepwise refinement (revisited)
return type, return value
(formal) parameter variable
argument (actual parameter)
variable scope: local, global
Common expressions are:
"call a method" or "call a function"
"return a value"
"pass a value as a parameter"
Topics: Chp 4 - Loops (topics still to cover)
- You should soon complete: BlackJack Part 1.
In preparation for Part 2 of the lab, try to better organize your code. That is, identify each of the actions that need to be done:
Try to write code where each action is done in a different section of the code.
- Picking a card index
- Calculating the suit and face indices,
- Determining the name of the suit and face
- Printing the full name of a card
- Prompting again
- Types of loops: 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
- Book examples: max values, min values, comparing adjacent
- Nested loops. See Nested Loop Problems (pdf)
- Random numbers and games- rolling a die, picking a card.
- Monte Carlo method
Topics: Chp 5 - Methods
- What are methods and why do we want them? E.g. Math.round, rolling a die.
- Why use methods?
- modularity and testing
- structure and readability
- Look at the structure of Part 1 of the BlackJack game.
- Components of a Method Declaration
- header (first line, aka the method signature) - contains the return type, method name, parameter list
- method body
- If the return type is not void, the method body must contain a return statement
- declare or write a method
- call a method
- arguments (actual parameters) vs formal parameters
- passing in a parameter (argument)
- Tracing the code - stepping through the code line-by-line. Do you understand the order the statements are executed?
- Scope - see problem in previous Exam 2
- Writing code using stepwise refinement - methods make this easy to do.
- Recursive methods - looping without loops or solving the towers of hanoi
In Class Practice Activities