Week 5
Monday
danger of making a function call it's self
recursion
_________________
Swap function, to trade the value of two variables
__________________
compiling with g++ in linux
__________________________
global variables - can not trust them, do not use them
global constants - can not be changed so you can trust them
describe checks assignment
___________________
debugging (aka. stepping through) a c++ program in visual studio using F10 and F11
___________________
Steil variable and function name rules
  1. use camel case for variables (averageDailyBalance)
  2. use uppercase letters with underscores for constants (DAYS_IN_A_WEEK)
  3. name void functions with verbs or verb noun combinations that describe what the function does
  4. name non-void functions with nouns that describe the value being returned
__________________
type cast - sometimes used to avoid compiler warnings
__________________
Namespaces
unary scope resolution operator to get gloabl scope ::x
binary scope resolution operator to get to named scope std:::endl
using namespace std;  //poluting global namespace
using std::cout;
__________________
Examples
Assign Homework
Read Chapter 5 sections 11 - 14
Tuesday
Pseudo-Random Number Generation
Overview
  • Software must often use random numbers (e.g., creating an AI that chooses randomly between multiple choices, simulating a dice roll, etc.)
  • Computers typically use random number generators that use mathematical equations to produce pseudo random numbers, numbers that are not truly random but are nearly impossible to distinguish from truly random numbers
  • These pseudo random number generators will produce the same random numbers every time unless they are initialized with a random seed
  • The seed is often based on the current date and time since time is always changing and never repeated
rand()
srand(n)
time(NULL) - number of seconds since 00:00 hours, Jan 1, 1970
finding a random number in a range
_getch()
 
Example
Assign Homework
Read Schaum's 4.8  
 
Wednesday
Introduction to Arrays
Array declaration
   int A[5];
Array indexes (0 through 1 less than size)            
 
Arrays - how do they work in memory?
  • list is contiguous
  • variable is a "pointer" to the first item in the list
Pointer - a variable that holds an address
Passing Arrays to functions
Is an array passed as to a function by value or by reference? Explain.
"When passing an array to a function, it copies only the address of the array to a new pointer variable inside the function.  Since the copy of the pointer also points to the array, any change made to the array within the function will change the array in the calling function.  A copy of the array is not made."
Array initialization at declaration
Array initialization using loops
Using for loops with arrays
Examples
Assign Homework
 
Thursday
Checks Program Help... Design
Array initialization at declaration
   int A[5] = {1,2,3,4};
top down vs. bottom up design
  1. top down -  Start at a high level and break a problem down into sub problems.  While coding programmers often pretend they have functions to use then write them later.
bottom up - Combining small systems to build larger ones. While coding programmers often have pieces they know they need to use the challenge is how to make them fit together to solve the problem at hand.
Friday
cin >>  - reads until whitespace
   example - 1 2 3 4 5 - entered into the input stream
Arrays - how do they work in memory?
  • list is contiguous
  • variable is a "pointer" to the first item in the list
Pointer - a variable that holds an address
Passing Arrays to functions
Is an array passed as to a function by value or by reference? Explain.
"When passing an array to a function, it copies only the address of the array to a new pointer variable inside the function.  Since the copy of the pointer also points to the array, any change made to the array within the function will change the array in the calling function.  A copy of the array is not made."          
2D Arrays
Matrix example with 2 2D arrays
Examples
none