Sample C++ Programs

Structured C++ programming examples:                               LINK TO HOMEWORK AND INFO  

Bubble sort: bubble.cpp ... using data: bubble.txt ... with ... output
Reading one char at a time using get(): get.cpp
Reading one line, using get(): readArray.cpp   or using getline(): readGetline.cpp ... using data: read.txt ... with ... output
Formatting using setw: format.cpp
Dynamic two dimensional array: twoDarray.cpp ... with ... output
Convert string object to char array: stringConvert.cpp
Messing around with pointer arithmetic: ptrArith.cpp
More pointer arithmetic, pointers to pointers: ptrptr.cpp
pointers to functions: ptrToFunc.cpp ... with ... output
Example using a vector from the STL: vector.cpp
Towers of Hanoi: hanoi.cpp ... with ... execution tree

Rational class:

Simple class, not documented, no overloading operators: rat.h ... rat.cpp ... ratdriver.cpp ... with output
Better class, documented, overload operators, etc.: rat2.h ... rat2.cpp ... rat2driver.cpp ... with output

Array class:

Simple int array class: array.h ... array.cpp ... arraydriver.cpp ... with output
Same int array class with pre/post condition comments: array.h ... array.cpp
Array class as a template (must put all code into the .h file):
    arraytemplate.h includes class def and implementation ... arraytemplatedriver.cpp ... with output

List class:

List class (singly linked list): list.h ... list.cpp ... listdriver.cpp ... listdata.txt ... listdata2.txt
Nodedata class: nodedata.h ... nodedata.cpp

Employee class: employee.h ... employee.cpp
List class as a template: listtemplate.h ... listtemplatedriver.cpp

Stack ADT: stack.h                  

Array implementation:   stacka.cpp  
Linked List implementation:   stackl.cpp  

Queue ADT:   queue.h

Array implementation:   queuea.cpp  
Linked List implementation:   queuel.cpp  


Using a static const data member: staticconst.cpp

Binary Search Tree:   binary search tree  

Sample Manager class:   for bridge game  

Inheritance example:

Simple example using inheritance ... consists of a base class (Fruit) and
three derived classes (Apple, Orange, Grape).   There is a linked list of Fruits.
The items start out as specific Apples, Oranges, or Grapes, then become Fruits in the list.
Inheritance allows the objects to define their own functionality.
All the code: fruit.cpp ... with output: output ... and UML diagram