Comp Sci Ch 9 Ch 10 Flashcards

(49 cards)

1
Q

what types of ordered list types does c++ suppport

A

arrays and vectors

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

how do you declare vectors

A

vector<type> name (elements)</type>

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

how do you access an index of a vector

A

name.at(i);

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

why are vectors safer than arrays

A

because it uses () that check the .at while the [] in arrays are not
AND
arrays do not have the size feature

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

what is a vector

A

an ordered list of items of a given data type

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

what is an element in a vector

A

each item

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

what do you need to include to use vectors

A

include < vector>

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

If a vector has N elements
what is the last element index

A

N - 1

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

if a vector has last index N, how many elements does it have

A

N + 1

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

The index of a vector to access must be

A

an unsigned int type and not a floating type number

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

what does size return for a vector

A

the number of elements

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

when a vector is initialized with a number of elements

vector<type> name (numOfElements);</type>

what are the elements initialized to

A

0

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

how to initialize all the elements of a vector to one value

A

vector <type> name ( numOfElements, valueToSetTo);</type>

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

how to initialize each element in a vector to different values

A

vector <type> name = {num, num, ...};</type>

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

for a large vector how should you initialize it

A

a for loop

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

normal loop header for iterating through a vector

A

for ( unsigned int i = 0; i < v.size(); ++i) {
//loop body;
}

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

you already have the vector size
how should you input stuff into the vector

A

for ( unsigned int i = 0; i < v.size; ++i) {
cin&raquo_space; v.at(i);
}

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

If you have multiple vectors….

A

both vectors should have same amount of elements

–0 corresponds to 0 and 1 to 1 and so on

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

how do you append items to a vector

A

.push_back

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

how to use .back()

A

to return a vectors last element and vector is unchanged

21
Q

what does .pop_back() do

A

removes last element and changes vector

22
Q

does the size of a vector have to specified in the declaration

A

no
instead of (numElements) just ;

23
Q

what is .resize() for

A

to change the size of the vector

24
Q

how does = compare vectors

A

copies all of one vector to another vector

25
how does == compare vectors
compared elements by elements true if same size and each element pair is equal
26
how should you reverse a vector
--iterate size/2 --need a temp value to hold the value at i --set that i equal to the last value size - 1- i --make the last element the ---temp value
27
vectors with....should be passed by
10 by reference then check if should be constant
28
what is an object
a grouping of data (variables) and operations that can be preformed on that data (functions) in a class
29
what is abstraction
having a user interact with an item at a high level with lower level internal details hidden from user
30
what is abstraction also thought of
info hiding or encapsulation
31
what does abstraction mean in a class
hiding entire groups of functions and variables exposing only certain functions to a user
32
what is abstract data type
a data type whose creations and update are constrained to specific well-defined operations - use a class to implement
33
what is a class
defines a new type that can group data and functions to form an object
34
what are public member functions
indicate all operations a class user can preform on the object
35
how to declare a class
class name { public: functions return type name ( type parameter) private: typically variables that public functions use; };
36
how to call a class in main
class name object name; object name. public functions (parameters);
37
what is the dot operator / member access operator do
used to invoke a function on an object
38
the string data type is an example of a ...
class
39
what are private data members
variables that member functions can access but class user cannot
40
main can access...but cannot access
public member functions private data members
41
each function declaration under public in a class needs to be....
defined outside of the class
42
the function declaration in the class has and the function definition has
declaration - return type name ( type parameter); definition- return type class :: name (type parameter) { statements }
43
when defining a member function with parameters you do not need to...
declare the variables you will use because they have been declared in the class, just call them
44
a class public functions are commonly classified as either
mutator or accessors
45
what is a mutator
function may modify (mutate) a class data member --sets the value
46
what is an accessor
function accesses data members but does not modify data members --gets the value
47
what are private helper functions
private functions to help public functions carry out tasks ---cane be called by private and public , not by main
48
can you initialize data members in class definition
yes, any variable declared in that class type will have those initial values
49
what is a constructor, where called and how defined, and what happens if there is no user defined one
called automatically when a variable of that class type is declared and which can initialize data members --called inside public as class name() (no return type) --defined out of the class as class name :: class name (){ initializing data members } if no user defined one, complier implicitly defines a default but having no statements