CPS 1 - Spring, 1998 - Ramm 2/23 #16
- Announce
- Friday's Test
- Quiz Wednesday
Chapt 4: Top-Down Programming, Subroutines, and Database Application
- Use Parameters to Increase Flexibility
- Use IntField to read in size
- Parameters change looping
DiaParms.java,
DiaParms.html
- Example: Functions using Functions
Shapes.java,
Shapes.html
- Getting Information In and Out of Functions
- Class Data; Known within class.
- Known within class.
- Instance Variable
- Formal Parameters/Arguments
- by position, not name
- names may or may not match
- types must match
- number of parameters must match
- Syntax: Using a Function
- function-name(arg1, arg2, ...);
- Whole statement is function invocation
- Functions that Return Values
- var = function-name(arg1, arg2, ...);
- Use function where-ever a variable can be used
- Examples
- Value Parameters vs Reference Parameters
- Primitive Types: by value
- Class, by reference
- Arrays, by reference
- Syntax: Defining a Function
- return-type function-name(type1 param1, type2 param2, ...);
- void return-type
- Examples
- Problem Solving: Divide and Conquer
- Top-Down Implementation
- Dummy Routines: Stubs
- Within level: I/O First
- Parallel Arrays