CS Week 1 - Vector and Functions Review Flashcards

1
Q

Radix sort

A

sort smaller pieces, than sort those pieces
- sorting last names, sort 26 stacks, put together sorted

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

modular development

A

process of dividing a program into separate modules that can be developed and tested separately and then integrated into a single program

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

incremental development

A

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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

function stub

A

function definition whose statements have not yet been written
- cout fixme
- helps capture the correct high-level behavior

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

function

A

defined to compute a mathematical calculation involving several numerical parameters and a number result

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

difference in using a function in main

A

void - a statement that calls it to cout or updates variables
any other type - a returned value use as an expression or cout it

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

unit testing

A

process of individually testing a small part of a program, typically a function

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

test bench

A

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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

test vector

A

each unique set of input values
- make sure you use border cases and inputs that thoroughly exercise the program

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

what does assert() do, how to include and use

A
  • 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
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

pass by value

A

arguments value is copied into a local variable for the parameter

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

pass by reference

A

does not create a local copy of the argument, refers directly to the arguments
variable memory location
append & to type

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

what is pass by reference for

A

changing the original variable
more than one return
big data types like strings and vectors

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

reference variable

A

variable type that refers to another variable
type& name = other;

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

scope

A

the name of a defined variable or function item is only visible to a part of a program
-starts after it is declared

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

global variable and why it should be avoided

A

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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
17
Q

side effects

A

a function that updates a global variable has side effects that go beyond its parameters and return value

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
18
Q

function declaration

A

declared before main with everything but { } and statements
- ends with ;

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
19
Q

rand() and what to include

A

generates a random number
# include <cstdlib>
range from 0 to RAND_MAX</cstdlib>

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
20
Q

what to use to make the range of a random number

A

%

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
21
Q

how many possible values in rand() % N and what range

A

N possible values from 0 to N-1

22
Q

specific range of a random number

A

rand() % (large - small + 1) + small

23
Q

pseudo random

A

not actually but having the appearance of
- the ints generated by rand()

24
Q

how to get different sequence of random numbers and how each time

A

srand( seedYouWant);
- called once before rand()

srand(time());
#include <ctime></ctime>

25
vector and what to include
ordered list of items of a given data type - an object #inlcude
26
element
each item in a vector
27
declare a vector with a size, with the same value, and all different values
vector name (numElements); vector name (numElements, value); vector name = {value, value, ...};
28
how to find vector size
name..size();
29
how to know if a vector is empty
name.empty() - returns a bool - 0 - false - 1- true
30
how to access an element in a vector and how to nth element
name.at(index); index of nth element = n - 1
31
difference between using v[index] and v.at(index)
v[index] faster but does not check if index is legal - not safe v.at(index) check is an index is legal - slower but safer
32
iterating through a vector
iterate .size() times
33
how to hold aside memory for a vector and why
name.reserve(amount); - does not change size, just holds memory - when you add another index, it makes a copy of it all in new memory, give compiler an idea/guess of what memory to hold aside
34
how to add a new element to a vector
v.push_back(elementToAdd);
35
how to add an element to the beginning of a vector
v.push_front(elementToAdd);
36
how to find/access the last element of a vector
v.back(); - returns last element
37
how to get rid of the last element of a vector
v.pop_back();
38
why can .at() be used on both side of =
because you can change its value and use its value
39
vector copy operation
= vecB = vecA b is a copy of a
40
vector equality operation
== vecB == vecA compares a and b
41
how to reverse a vector
iterate .size() / 2 times temp val = .at(i) .at(i) = .at( .size() - 1- i); .at( .size() - 1 - i ) = temp val
42
auto
tells compiler to determine the variables type using the value we give it auto v = 2; compiler now knows its type can use auto in a loop with this variable - this is the context you need to use auto elsewhere
43
how to print the type of a variable
typeid( variableName).name()
44
types of d, i, and PKc
d - double i = int PKc = string (point, const, char) - a string is a const char*
45
range based loop
- does not use an index - copy first value of vector into a variable and run the loop until there are no more elements in the vector for ( type variable : vector) { cout << variable; } ---------------------------------------- - use const and & so that variable is not changed and it just reads vector - when variable is called, go find the address for ( const auto(or type)& variable : vector) { sum += x; } - add auto so that x holds the right type ----------------------------------------- - if variable is a reference, it will change the vector directly for (type& n1 : vector) { type n2; cin >> n2; n1 = n2; }
46
what is cerr
not for normal output errors
47
what allows for this to work : vector name; and how would it look different if we did not include what makes it work
using namespace std; std : vector name;
48
two first statements
include using namespace std;
49
how to test your input
if ( !cin) { cerr << "bad" << endl; }
50
.good(); .eof(); .fail(); .bad();
good - returns true if no stream errors have occurred eof - returns value of eofbit if end of line reached fail - returns true if fail bit or bad bit is set/error for previous operation bad - returns true of bad bit is set, indicating the stream is bad
51
if ( conditional ) break; if ( conditional) continue; and where can you use these
- get out of loop - skip this iteration - in a loop before all other statements
52
look over ch2, ch 4, ch 5, CH 6!!, ch 7, ch 8, ch 9 from 10A
:)