# Fred: C++ Notes: Table of Contents

Some of these supplemental notes are good, others only rough drafts or half-completed. Because they are designed only to provide additional examples, summaries, or explanations where the textbook is weak, they do not cover many obviously important topics. You can download a zipped version: notes-cpp-2004-12-19.zip [less than 400 KB]. -- Fred

## Getting Started

- Development Systems
  - IDEs - Dev-C++
- Model programs
  - Example - Celsius to Fahrenheit.
  - Example - Celsius to Fahrenheit loop.
  - Example - Template for main.
- Misc
  - Braces
  - Development Techniques

### Summaries

- Summary - Basic Elements - types, ...
- Summary - Expressions
- Summary - Control Flow Statements
- Summary - Functions
- Summary - Program Structure
- Summary - Header Files

## Types and Expressions

### Types

- Integers (`int`, `short`, `long`, `char`)
- Floating Point (`float`, `double`, `long double`)
- Characters (`char`)
  - Reading characters
  - Character functions - <cctype>
- `bool`
- Enums
  - Enums
  - Enum Values and I/O

### Expressions

- Summary: Expressions
- Example: Converting to binary by division
- Operator: sizeof
- Bitwise Operators
  - Operators: Bitwise
  - Example: convert to binary using bitwise ops
  - Example: Convert to hex using bitwise ops
- Exercises: ++, =, ?: Expressions

## Control Flow

### Loops

- Examples
  - Ex: Line of stars - count up
  - Ex: Line of stars - count down
  - Ex: Finding max of input values
- Programming Problems - Reading from `cin`
  - Programming Problem - cin Count Input Values
  - Programming Problem - cin Count Equal
  - Programming Problem - cin Max and Min
  - Programming Problem - cin Average
  - Programming Exercise - Average Positive Negative
- Programming Problems - Writing from a loop
  - Programming Problem - Print Numbers
  - Programming Problem - 99 Bottles of Beer
  - Programming Problem - Ulam Sequence
- Programming Problems - Nested loops
  - Programming Problem - Print Parallelogram
  - Programming Problem - Figures
  - Programming Problem - Multiplication Table

### Switch Statement

- Switch
- Switch usage
- Simple Calculator

### Functions

- Function Concepts
- Function Structure
- Function `return` Statement
- Function Parameters
- Function Call Order
- Function Reference Parameters
- Programming Problems
  - Programming Problem - Convert to Seconds
  - Programming Problem - Temperature Opinion
  - Programming Problem - Convert to Meters
  - Programming Problem - Average 3 Numbers
  - Programming Problem - Prompt Y/N

### Exceptions

- try - catch
- Standard exceptions
- Exception test

## Input / Output

- I/O streams - overview
- Idiom: cin loop
- Anti-idiom - Using `cin` in three places, instead of one
- End-Of-File (EOF)
- Reading numbers
- Reading characters
- Reading lines
- Reading text files

- Example: File open dialog
- I/O operators - << and >>
- I/O manipulators
- String streams
- String stream example
- Idiom - Separate User Interface from Logic

### GUI

- Graphical User Interfaces

## Arrays

### One-dimensional Arrays

- Arrays
- Array Examples
- Array Memory Diagrams
- Array Initialization
- Passing Array Parameters
- Arrays - Problems and Solutions
- Arrays - Buffer overflow

### C-Strings - arrays of char

- C-Strings (arrays of chars)
- Common <cstring> functions
- C-string Prog exercises 1
- C-string Prog exercises 2
  Here are solutions to a few problems, using separate source files.
  - C-Strings - Programming Exercise Solutions - main
  - C-Strings - Programming Exercise Solutions - functions
  - C-Strings - Programming Exercise Solutions - header

### 2-dimensional arrays

- 2-Dimensional arrays
- 2-D Array Memory Layout
- Arrays of arrays

### Battleship Example

- Example - Battleship ver 1 - First version does nothing
- Example - Battleship ver 2 - One ship in linear grid
- Example - Battleship ver 3a - Multiple ships in Suez Canal

### Sorting Arrays

- Sorting
- Sort efficiency
- Bubble Sort - Fixed passes
- More Bubble Sorts
- Selection Sort
- isSorted
- STL sort for arrays

### Searching Arrays

- Linear Search
- Binary Search
- Recursive Binary Search

### Misc Array Function Examples

