CPS 1 - Spring, 2000 - Ramm 2/21/00 #15
- Announce
- Continue to Read Course Pack Chapter 4
- Test ...
Chapt 4: Top-Down Programming, Subroutines, and a Database Application
- 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
- Larger Problems: How to Deal with the Complexity
- Divide and Conquer
- Design: Stepwise Refinement
- Implementation: Top-Down
- Dummy Routines: Stubs
- Within level: I/O First
- "Parallel" Arrays or "Corresponding" Arrays
- Model Phone Book Capability
- Array (of strings) for Names
- Array (of strings) for Phone Number
- Array (of strings) for Address
- Typical Access by Name
- For human use, ordered by name to speed access
- For computer use, may be fast enough for non ordered access
- Access by other Fields (other arrays)
- Can access by phone number and get name/address
- (like "phone -p 660-6532" on acpub system)
- Extend Idea to Database
- Generalization of phone book problem
- Can have many "parallel" arrays
- Basic Data Base Functions
- Load Data (File I/O would be nice)
- Display Data (Complete Dump)
- Query/Search (Selective Info Retrieval)
- Edit/Update (Update or Correct: Edit Database)
- Wild Card Retrieval
- Allows query to say "I don't care" for certain fields
- Used Car Database
UsedCars.java,
UsedCars.html