CS 1320 (Principles of Algorithm Design I):
Sample Programs
(All programs/files referenced here are available on the CS lab
machines in directory /users/blm1320/SamplePrograms.)
Programs from class
- (January 19) "Hello world" program.
- (January 21) Program to add two integers.
- (January 24) Program to "make change" (convert cents to
quarters, dimes, etc.).
- (February 4) Program to define and test a simple integer
function.
- (February 7) Improved version of "volume" program (checks for
valid input).
- (February 7) Program to check whether three integers form
the sides of a right triangle.
- (February 9, 11) Programs to test functions written in class.
- (February 14) Program to display hexadecimal representation
of integer.
- (February 21) Programs to test functions written in class.
- (February 28) Program to test largest-power-of-2 function
from class.
- (February 28) Two versions of program to compute average grade.
- C++ source for version 1 (input terminated by negative
number):
average_v1.cc.
- C++ source for version 2 (input terminated by end of file):
average_v2.cc.
- (March 13) Program to repeatedly calculate value of stock
investment.
- (March 20) Example menu-driven program.
- (March 20) Program to echo character input.
- (March 27) Program using pass-by-reference parameters.
- (March 29) Program to compare yesterday's high and low
temperatures with record highs and lows, as recorded
in file, and update file if necessary.
- (April 3) Program to print input numbers in two-column
format.
- (April 7) Program to print input numbers in reverse
order.
- (April 9) Program to simulate rolling a die. First
version performs only one trial (experiment);
second version performs a sequence of trials.
- C++ source for version 1:
roll_dice_v1.cc.
- C++ source for version 2 (not presented in class;
performs multiple trials and averages them):
roll_dice_v2.cc.
- (April 19) Program to count lines in a file.
- (April 19) "Phone book" program.
- (April 19) Function to compute length of a string,
plus test program (not discussed in class).
- (April 19) Function to decide whether two strings are the same,
plus test program (not discussed in class).
- (April 24) Recursive function to compute N factorial,
plus test program.
- (April 24) Recursive function to count whitespace characters
in a text string, plus test program.
- Not presented in class: Program to print name in a frame of stars,
demonstrating decomposing a problem into several functions.
- Not yet presented in class: More examples of recursion.
- C++ source for recursive function to compute a Fibonacci
number, plus test program:
fibonacci.cc.
- C++ source for recursive function to sum elements of an
array, plus test program:
array_sum.cc
- C++ source for recursive function to search for number
in an array, plus test program:
in_array.cc
- C++ source for a program to print numbers entered by
the user in reverse order using recursion:
print_reverse_recursive.cc.