Lectures

Lecture 1: Introduction to C++

  • Outline: [PDF]
  • Lecture 1: Introduction to C++
    • A first introduction to programming in C++. We will learn how to compile and run C++ programs from command-line in Linux.
    • Slides: [PDF]
    • Exercises:

LECTURE 2: Data Types & Variables

  • Today we will learn the basics of writing C++ programs including input/output, data types and variables and type casting.
  • Slides: [PDF]
  • Exercises:
    • [PDF] – example of C++ input and output using a string and example of formatting double output. [YouTube]
  •  Readings:
    • Absolute C++ 6/E 1.2-1.5

LECTURE 3: Type casting (conversion)

  • Today we will learn more about the basics of writing C++ programs including data types and type casting.
  • Slides: [PDF] (same as Lecture 2)
  • Exercises:
  •  Readings:
    • Absolute C++ 6/E 1.2-1.5

LECTURE 4: BRANCHING

  • Today we will learn about branching in C++ including if statements and switch statements.
  • Slides: [PDF]
  • Exercises:
  • Readings:
    • Absolute C++ 6/E 2.1-2.2

LECTURE 5: LOOPING

  • Today we will learn about looping in C++ including for loops, while loops and do-while loops.
  • Slides: [PDF]
  • Exercises:
    • loop_ex1.cpp – two different for loop examples for adding up even numbers.
    • loop_ex2.cpp – while loop example for adding up even numbers.
    • loop_ex3.cpp – while loop example for finding the largest number less than 10,000,000 and divisible by 63.
    • loop_ex4.cpp – while loop example for allowing user to enter an arbitrary amount of input.
  • Readings:
    • Absolute C++ 6/E 2.3

LECTURE 6: Functions I

  • We will learn how to use predefined functions in libraries such as cmath and ctime. In addition to using predefined functions we can also create our own functions and use them in our programs. We will also start to learn about programmer-defined functions.
  • Exercises:
  • Readings:
    • Absolute C++ 6/E 3.1, 3.2, 3.3, 4.1, 4.2

LECTURE 7: Functions II

LECTURE 8: FILE INPUT/OUTPUT

  • Today we’ll learn about file input and output using streams. How to write to files, read from a file and append to a file. Our file input and output example will also introduce arrays. Although arrays are not the main topic of the lecture they are an important programming language concept. Next, we’ll learn how to handle when a file fails to open. To assist with the example we will learn about the the chmod Linux command.
  • Exercises:
  • Readings:
    • Absolute C++ 6/E 12.1, 12.2, 5.1-5.3
  • References:

LECTURE 9: CODE STYLE & DOCUMENTATION

  • Overview of how to properly document your programs including in-program documentation and API documentation. We will also learn about code style – best practices for how to write and organize your programs. Examples of code style include best practices for indentation, white space, line length, comments, naming conventions and file structure.
  • Slides: [PDF]
  • Readings:
    • Absolute C++ 6/E 1.4
  • References:

LECTURE 10: Namespaces

  • Overview of the four kinds of namespaces in C++: the standard namespace, user-defined namespaces, the unnamed namespace and the global namespace.
  • Slides: [PDF]
  • Exercises:
    • namespace_ex1.cpp – examples of using the standard namespace, user-defined namespaces and unnamed namespace as well as an examples of using the scope resolution operator (::) with namespaces.

LECTURE 11: In-class exercise

LECTURE 12 & 13: In-class exercise

LECTURE 14 & 15: POINTERS IN C++

  • Introduction to pointers, declaring a pointer variable, the dereferencing operator and the address-of operator.
  • Slides: [PDF]
  • Exercises:
    • pointers_ex1.cpp – an example of using pointers with ordinary (automatic) variables in C++.  [YouTube]
    • pointers_ex2.cpp – an example of how to pass a pointer variable to a function as a call-by-value parameter. This is the first of two examples that highlight the difference between passing a pointer as a call-by-value vs. call-by-reference parameter.  [YouTube & YouTube]

LECTURE 16: Dynamic variables

  • Using pointers to create dynamic variables and dynamic arrays.
  • Slides: [PDF]
  • Exercises:

LECTURE 17: Dynamic Arrays

  • More examples of dynamic arrays.
  • Slides: [PDF]
  • Exercises:
  • Readings:
    • Absolute C++ 6/E 10.2