Select this to skip to main content [CSUSB] >> [CNS] >> [Comp Sci] >> [R J Botting] >>
[Blog] || [Plan] || [Research] || [Teaching] || [Searches] Wed Nov 10 07:43:17 PST 2004
Copyright(2004). Copy and use as you wish but say where you found it. Make links as you need.

Use your browser searching button or command to find examples on the topic that interests you, or just explore...

  • A Classic first program analysed
  • A Genric Class or Template Example
  • Arith_float_collection.h: Arrays of floating point numbers with addition and subtraction between them. Uses template and member functions.
  • A structure with a ++ operator and print function by Ron Paquette
  • program that uses structs and strings to record data baout people by Stephen Widdows
  • A program demonstrating the meaning ofthe arguments of 'main'
  • An example of a bad C++ program. It works but it is still a bad program (Why?)
  • One of the best programs that soes the same thing as, but explains why and what-for in detail.
  • Some simple for loops
    Nasty 'for' loop: iterative but confusing.
  • To show how to input a line of characters one character at a time
  • A second way to do the above
  • And a second way to read characters...
  • An example of bad style.
  • An example of better style.
  • An example of using input and output streams
  • A function used in the above program.
  • Do-it-yourself iinput/output manipulators written by Lori Walker
  • An example of output manipulation: Dollars and Cents Formats
  • A test of if you understand functions and function calls. Also needs a copy of
  • An Example of a Dynamic array class by Lori Walker
  • matrix.cpp: An Example of a Dynamic 2 dimensional array class
  • An example of file input/output and bitmanipulation by Stephen Widdows
  • A puzzle testing your knowledge of function calls
  • Another test of your understanding of function calls with arguments
  • An example of how you can use exceptions/try/throw/catch to terminate a loop
  • An example of a faster algorithm for int powers of integers
  • A simple example of a for loop that adds up a sequence of numbers.
  • Example of converting an int variable to floating point
  • Examples of many different output formats circa 1990s An experiment of many combinations of IO formats More.... formats.cpp: Examples of many different output formats (IDIC!)
  • Functions: An exercise in how functions are declared, called and defined. Can you predict the output?
    More exerrcise where the functions have simple arguments. || || || || || || || fun.trace: || || Used in A test of if you understand functions and function calls.
  • Advanced Functions:
    Passing a function as an argument to a function: in C and in C++
    Returning an reference as a function value:
    (with thanks to Richard Assal who wrote these and sent them to me).
  • Boolean:
  • and how to parse it
  • A first C++ Attempt at the Towers of Hanoi. Please Improve! An iterative but confusing Towers of Hanoi program. Not for the faint of heart.
  • The traditional Hello, World! program.
    and variations
    hello.cpp: Using fstream for Out and Input of file Hello.txt
    hello.cpp: Using fstream for Out and Input of file Hello.txt
    Classic Code plus an analysis of what it means.
  • An example of a buggy program.... includes a compound if statement
  • fstream Input/Output:
  • An experiment of many combinations of IO formats
  • How the state of an iostream chages.... You feed it data and the successive states are printed. Will accept any data as input.
  • As above but when the input is supposed to be integers only...
  • infail.cpp: One way to handle user errors and end of file -- fail() and eof().
  • testStreamIterators2.cpp: Using the Standard C++ Library to input and output some numbers by copying.
  • copy.cpp: using character get and put to copy files. Opening and clossing files.
  • testStreamIterators.cpp: Using the Standard C++ Library to input and output some numbers by copying into and out of a vector buffer.
  • An example of how to confuse people by using C arrays in a wierd way.
  • Kitten is a small cat. In UNIX cat copies a file so...
  • kbhit.c: How to detect key strokes in UNIX/Linux.
  • Lab experiments: || || || || ||
  • life.doc: Documentation for Conway's Game of Life The first prototype version for Conway's Life The second prototype for Life... using pointers to elements in arrays to speed things up. The Latest version of Conway's Life
    life3.cpp: An ANSI C++ version of Conway's Life
  • Using the Standard Template Library (STL) Lists
  • A simple exercise... converting metric areas to square yards
  • A batch version of the above program.
  • A very simple program... read 3 chars and output them in reverse order.
  • The group Z mod 5 by Ketherine Scott. Plus its documentation: mod5.doc:
  • money.h: A description of the Money class. #include this header in any program that uses the class Money.
  • A body for the Money Class above. Can be compiled separately and linked into a main program. This version is designed to make arithmetic efficient.
  • moneyv.h: An example of an abstract class that can be used for several different purposes: Money is an international concept, with different rules for each nation. Dollars is one form of Money.
  • This implements the abstract money and dollars classes described above.
  • The Game of Nim:,,, nimturn.h.
  • A Payroll example. How to handle files in C++
  • A simple data structure... modelling a family tree in a simple but OO way.
  • This program tests your understanding of simple pointers. You should be able to figure the things that can not be predicted and the things that can be predicted. Also you should be able to say what the predictable values actually are.
  • Processing a file of employee data:
  • An Example of the complex restrictions on the use of 'protected' data in an object. From The Annotated Ref Manual.
  • Old Quiz Questions/Examples
  • Virtual functions made obvious by the design of a bowl of Rice Crispies - each object knows whether it should Snap, Crackle, or Pop!
  • Run Time Type Identification example (RTTI). Each object and each pointer knows what type of object it is, or that it points at.
  • scopes.cpp: Demonstrates how nested scopes allow several meanings for one variable.
  • The shortest program to output "hi"
  • An example of a STUB: A function that can be used to test a main program but will have to be replaced to some real work later.
  • Stephen Widdows example of a class of strings and a way to sort them.
  • Timing a collection of classic sort algorithms with and without the C++ Standard Library:
    Bubble Sort
    Heap Sort
    Insertion Sort
    Sort STL list
    Merge Sort
    Sort using a Multiset
    Sort using a priority Queue
    Quick Sort
    Selection Sort, Selection Sort(2)
    Sorting a vectore
    Note. some words/symbols have been deleted from these to make you think about the code
  • Two different algorithms for finding the best integer square root of an integer. and Test programs: and and
  • Using the Standard Template Library (STL) Lists
  • gin_stack: A generic templatized stack wrapped arround the STL vecto and a test program (that should crash) gtin_stack.cpp for it. The STL stack is more complex but similar.
  • Example of using strcmp - Lori Walker
  • stringFind.cpp: How to use string::find(string) to see if one string can be found in another string.
  • The main program for testing a simple Generic Stack Class - that you have to supply as include file ''
  • timing.cpp: How time a processusing ctime or time.h.
  • Generic Maximum function - a template function example.
  • Tyranosaurus Rex: An attempt at a recursive template... this is OK according to the standard, but is your compiler up to standard?
  • A Vector Class. Header file: vector.h and the body of the class:
  • Examples of virtual functions:, . . ., . . .
  • Some classes that identifier themselves at run time: what was compiles (the UNIX 'what' command), and when asked to print their parentage. Also ready to work with the UNIX Source Code Control System(SCCS). Good for large projects done by a group of people.
  • A simple example of how void functions are declared. called, and defined.
  • An example of the differences between call by value, reference, and pointer. What values can you predict and which can not be predicted precisely?
  • Hello World (Again!)
  • A simple example of a class of Widgets (Not X-Widgets...)
  • Another Class of Widgets
  • Two nice programs that display wallpaper patterns on the screen: and