CS1411 - 160 - Programming Principles I, Spring 2005
Examples
Here are some examples from class:
Chapter 1
Chapter 2 (boolean + if)
Chapter 2 (enum, switch, loop)
Chapter 3 (function basics)
- Functions for enum
- Forward declaration
- Parameter passing with global variables (bad example)
- Multiple Returns
- Parameter passing (correct way)
- Return statements
- Simple Function
- Square and Pow (see also list of math functions in book)
Chapter 4 (functions, drivers, stubs)
- Assertion
- Overload and typecast
- Celsius -> Fahrenheit
- Overloaded function
- Call-by-reference
- Function Stub
- Miles per Gallon
Chapter 5.1 (arrays)
- Grades without array
- Grades with loop
- Grades with array 1
- Grades with array 2
- Grades with array 3
- Grades with array 4
- Fill an array 1 (good quiz question!)
- Fill an array 2
Chapter 5 (more on arrays)
- Comprehensive array example
- Element of an array as function parameter
- Arrays as parameters
- Array initialization and sentinel
Chapter 5 (even more on arrays)
Random stuff
Chapter 6.1 (structs)
- Simple struct
- Struct vs. enum
- Date struct
- More on date struct
- Struct for students
- More on struct for students
- List of students
- Initialize a struct
- More on initializing a struct
Chapter 9 (C-Strings)
- simple cstring, initialized as array
- cstring initialization
- cstring input
- cstring getline
- manipulating cstrings
- comparing cstrings (strcmp)
- comparing cstrings (strncmp)
- cstring length
- cstring initialization
- cstring to upper case
- toupper printed on screen
- cstring inilialized as array
Chapter 9 (C++-Strings)
- Simple C++ string
- String assignment C vs C++
- String concatenation C vs C++
- Getline with C++ strings
- Concat of 2 c++ strings
- Convert C++ string to cstring
- Manipulating C++ strings by character
- is a palindrome example with C++ strings
Chapter 11: Separate compilation
Chapter 10: Pointers
- Simple pointers
- Pointing to different variables
- Assigning one pointer to another
- using new
- using delete
- Simple pointers with explanation
- new and delete with explanation
- dynamic array (new[], delete[])
- dynamic array as parameter
- single variable as array
- returning a dynamic array
- Pointers to structs
- Smart array using pointers
- Smart array using pointers 2
- Comparison of: Pointer, call-by-value, call-by-reference
- Different ways of passing ints: by value, by ref erence, pointer, array
Chapter 13: Recursion
- Non-recursive number printer
- Recursive number printer
- Two-way recursive number printer
- Recursive pow
- Recursive fib
- Recursive fib (multiple times)
- Counting down recursively
- Counting down and up recursively
- Halfing values
- Binary search
- Recursive counting up and down
File I/O
- Simple file output
- Output with recursion
- Using flush
- Simple file input
- Reading until eof
- Reding until eof, making sure read succeeded
- Reading, having >> in while condition
- Writing to file on root of C:
- Output with fixed width
- using setw
- more setw
- using fill to set the fill char
- using ios::left and ios::right
- Simple printing a double
- Saving flag state
- Set / clear vs. saving flag states
- Printing Money
- Printing in oct, hex, dec format
- Read in an unknown amount of numbers into a dynamic array
Exceptions
- Throwing one error message on io fail
- Throwing from a function
- the throw () declaration
- catching different types of errors
- using static_cast
- Exception review