- Example - readArray
- Example - insert
- Example - erase
- Example - reverse
- Example - push
- Example - pop
- Example - maximum
- Example - average

## Misc practical issues.

### Multiple source files

- Multiple Source Files

## Pointers, References, and Dynamic Allocation

### Pointers and References

- Addresses, pointers, references
- Pointers
- The NULL pointer
- Pointer quote
- The Name of the Song is ...
- swap - references, pointers, STL, templates

### Pointers, arrays, and subscripts

- Arrays as pointers
- Arrays as Pointers - Weird but true
- Pointers and Subscripts - strcpy
- Programming Problems
  - Words in Reverse Order
  - Example - Words in Reverse Order - vector

### Dynamic allocation (new, delete)

- Dynamic Allocation of Arrays
- Dynamic Allocation of C-Strings
- Example: Expanding an Array
- Dynamic allocation issues
- Example - Dynamic C-String Allocation

## Structs

- Structs
- Struct operations
- Struct Example: Time
- Struct operators
- Struct example 1
- Struct example 2
- -> operator

### Examples

- Classical (non-OOP) Linked Lists
  - Linked Lists - Example Using Nodes
  - Singly linked, doubly linked, class lists
  - Combining two circular, doubly linked lists
- Binary Search Trees
  - Binary Search Trees
  - Binary Tree Traversal
- Expression Trees
  - Expression Trees
  - Expression Tree Struct
  - Expression Tree Class (like struct)
  - Expression tree using inheritance

## Object-Oriented Programming with Classes

- OOP
  - Object-Oriented Programming (OOP)
  - OOP Terminology
- Classes
  - Classes
  - this
  - Example: floatVector v1
  - Visibility - public and private
- Data members
  - Member initializers
- Constructors and Destructors
  - Constructors
  - Shallow vs Deep Copies
  - Copy Constructors
  - Destructors

- Operator Overloading
  - Operator Overloading
  - Overloading Assignment
  - Overloading Derived Class Assignment
- Member functions
  - `const` member functions
- Friend functions
  - Friend Functions
  - Overloading << and >>
- Inheritance
  - Nothing yet

## Generic Programming

- Templates
  - Templates
- Template functions
  - Nothing yet

- Template Classes
  - Example - CheckedArray Template Class
  - Programming Exercises - Extend CheckedArray
  - Example - CheckedArray Alternate Style

## STL (Standard Template Library) containers, iterators, algorithms

### General

- STL Overview

### Containers

- General information
  - Introduction to Containers
- Sequence containers
  - Common Sequence Container Operations
  - Strings
    - <string> header
  - Vectors
    - <vector> header
    - Example - Vector reverse input
    - Example - RPN (Reverse Polish Notation) calculator
    - Passing Vector Parameters
    - Iterators for vector
    - Crossword Helper - uses `vector`, `string`, `ifstream`.
  - Lists
    - <list> header
  - Deques
- Associative containers
  - Maps, Multimaps
    - `pair` utility struct
    - Example - Word frequency using `map`
  - Sets, Multisets
- Adapter containers (based on other containers)
  - Stacks
  - Queues
  - Priority Queues

### Iterators

- Introduction to Iterators
- Iterator Operators
- Iterators for vector

### Examples

- Lefthand
  - Lefthand 1 - uses `string`.
  - Lefthand 2 - uses `string` and `vector`.
  - Lefthand 3 - uses `string` and `set`.
- Compress - Uses vector, string, sort.
- Printing input words in reverse order
  - Using array - for comparison.
  - Using `vector` and `string`
  - Using `stack` and `string`

## Misc Examples

- string2int function
- Word length frequency (arrays, c-strings)

## Misc

### Random numbers

- Random Numbers
- Example - Shuffle Array
- Example - Deal Cards
- Example - Random Names

### Preprocessor

- #ifdef and #ifndef

### Big-Oh Notation

- Big-Oh Introduction
- Big-Oh Examples

### Other online sources

- www.cppreference.com - Function references.
- www.codeproject.com - Many articles from beginner to advanced. Very interesting.
- www.bruceeckel.com/ has both volumes of Bruce Eckel's excellent Thinking in C++ books. Yes, the entire books are there! These aren't for real beginners, but after you've had a little bit of C++ programming, these will be very useful.
- www.cplusplus.com/doc/tutorial

Acknowledgements.