Some of the examples in this folder will build with older versions of C++, but in many cases you will need C++14 or later.
ave.cpp: print the average of a list of
integers ave1000.cpp: same, but
using arrays (illustrating how they are passed)
round_error.cpp: illustrates why
== on floats is a bad idea
simple_time.cpp: illustrates
simple classes (along with cassert)
occurrences.cpp: count number of
times a character appears input. If build to a.exe, then
a.exe < occurrences.cpp
counts 17 semicolons, and
a.exe _ < occurrences.cpp
counts 5 underscores.
increasing-numbers.cpp:
illustrates writing an eof-controlled loop with limits
increasing-numbers-v2.cpp:
Same, but using functions.
distinct1000.cpp: count number
of distinct values in the input.
countvowels.cpp: count the
number of vowels; illustrating reading input by characters (and including
code to read from a file as well as standard input). This is the C++
version of countvowels.rb.
ave.h,
ave.cpp,
printave.cpp: illustrating
separate compilation and reference parameters
2darray.cpp: illustrates
two-dimensional arrays (really, tables) using both plain-old arrays
(int a[cols][rows];) and vectors
(vector<vector<int>>).
todo.cpp: simple todo list using
fixed-size arrays and strings.
phonebook: A class with the
interface separated from the implementation.
simple_vector.h: Simple vector code
alg-examp.cpp: illustrate
algorithm code
slist.cpp: Simply Linked List
rwh_string.cpp: simple
implementation of arbitrary-length strings
list_iterator.cpp: illustrates
iterating over a list
repeated_words.cpp:
illustrates using std::set
ave1000.cpp, but this version prompts for inputs and computes
the average of doubles
array.c: illustrates properties of arrays
points0.c, points.c:
structs in C using two different styles
messed_up.c: really odd code...
hello.c: yup
MysteryCode.java
Display.java: illustrates
reading from standard input and writing to standard output
MysteryCode.java:
illustrates that Java programs can be obfuscated as well
simp_asm_fun_call.cpp:
Windows GAS code illustrating calling a function with embedded assembly
simp_mac_asm_fun_call.cpp:
the Intel-based Mac version of the above embedded assembly
counting_bits.cpp:
C++ with assembly code to count the number of
bits set in the 2s-complement representation of an integer; the pure
assembly version (which assumes data is in %ebx) is
in counting_bits.asm.