294x Filetype PDF File size 0.06 MB Source: personalpages.manchester.ac.uk
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
Summaries
IDEs - Dev-C++
Summary - Basic Elements - types, ...
Model programs
Summary - Expressions
Example - Celsius to Fahrenheit.
Summary - Control Flow Statements
Example - Celsius to Fahrenheit loop.
Summary - Functions
Example - Template for main.
Summary - Program Structure
Misc
Summary - Header Files
Braces
Development Techniques
Types and Expressions
Types Expressions
Integers (int, short, long, char) Summary: Expressions
Example: Converting to binary by division
Operator: sizeof
Floating Point (float, double, long double)
Bitwise Operators
Operators: Bitwise
Characters (char)
Example: convert to binary using
Reading characters
bitwise ops
Character functions -
Example: Convert to hex using bitwise
bool
ops
Enums
Exercises: ++, =, ?: Expressions
Enums
Enum Values and I/O
Control Flow
Loops Switch Statement
Examples Switch
Ex: Line of stars - count up Switch usage
Ex: Line of stars - count down Simple Calculator
Ex: Finding max of input values
Functions
Programming Problems - Reading from cin
Function Concepts
Programming Problem - cin Count Input Values
Function Structure
Programming Problem - cin Count Equal
Function return Statement
Programming Problem - cin Max and Min
Function Parameters
Programming Problem - cin Average
Function Call Order
Programming Exercise - Average Positive
Function Reference Parameters
Negative
Programming Problems
Programming Problems - Writing from a loop
Programming Problem - Convert to
Programming Problem - Print Numbers
Seconds
Programming Problem - 99 Bottles of Beer
Programming Problem - Temperature
Programming Problem - Ulam Sequence
Opinion
Programming Problems - Nested loops
Programming Problem - Convert to
Programming Problem - Print Parallelogram
Meters
Programming Problem - Figures
Programming Problem - Average 3
Programming Problem - Multiplication Table
Numbers
Programming Problem - Prompt Y/N
Exceptions
try - catch
Standard exceptions
Exception test
Input / Output
I/O streams - overview Example: File open dialog
Idiom: cin loop I/O operators - << and >>
Anti-idiom - Using cin in three places, instead of one I/O manipulators
String streams
End-Of-File (EOF)
String stream example
Reading numbers
Idiom - Separate User Interface from Logic
Reading characters
Reading lines
GUI
Reading text files
Graphical User Interfaces
Arrays
One-dimensional Arrays Sorting Arrays
Arrays Sorting
Array Examples Sort efficiency
Array Memory Diagrams Bubble Sort - Fixed passes
Array Initialization More Bubble Sorts
Passing Array Parameters Selection Sort
Arrays - Problems and Solutions isSorted
Arrays - Buffer overflow STL sort for arrays
C-Strings - arrays of char Searching Arrays
C-Strings (arrays of chars) Linear Search
Common functions Binary Search
C-string Prog exercises 1 Recursive Binary Search
C-string Prog exercises 2
Misc Array Function Examples
Here are solutions to a few problems, using separate
Example - readArray
source files.
Example - insert
C-Strings - Programming Exercise Solutions -
Example - erase
main
Example - reverse
C-Strings - Programming Exercise Solutions -
Example - push
functions
Example - pop
C-Strings - Programming Exercise Solutions -
Example - maximum
header
Example - average
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
Misc practical issues.
Multiple source files
Multiple Source Files
Pointers, References, and Dynamic Allocation
Pointers and References Dynamic allocation (new, delete)
Addresses, pointers, references Dynamic Allocation of Arrays
Pointers Dynamic Allocation of C-Strings
The NULL pointer Example: Expanding an Array
Pointer quote Dynamic allocation issues
The Name of the Song is ... Example - Dynamic C-String Allocation
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
Structs
Structs
Examples
Struct operations
Classical (non-OOP) Linked Lists
Struct Example: Time
Linked Lists - Example Using Nodes
Struct operators
Singly linked, doubly linked, class lists
Struct example 1
Combining two circular, doubly linked
Struct example 2
lists
-> operator
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 Operator Overloading
Object-Oriented Programming (OOP) Operator Overloading
OOP Terminology Overloading Assignment
Classes Overloading Derived Class Assignment
Classes Member functions
this const member functions
Example: floatVector v1
Friend functions
Visibility - public and private
Friend Functions
Data members
Overloading << and >>
Member initializers
Inheritance
Constructors and Destructors
Nothing yet
Constructors
Shallow vs Deep Copies
Copy Constructors
Destructors
Key Points - Constructors
Generic Programming
Templates Template Classes
Templates Example - CheckedArray Template
Template functions Class
Nothing yet Programming Exercises - Extend
CheckedArray
Example - CheckedArray Alternate
Style
STL (Standard Template Library) containers, iterators, algorithms
General Iterators
STL Overview Introduction to Iterators
Iterator Operators
Containers
Iterators for vector
General information
Introduction to Containers Examples
Sequence containers Lefthand
Common Sequence Container Operations Lefthand 1 - uses string.
Strings
Lefthand 2 - uses string and vector.
header
Lefthand 3 - uses string and set.
Vectors
Compress - Uses vector, string, sort.
header
Printing input words in reverse order
Example - Vector reverse input
Using array - for comparison.
Example - RPN (Reverse Polish Notation)
Using vector and string
calculator
Using stack and string
Passing Vector Parameters
Iterators for vector
Crossword Helper - uses vector, string,
ifstream.
Lists
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
Misc Examples
string2int function
Word length frequency (arrays, c-strings)
Misc
Random numbers Big-Oh Notation
Random Numbers Big-Oh Introduction
Example - Shuffle Array Big-Oh Examples
Example - Deal Cards
Example - Random Names
Preprocessor
#ifdef and #ifndef
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
publications.gbdirect.co.uk/c_book/ Has made an entire 1991 C book online freely available.
Acknowledgements.
Copyleft 2004 Fred Swartz MIT License
no reviews yet
Please Login to review.