A Review of C++
Procedural Paradigm
Identifiers | Data Types | ASCII | Constants | Variables | Operators | Expressions | Statements | Arrays | Simple I/O | Std Lib | Böhm & Jacopini | Functions | Strings | Recursion
| Identifiers - | Names given to functions and variables not predefined in C++. Rules to Identifiers:
There are two types of identifiers, external and internal.
|
||||||||||||
Data Types - |
Specifies the type of content to be stored in a constant or variable. Such types are:
|
||||||||||||
ASCII - |
The character data type, char, is represented with its ASCII value. ASCII is a standard correlating characters to an interger value. ASCII Table |
||||||||||||
Constants - |
Identifier whose value does not change throughout the execution of the program. Declaration is as such: const int MY_INT = 1000; |
||||||||||||
Variables - |
Identifier whose value may change repeatedly during the execution of the program. Declaration is as such: int myInt = 934; |
||||||||||||
Operators - |
Operators are broken into three groups; Arithmetic, Logical and Relational, and Bitwise Operators. The operators are in order from highest to lowest precedence, starting at the top.
|
||||||||||||
Expressions - |
Expressions take variables, literals, and operators and combine them into pieces of a program. Below are examples of expressions: (x + y)/ 100 z <= w |
||||||||||||
Statements - |
Statements are complete units that can be executed. They can be broken up into three types:
|
||||||||||||
Arrays - |
Example declaration: int myArray[100]; Arrays can be declared using any type. The above declaration allows for an array of 100 elements, in this case integers, which are accessed by using the subscript operator, [ ]. The indexing of an array starts at 0, therefore, myArray[67], would access the 68th element in the array. Arrays can be initialized by using the curly braces in the declartion. char myArray[5] = {'a', 'b', 'c', 'd', 'e'} |
||||||||||||
Simple I/O - |
The << and >> operators have been overloaded to handle input and output in C++. The << operator ouputs data to the I/O stream while the >> operator inputs from the I/O stream. Examples: cin >> myFloat; cout << "This is a float: " << myFloat; |
||||||||||||
Standard Libraries - |
These libraries contain many of the predefined function of C++, like the I/O functions and math functions. This is a reference to some of the libraries found in C++: http://www.cppreference.com/ |
||||||||||||
Böhm and Jacopini structures - |
Böhm and Jacopini proved that there is a need for only three control structures when writing a program.
Structured Programming: Along with the control structures above, a program must have good structure. Producing human understanding is the key to good structure. Single-Entry, Single-Exit: Becuase humans read linearly, the program should execute as such. This is accomplished with a single-entry and a single-exit program. |
||||||||||||
Functions - |
Functions make up the program. Each having there separate actions to preform, combining them produces a "functional" program. Each function has a parameter list, the elements being passed into the function from outside, and a return type, or the data type of the element to be returned from the function. Function Prototypes: This declares the function at the beginning of the program. The prototype looks exactly like the first line of the function, followed by a semi-colon. Example: int myFunction (int theNum, float theFloat); Scope: Every function and variable has a scope or bounds which it can work within. If a variable is declared locally to a function, it can only be used inside that function. Pass By Value and Reference: Every function and variable has a scope or bounds which it can work within. If a variable is declared locally to a function, it can only be used inside that function. Function Overloading: overloaded functions have the same name, but a different parameter list and/or return type. When this type of function is called, the complier decides which function is to be called out of the overloaded ones. |
||||||||||||
Strings - |
C-strings: C-strings are character arrays with a NULL character at the end to signal the end of the string. There is a library in C++ that contains functions that can be executed on C-strings. ( C-Strings Library References) String Objects: A string class has also been introduced into C++. This class adds different functions to the C-string library. ( String Class Library References) |
||||||||||||
Recursion - |
A resursive function is a function that calls itself. The programmer specifies a basis case and the function will continue to run, calling itself, until that basis case is found. Everytime the function is called a new set of parameters and variables are allocated memory, thus recursion keeps track of values at different levels of the recursive loop. |