CS Week 1 - Vector and Functions Review Flashcards
Radix sort
sort smaller pieces, than sort those pieces
- sorting last names, sort 26 stacks, put together sorted
modular development
process of dividing a program into separate modules that can be developed and tested separately and then integrated into a single program
incremental development
process in which a programmer writes, compiles, and tests a small amount of code, then writes compiles and tests a small amount more and so on
function stub
function definition whose statements have not yet been written
- cout fixme
- helps capture the correct high-level behavior
function
defined to compute a mathematical calculation involving several numerical parameters and a number result
difference in using a function in main
void - a statement that calls it to cout or updates variables
any other type - a returned value use as an expression or cout it
unit testing
process of individually testing a small part of a program, typically a function
test bench
a separate program whose sole purpose is to check that a function returns the correct output values for a variety of inputs
- used to conduct unit testing
test vector
each unique set of input values
- make sure you use border cases and inputs that thoroughly exercise the program
what does assert() do, how to include and use
- tests your function in main
# include <cassert>
assert ( functionCall(arguments) == correct output );</cassert> - if false, exits and tells you the line number and expression
- or cout that you are testing the input and the expected output and what you got by calling the function
pass by value
arguments value is copied into a local variable for the parameter
pass by reference
does not create a local copy of the argument, refers directly to the arguments
variable memory location
append & to type
what is pass by reference for
changing the original variable
more than one return
big data types like strings and vectors
reference variable
variable type that refers to another variable
type& name = other;
scope
the name of a defined variable or function item is only visible to a part of a program
-starts after it is declared
global variable and why it should be avoided
variable declared outside
any function
- reaches into functions
- better for constants
-a local defined with same name than global is ignored AND
-if a function changes it, its effects go beyond its return and parameters
side effects
a function that updates a global variable has side effects that go beyond its parameters and return value
function declaration
declared before main with everything but { } and statements
- ends with ;
rand() and what to include
generates a random number
# include <cstdlib>
range from 0 to RAND_MAX</cstdlib>
what to use to make the range of a random number
%