CPS 6, Ramm - Spring 2000 - 1/21/00 #4
Chapter 2: C++ Programs: Form and Function
- 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
- 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
- So Far: Previous Programs Fixed, Once Written
- More typically:
- Input: information fed to program (yum yum)
- Process: information is processed (indigestion?)
- Output: results of processing displayed (oh oh !?)
- Divide and Conquer
- Iterative Enhancement
(Planning for our Multi-Story Building)
- The Input Stream
cin
cin >> person
- Extraction Operator
>>
- Variables/Objects
- Definition/Creation/Memory
Type/Class
type name;
type name1, name2, ... name N;
- Modify Paging Program
page2.cpp
- Processing Numbers
Example: Collision at -40
tempscale.cpp
- Type:
int Numbers
- max, min
- micros, workstations
- Type:
double Numbers
- Arithmetic Operators/Operands
- + addition
- - subtraction
- * multiplication
- / division
- % modulus/remainder
- Operator Precedence
- ( )
- *, /, %
- +, -
- left to right
- Automatic
int to double conversion
- Classes and Types
- Objects and Variables