[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
Array.cc: 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.
BigInt.cc: A structure with a ++ operator and print function by Ron Paquette
address.cc:A program that uses structs and strings to record data baout people by Stephen Widdows
args.cc: A program demonstrating the meaning ofthe arguments of 'main'
bad.cc: An example of a bad C++ program. It works but it is still a bad program (Why?)
best03.cc: One of the best programs that soes the same thing as bad.cc, but explains why and what-for in detail.
bresenham.cc: Some simple for loops
Nasty 'for' loop: hanoi2.cc: iterative but confusing.
charlene.cc: To show how to input a line of characters one character at a time
charlie.cc: A second way to do the above
charline.cc: And a second way to read characters...
coins.bad.cc: An example of bad style.
coins.cc: An example of better style.
copyfile.cc: An example of using input and output streams
copyline.cc: A function used in the above program.
diy.manip.cc: Do-it-yourself iinput/output manipulators written by Lori Walker
dolman.cc: An example of output manipulation: Dollars and Cents Formats
driver.cc: A test of if you understand functions and function calls. Also needs a copy of
fun2.cc.
dynarray.cc: An Example of a Dynamic array class by Lori Walker
encrypt.cc: An example of file input/output and bitmanipulation by Stephen Widdows
enigma.cc: A puzzle testing your knowledge of function calls
ex18.cc: Another test of your understanding of function calls with arguments
except.cc: An example of how you can use exceptions/try/throw/catch to terminate a loop
fast.pow.cc: An example of a faster algorithm for int powers of integers
fig5.15.cc: A simple example of a for loop that adds up a sequence of numbers.
float.cc: Example of converting an int variable to floating point
formats.cc: Examples of many different output formats (IDIC!)
Functions: av26.cc: An exercise in how functions are declared, called and defined. Can you predict the output?
More exerrcise where the functions have simple arguments.
av27.cc
|| ex03a.cc
|| 03b.cc
|| 03c.cc
|| 03d.cc
|| fun.cc:
|| fun.ref.cc:
|| fun.trace:
|| fun.trace.cc:
||fun2.cc:
Used in driver.cc: 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:
returnaddress.cc
(with thanks to Richard Assal who wrote these and sent them to me).
Boolean: george.cc:
giomanip.cc:
grading.cc:
greeting.cc and how to
parse it
hanoi.cc: A first C++ Attempt at the Towers of Hanoi. Please Improve!
hanoi2.cc: An iterative but confusing Towers of Hanoi program. Not for the faint of heart.
The traditional Hello, World! program.
Theme
hello.cc:
and variations
hello.bad.cc:
hello_spaced.cc:
hello.cpp: Using fstream for Out and Input of file Hello.txt
Classic Code plus
an
analysis of what it means.
illogical.cc: An example of a buggy program.... includes a compound if statement
fstream Input/Output: fq.cc.
iomanip.cc: An experiment of many combinations of IO formats
iostates.cc: How the state of an iostream chages.... You feed it data and the successive states are printed. Will accept any data as input.
iostates2.cc: 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.
testStreamIterators.cpp: Using the Standard C++ Library to input and output some numbers by copying
into and out of a vector buffer.
joke1.cc: An example of how to confuse people by using C arrays in a wierd way.
kitten.cc: Kitten is a small cat. In UNIX cat copies a file so...
kbhit.c:
How to detect key strokes in UNIX/Linux.
Lab experiments: lab05a.cc ||
lab06a.cc ||
lab06b.cc ||
lab07a.cc ||
lab07b.cc ||
lab09.cc.
life.doc: Documentation for Conway's Game of Life
life1.cc: The first prototype version for Conway's Life
life2.cc: The second prototype for Life... using pointers to elements in arrays to speed things up.
life.cc: The Latest version of Conway's Life
life3.cpp: An ANSI C++ version of Conway's Life
lists.cc: Using the Standard Template Library (STL) Lists
metric.cc: A simple exercise... converting metric areas to square yards
metric_batch.cc: A batch version of the above program.
mirror.cc: A very simple program... read 3 chars and output them in reverse order.
mod5.cc: 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.
money0.cc: 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.
moneyv.cc: This implements the abstract money and dollars classes described above.
The Game of Nim:
nim.cc,
nim.sh,
nimturn.cc,
nimturn.h.
payroll.cc: A Payroll example. How to handle files in C++
people.cc: A simple data structure... modelling a family tree in a simple but OO way.
point.cc: 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: prcsemp1.cc:
protected.cc: An Example of the complex restrictions on the use of 'protected' data in an object. From The Annotated Ref Manual.
Old Quiz Questions/Examples
rtti.cc: Virtual functions made obvious by the design of a bowl of Rice Crispies - each object knows whether it should Snap, Crackle, or Pop!
rtti.cc: Run Time Type Identification example (RTTI). Each object and each pointer knows what type of object it is, or that it points at.
short.cc: The shortest program to output "hi"
skipnwln.cc: 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.
sorts.cc: 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.
sqrt1.cc and
sqrt2.cc.
Test programs: tsqrt1.cc and
tsqrt.cc and
tsqrt2.cc:
lists.cc: 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.
strcmp.cc: 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.
test_stack.cc: The main program for testing a simple Generic Stack Class - that you have to supply as include file 'tstack.cc'
timing.cpp:
How time a processusing ctime or time.h.
tmax.cc: Generic Maximum function - a template function example.
trex.cc: 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:
vector.cc.
Examples of virtual functions:
virtual_fun.cc, . . .
vf.cc, . . .
vmf.cc.
vn.cc: 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.
void.fun.cc: A simple example of how void functions are declared. called, and defined.
vrp.cc: An example of the differences between call by value, reference, and pointer. What
values can you predict and which can not be predicted precisely?
w1.cc: Hello World (Again!)
w3.cc: A simple example of a class of Widgets (Not X-Widgets...)
w4.cc: Another Class of Widgets
Two nice programs that display wallpaper patterns on the screen: wallpaper.cc and
wallpapr.cc: