CPS 6, Ramm - Summer Semester I - 5/24/99 #3
- Announce
- Coint toss for Random Quiz #1
- Random Quiz #2
Chapter 2: C++ Programs: Form and Function
- Functions Invoking Functions
diamond2.cc
- Order of Functions
mondias.cc
- Function Prototypes - Syntax
return-type
function(type name, type name, ...);
return-type
function(type, type, ...);
===>>> ;
- Using Function Prototypes
diamondsp.cc
- Let's Write a Program (class activity)
Requirements:
- Use functions
- Have functions use functions
- Minimize repetition
- Some kind of "graphic" output
Questions:
- Do we need prototype statements?
- What language features could we use?
- More on Style
- Indenting
- Braces on separate lines
- Good Identifiers
- Identifiers/Syntax
- letters, digits, underscore
- do not start with digit
- case sensitive
- arbitrary length
- do not use reserved words (p54)
- Identifiers/Style
- meaningful identifiers
- user defined functions & types start: uppercase
- parameters or variables start: lowercase
- constants (later): all uppercase
- use uppercase to start multi-part words (not _)
- Complexity: Measuring Computer Resources
- Looking Up a Phone Number Given a Name
- Looking Up a Name Given a Phone Number
- Wooden Nickels & Printing Money
- Complexity: Size of the Program
- A: One $0.01 per cout
moneyA.cc
Linear Yield
- B: $0.01 per cout/10 cout's per function call
moneyB.cc
Linear Yield
- C: Increase both calls and couts
moneyC2.cc,
moneyC5.cc,
moneyC10.cc
Quadratic Yield
- D: Increase Depth (of functions calling)
moneyD2.cc,
moneyD3.cc,
moneyD5.cc
Exponential Yield