CSC 221: Computer Programming I
Fall 2001
Test 1 Review
Overview & history
hardware vs. software
historical generations
mechanical -> vacuum tube -> transistor -> IC -> VLSI -> parallel & networks
evolution of programming
machine language -> assembly language -> high-level language
C++ basics
program structure: comments, #include, main, return
input & output
: cin (input stream), >> operator
: cout (output stream), << operator, endl
formatted output : setiosflags & setprecision, setw
variables
declarations, declaration + initialization, identifiers, memory cells
data types: int, double, char, bool, string
local variables: scope is limited to enclosing block { }
lifetime begins when reach declaration, ends with block
constants
declaration + initialization, constancy ensured by compiler
global constants: declared outside of functions, accessible to entire program
Visual C++
projects, edit-compile-debug-execute cycle, syntax errors
Expressions and assignments
mathematical expressions
+, -, *, /, and % operators, precedence & associativity
assignments
= operator, evaluation order (evaluate rhs, then assign to lhs)
calling functions
library: fabs, sqrt, pow, floor, ceil, ...
User-defined functions
advantages of functions
computational abstraction, simplify main, generalize tasks via parameters
function definitions
return type, function name, parameters, comments, return statement
function prototypes
function calling sequence (5 steps)
Conditional execution
selectively execute code based on a condition
if statement (1-way), if-else (2-way), cascading if-else (multi-way)
Boolean expressions
comparison operators: ==, !=, <, >, <=, >= (danger: = vs. ==)
logical connectives: && (AND), || (OR), ! (NOT)
short-circuit evaluation
Libraries & objects
Abstract Data Type (ADT): collection of data + operations on that data
libraries of functions for primitive ADTs: , , ...
C++ classes (user-defined types)
class encapsulates data fields (variables) and member functions
e.g., string class in : +, <<, >>, length, at, substr, find, ...
Die class in "Die.h": Roll, NumRolls, NumSides