Example Programs

bullet Simple Programs (Chapter 1)
bullet hello.cpp - An initial C++ program
bullet prog2_2.cpp - Demonstrate how to output an equation
bullet power.cpp - Demonstrates how to compute exponents in C++
bullet Examples w/Fundamental Types (Chapter 2)
bullet constant.cpp - Demonstrates literal (constants) of each of the fundamental types
bullet size.cpp - Demonstrates the size in bytes of each of the fundamental types
bullet Examples w/cin and cout (Chapter 2)
bullet   swap.cpp - Demonstrates cout to prompt for values from the user and cin to read those values into local variables
bullet   Examples w/printf and scanf (from lecture)
bullet   printf.cpp - Demonstrates printf() to print values to the terminal and to C-style string variables.
bullet   scanf.cpp - Demonstrates scanf() to input variables from the keyboard and C-style strings.
bullet strchr.cpp - Demonstrates strchr() to find a given character in a C-style string.
bullet   Control Flow:  Selection (Chapters 2 and 3)
bullet boolean.cpp - Demonstrates how to declare and use boolean variables
bullet expr.cpp - Demonstrates various types of boolean expressions
bullet selection.cpp - Demonstrates single-, two-, and multi-alternative selection (if) statements.  Also demonstrates the switch statement
bullet mathexpr.cpp - Demonstrates a switch statement
bullet   Control Flow:  Looping (Chapters 2 and 3)
bullet average.cpp - Demonstrates a while loop and also totaling a running sum
bullet fact.cpp - Demonstrates a while loop
bullet scope - Demonstrate variable scope
bullet find_largest - Demonstrate a for loop
bullet   Predefined Functions (Chapter 4)
bullet screen_control - Demonstrates I/O manipulator setw() and the use of sleep() and control characters.
bullet outputbase.cpp - Demonstrates the I/O manipulators dec, oct, and hex
bullet   Programmer-Defined Function (Chapter 4)
bullet functions.cpp - Demonstrates function prototypes and simple function definitions
bullet debug.cpp - Demonstrates how to use the C++ preprocessor for conditional compilation
bullet area.cpp/a.cpp - Demonstrates the before/after versions of a simple program with functions
bullet   Value and Reference Parameters (Chapters 4 and 5)
bullet value_parms.cpp - Demonstrates call-by-value parameter passing
bullet reference_parms.cpp - Demonstrates call-by-reference parameter passing
bullet   File and Character  I/O (Chapter 6)
bullet file_io_example.cpp - Demonstrates how to open, read, write and close files
bullet Introduction to Classes (Chapter 10)
bullet student.cpp, students.cpp - Introduces classes by demonstrating how you can combine related variables into a single structure (class) to simplify your programming.
bullet complex.h, complex.cpp, complex_app.cpp - Demonstrates a C structure for complex numbers.
bullet complex_op.h, complex_op.cpp, complex_op_app.cpp - Demonstrates a corresponding C++ class for complex numbers.
bullet   Separate Compilation (Chapter 10)
bullet See examples in "Introduction to Classes"
bullet   Arrays (Chapter 7)
bullet letter_count - Demonstrates a nested loop, character arrays, and reading "white space"
bullet arrayinit.cpp - Demonstrates the various initialization possibilities with C++ arrays
bullet find_smallest - Demonstrates a search through an array for the smallest value
bullet insert - Demonstrate how to insert an array element in the middle of the array
bullet matrix_addition - Demonstrates how to declare and access multi-dimensional arrays
bullet flip_square - Demonstrates how to access multi-dimensional arrays
bullet   Sorting (Chapter 7)
bullet random_number - Demonstrates random number generation (for sorting) and file redirection examples
bullet insertion_sort.cpp - Demonstrates array access and manipulation with sorting as the example
bullet bubble_sort.cpp - Demonstrates "bubble sort"  the easiest of the sorts to write (and also the most inefficient)
bullet quick_sort.cpp - Demonstrates how much difference a good algorithm can make
bullet   Strings and Vectors (Chapter 8)
bullet str.cpp - Demonstrates how to use getline (a string input function)
bullet strex.cpp - Demonstrates how to use each of the string member functions:  size(), substr() and find()
bullet   Introduction to Pointers (Chapter 9)
bullet Recursion (Chapter 14)
bullet fib.cpp - Demonstrates recursion in a function
bullet factorial.cpp - Demonstrates recursion
bullet Random Numbers (Appendix 4)
bullet random_numbers.cpp - Demonstrates how to generate a random number between 1 and 100
bullet Decryption Example
bullet decrypt_test.cpp - Demonstrates how to use the decrypt() function for the homework on file I/O.