CS314 Lab 1
Prep Material

C++ Material

  • Header files and source files
    • Don't forget to include in your header file:
#ifndef _FILENAME_H_
#define _FILENAME_H_

// prototype code goes here
#endif
    • Where does main go?
    • Including other "packages/libraries"
      • iostream is really useful!
  • Go over primitive data types:
    • e.g. intfloatdouble
    • const replaces final
  • Declaring static arrays, e.g.:
const int size = 3;
float vector[size];
  • Classes in C++
    • Declaring a class prototype
    • Constructor / Destructor - what do they do?
    • Defining methods and data members
    • Class methods vs. Instance methods [i.e.. static]
    • Private, Public, and Protected members
    • Class inheritance
    • Polymorphism
    • Overloading
  • Pointers:
    • Declaring pointers: e.g.,
float *ptr;
    • Initializing pointers (and the Address-of Operator '&'):
float a = 10.f;
float *ptr = &a;    // or
float *ptr = NULL; // or
float *ptr = vector;
    • Pointer operations, e.g.:
      • ++, --, <, >, ==, [int], etc.
    • Dereferencing pointers, e.g.:
float a = 10.f;
float *ptr = &a;

cout << ptr << endl;    // vs.
cout << *ptr << endl;

*ptr = 5.5;

cout << *ptr << endl;
cout << a << endl;
  • Pass by reference vs. pass by value
  • Dynamic memory allocation:
    • new and delete (or C-style malloc and free)
    • Allocating and freeing arrays and objects.
  • namespaces
  • Useful libraries
  • If there's time: templates?



Methods for debugging:
  • Print statements
  • Assertion statements
  • Try-catch clause
  • Breakpoints
  • Stepping through code
  • Examining variables
  • See Eclipse sheet to get started debugging