A Summary of Topics for CSC1321 Programming in C++

This page summarizes the topics covered in the beginning programming class, CSC1321 Programming in C++. It highlights the essential programming structures.

Introduction to Programming
  • What is programming?
  • Popular modern programming languages
  • C++ program structure and a short history of C++
  • Compiling process and software tools such as Visual Studio for Windows, Xocde for Mac OS, and command line compiling.
Basic Language Elements and Structures
  • Identifier
  • Expression
  • Input from keyboard and file
  • Output to monitor display and file
Conditional Structure
  • Boolean data type
  • Boolean algebra operators: AND, OR, NOT
  • Boolean algebraic properties: DeMorgan's Law
  • Seven relational operators, three logic operators and their precedence.
  • Conditional statements: if, if-else, and nested if-else
  • In nested if-else, the else always matches with the nearest if.
  • Short-circuit evaluation of a boolean expression.
  • Short-hand expression for a mini if-else. For example:
    	   if(a > b)
    	     larger = a;
    	   else
    	     larger = b;
    
    	   larger = a > b ? a : b; 
    	   
  • Switch statement. It can be used as an alternative to a nested if-else with many caseso.
    1. The type of the variable for switch cases must be integral: integer, character, enumeration, or boolean
    2. Normally, a break statement is needed for each case. If a case body doesn't contain a break, the statements that follow will be executed until a break statement is encountered or the end of the switch is reached. It is called "follow through." Sometimes, this feature is used for the situation where a block of statements are shared by multiple cases.
    3. The final case is under a keyword "default."
Looping Structure
  • while loop
  • do-while loop. It always executes the loop body at the first time.
  • for loop. It is a compact form of loop structure with three parts: initialization, condition, and a post-statement.
  • A loop can be executed forever, called infinite loop.
Functions
  • A function is an independent group of program. Once a function is defined, it can be called or invoked as many times as needed.
  • A function consists of two parts: heading and body. The heading includes the type of the value returned by the function, function name, and a list of input parameter variables.
  • A function is normally called from another function. The caller must provide a matching number of arguments and correct types.
  • Parameter values can be passed through two ways: passing-by-value and passing-by-reference.
  • A reference variable is another name for an existing variable. Value changes to a reference variable is an indirect change to the referenced variable.
  • Passing-by-reference can be used to mimic returning multiple values by a function through the reference parameter variables.
Scope and Life Time of Variables
  • Static vs automatic variables
  • The scope of a variable is a region where the variable can be accessed or recognized. It starts from the point of variable declaration to the end of the most inner block within which the variable is declared.
  • Global variables have a scope of the entire file.
  • The life time of a variable refers to the duration of the variable memeory being allocated.
Arrays
  • An array is a collection of elements with the same data type.
  • Two ways to create an array: static and dynamic
  • How to access array elements?
  • Pass entire array to functions
  • Passing array is equivalent to passing-by-reference.
  • A 2D array is simply an array of 1D arrays
  • Correspondance between 1D and 2D array locations.

Key Terms in Programming

Variable
A symbolic name for the memory space allocated to a variable.
Identifier
A generic term for a variable or function name.
Boolean
A data type with only two possible values: true and false. "Boolean" was named after Engish Mathematician Geogia Boole who introduced Boolean Algebra.
Compiling
Compiling is a process of translating high-level programs to a low-level machine dependent execuatable code.
Runtime
Runtime refers to the program execuation period.
Namespace
A namespace is a grouping of C++ library functions and programming objects.
Function
A function is an independent group of programs. It can be called as many times as needed once defined.