Comp Sci Ch 9 Ch 10 Flashcards

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
Q

how does == compare vectors

A

compared elements by elements
true if same size and each element pair is equal

26
Q

how should you reverse a vector

A

–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
Q

vectors with….should be passed by

A

10 by reference
then check if should be constant

28
Q

what is an object

A

a grouping of data (variables) and operations that can be preformed on that data (functions) in a class

29
Q

what is abstraction

A

having a user interact with an item at a high level with lower level internal details hidden from user

30
Q

what is abstraction also thought of

A

info hiding or encapsulation

31
Q

what does abstraction mean in a class

A

hiding entire groups of functions and variables exposing only certain functions to a user

32
Q

what is abstract data type

A

a data type whose creations and update are constrained to specific well-defined operations - use a class to implement

33
Q

what is a class

A

defines a new type that can group data and functions to form an object

34
Q

what are public member functions

A

indicate all operations a class user can preform on the object

35
Q

how to declare a class

A

class name {
public:
functions
return type name ( type parameter)
private:
typically variables that public functions use;
};

36
Q

how to call a class in main

A

class name object name;

object name. public functions (parameters);

37
Q

what is the dot operator / member access operator do

A

used to invoke a function on an object

38
Q

the string data type is an example of a …

A

class

39
Q

what are private data members

A

variables that member functions can access but class user cannot

40
Q

main can access…but cannot access

A

public member functions
private data members

41
Q

each function declaration under public in a class needs to be….

A

defined outside of the class

42
Q

the function declaration in the class has and the function definition has

A

declaration -
return type name ( type parameter);

definition-
return type class :: name (type parameter) {
statements
}

43
Q

when defining a member function with parameters you do not need to…

A

declare the variables you will use because they have been declared in the class, just call them

44
Q

a class public functions are commonly classified as either

A

mutator or accessors

45
Q

what is a mutator

A

function may modify (mutate) a class data member
–sets the value

46
Q

what is an accessor

A

function accesses data members but does not modify data members
–gets the value

47
Q

what are private helper functions

A

private functions to help public functions carry out tasks
—cane be called by private and public , not by main

48
Q

can you initialize data members in class definition

A

yes, any variable declared in that class type will have those initial values

49
Q

what is a constructor, where called and how defined, and what happens if there is no user defined one

A

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