Semester Review
C++ Basics
C++ Variables: Names, Types, Declarations, and Scope
C++ Operators
C++ has lots of operators (i.e., like +, * and /). In general, you should be familiar with:
Those that let you do arithmetic: e.g., +, -, *, / and %.
Those that let you compare things: e.g., >, <, ==, !=, <=, etc.
Those that let you increment and decrement variables: e.g., ++ and --
Those that let you put logical expressions together: e.g. && (and) and || (or)
Those that let you assign a value to a variable: =, +=, -=, etc.
Those that let you do input (>>) and output (<<).
The complete list of operators with their precedence rules can be found here.
Programming Languages: High-Level, Assembly and Machine (or Object)
Types of Control Flow
Sequential
By default, this is the type of control flow you get. Your program starts with the first statement, then goes to the next, and the next, and the next, and the .....
You can only do something other than sequential control, if you use one the types below (selection or iteration).
Selection (or Branching): if statements and switch statements
Functions
Calling Existing (or Predefined) Functions
Once a function has already been written---by you or someone else---you can use it as often as you need, by calling it in your program. The only two rules you really need to remember are:
(1) The function has to be "declared" before you call it (by "declare" a function, we really mean that a function prototype or definition has to proceed the first function call)
(2) The function has to be called correctly (by the correct name and with the correct number of parameters).
Function Prototypes
A function prototype gives you all the necessary information you need to use (or call) the function including:
The function's return type
The function's name
The number and type of each parameter to the function
The syntax for a function prototype is: returnType functionName (parameters);
Examples:
double sin (double angle);
int strcmp (char* string1, char* string1);
User-Defined Functions
Functions are named, parameterized blocks of code.
Any section of code that you write can become a function by taking the code, enclosing it in braces (i.e., making it a block) and giving it a function name (and parameters, if appropriate).
Function Parameters: There are a lot of details regarding function parameters. To fully understand them, you'll need to review the examples from the class schedule page. Brief descriptions of the different parameter types appear below.
Call-By-Value Parameters (or Call-By-Copy): When the '&' character is *not* present on the parameter, the parameter uses call-by-value semantics, which means the function uses a copy of the argument in the function call.
Call-By-Reference Parameters: When the '&' character *is* present, call-by-reference semantics are in effect and the function uses the actual variable which appears as the argument---meaning the argument can be changed in the function.
Constant Parameters: When the const keyword appears before the parameter, then the parameter can't be changed in the function.
Default Parameters: When the parameter is given a value in the parameter list, then it gets this value by default if an argument is missing in the function call.
Structs
Classes