CS 115 Examples
Alice
Fibonacci Kangaroo example
Calculating Cow example
Data Types
Example of using type cast to round 1/31/08
Example of integer overflow
Example of floating point overflow
Interesting example of the difference between float and double variables
Arithmetic
Mowing the Lawn example 1/29/08
Strange use of Increment operators
String functions
Example of string functions - reversing a sentence
Logic
Example of nested ifs
Chemistry problem - ifs - 2/26/08
Input and Output
Example of fixed, showpoint and setprecision
Example of input problem with >> and getline combined
Example of Sentinel logic reading a file
BAD Example of logic reading a file
An example
of manipulators for left, right and internal justification
Example
of forcing the user to give a useable input file name
Loops and Flags
Examples of loops
A rather nasty bug
A Problem with a Loop
Common Mistakes with Flags
Functions
example of value returning function
Example of void functions
Example of a bool function
Example of functions - the quadratic formula
Example of a value-returning function Hypotenuse
Finding distances with a function
Void Functions to draw a box
Example of functions with reference parameters
Example with functions
A Scope Question
Random numbers
Example of generating random numbers, with constant seed
Example of generating random numbers, with user-supplied seed
Example of generating random numbers, with time seed
Arrays and Sorting and Searching
Example done in lecture 11/30 - passing arrays
Example of passing arrays to functions 12/4/07
Example of passing an array as a parameter
Example of selection sort code (html file)
Example of selection sort code (cpp file)
Binary search
Designs
A Design for a Notepad Problem
Design Example 1
Design Example 2
Design with a Loop in it
Example Program Assignments and Designs
My Comments about Comments
Miscellaneous
Examples of tracing code
Programming Tips
Common Programming Errors