CSC 221: Computer Programming I
Fall 2001
Test 2 Review
TEST 1 MATERIAL
Overview & history: hardware vs. software, technology generations, ...
C++ basics: program structure, input & output, variables, constants, ...
Expressions & assignments: mathematical operators, library functions, ...
User-defined functions, computational abstraction, calling sequence, ...
Conditional execution: if/if-else/cascading if-else, boolean expressions, ...
Libraries & objects: cctype library, ADT, C++ classes (e.g., Die class), ...
Conditional looping
while loops
controlled by boolean expressions
danger: infinite (black-hole) loops
counters (init & increment) & sums (init and add)
increment/decrement operators, arithmetic assignments
for loops
used for counter-driven applications
equivalence to while loops
Top-down design
approach to designing solutions to complex problems
break problem into main tasks, then divide each into subtasks, ...
eventually, subtasks are simple enough to implement
advantages: helps to manage complexity, focus on small, indep. tasks
can focus on big picture (functions + data flow) before details
parameter passing
value parameters (default) allow for info to be passed into a function
parameter is a local copy of the corresponding argument
any changes within the function happen to the copy only
reference parameters (via &) allow for info to be passed in and out
parameter is a local alias for the argument (which must be a variable)
any changes within the function happen simultaneously to the argument
Arrays
homogeneous collection of items, accessible via indexing
advantages: can group related values under one name
can traverse and systematically access all values via a loop
can pass all values as one entity
declaration: specify number of entries in brackets
access: specify index in brackets (indices range from 0 to numEntries-1)
index out-of-bounds errors
arrays as parameters
don't specify size in parameter type
arrays are treated as references (pointers) to memory
--> can't copy one array to another using assignment
--> when pass by value, function can still change element values
can declare parameter to be const in order to protect elements
Review Questions