CS150 Intro C++ Flashcards

1
Q

The value in ________ local variable is retained between function calls

 a. a global
 b. an internal 
 c. a static 
 d. a dynamic
 e. no
A

ch6-2

a static

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

When a function just needs to use a copy of an argument passed to it, the argument should normally be passed

 a. by variable.
 b. by value. 
 c. by reference. 
 d. as a string
A

ch6-2

by value.

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

When used as a parameter, a ________ variable allows a function to access and modify the original argument passed to it

 a. static
 b. value
 c. reference
 d. floating-point 
 e. default value
A

ch6

c. reference

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

True/False:

It is possible for a function to have some parameters with default arguments and some without.

A

ch6

True

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

Two or more functions may have the same name provided that

 a. they do different things.
 b. one has a prototype and the other doesn't.
 c. their parameter lists are different. 
 d. their return types are different.
 e. either C or D is true.
A

ch6

their parameter lists are different.

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

When more than one function has the same name they are called ________ functions.

 a. overloaded
 b. renamed
 c. parallel
 d. identical e. sister
A

ch6

overloaded

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

The ________ statement causes a function to end and the flow of control to move back to the point where the function call was made.

 a. end
 b. break
 c. continue
 d. return 
  e. exit
A

ch6

return

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

True/False:

If a function has no return statement, the flow of control moves to the next function in the file when the closing brace of the function body is reached.

A

ch6

False

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

The ________ function causes the entire program to terminate, regardless of which function or control mechanism is executing.

 a. terminate()
 b. return()
 c. continue()
 d. exit() 
 e. break()
A

ch6

a. terminate()

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

A ________ is a program module whose purpose is to test other modules by calling them.

 a. stub
 b. driver
 c. main function
 d. dummy program
 e. pseudocode routine
A

ch6

driver

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

Once a class is declared, how many objects can be created from it?

  a. 1
  b. 2
  c. Many
  d. None
A

ch7

Many

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

True/False:

Object‐oriented programming is centered around objects that include both data and the func ons that operate on them.

A

ch7

True

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

ADT stands for ________ Data Type.

 a. Abstract 
  b. Action
  c. Algorithmic 
  d. Automatic
  e. None of the above
A

ch7

Abstract

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

In an ADT the implementation details are ________ the interface through which a program uses it.

a. a part of
b. determined by
c. kept separate from
d. used by
e. None of the above

A

ch7

kept separate from

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

Objects permit data hiding. This means they can keep function outside the class from

a. directly accessing the data.
b. changing the data.
c. knowing the names of the variables holding the data.
d. deleting the data.
e. doing all of the above

A

ch7

doing all of the above

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

True/False:

A class declaration provides a pattern for creating objects, so when a class is declared it automatically creates an object.

A

ch 7

False

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

When three different objects of a particular class are created, they are said to be separate______ of the class.

a. members
b. ADTs
c. instances
d. children
e. None of the above

A

ch7

instances

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

In OOP terminology, an object’s member variables are often called its _____, and its member functions are sometimes referred to its _____.

a. values, operators
b. data, activities
c. attributes, activities
d. attributes, methods
e. values, activities

A

ch7

attributes, methods

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

When the body of a member function is defined inside a class declaration, it is call a(n) _____ function.

a. static
b. global
c. inline
d. conditional
e. constructor

A

ch7

inline

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

True/False:

A constructor is a public class function that is automatically invoked (i.e., called) whenever a class object is created.

A

ch7

True

21
Q

True/False:

A class can only have one constructor.

A

ch7

False

22
Q

When a constructor does not require that any arguments be passed to it, it is called a(n) ________ constructor.

a. empty
b. default
c. stand‐alone
d. zero-element
e. useless

A

ch7

default

23
Q

A(n) ______ member function can be called by a statement in a function that is outside the class.

a. declared
b. public
c. private
d. inline

A

ch7

public

24
Q

Accessors are sometimes called ________ functions and mutators are sometimes called ________ functions.

a. set, get
b. get, set
c. public, private
d. private, public
e. regular, inline

A

ch7

get, set

25
Q

If Circle is the name of a class, which of the following statments would create a Circle object named myCircle?

a. myCircle Circle;
b. myCircle Circle();
c. circle myCircle;
d. Circle myCircle();
e. None of the above

A

ch7

circle myCircle();

26
Q

A structure variable is similar to a class object in which of the following ways?

  a. It has member data that is usually private and    accessed through public member functions.
 b. Its data can be initialized with a constructor.
  c. It can be passed to a function or returned from a function. 
d. All of the above.
 e. B and C, but not A.
A

ch7

B and C, but not A

27
Q

Which of the following correctly declares an array?

  a. int anarray[10]; 
  b. int anarray;
  c. anarray{10}; 
 d. array anarray[10]
A

ch8

int anarray[10];

28
Q

What is the index number of the last element of an array with 29 elements?

 a. 29
  b. 28
  c. 0
 d. Programmer­defined
A

ch8

28

29
Q

Which of the following is a two-dimensional array?

 a. array anarray[20][20];
  b. int anarray[20][20]; 
  c. int array[20, 20];
 d. char array[20];
A

ch8

int anarray[20][20];

30
Q

Which of the following correctly accesses the seventh element stored in foo, an array with 100 elements?

 a. foo[0];
 b. foo; 
  c. &foo;
 d. foo[1];
A

ch7

&foo;

31
Q

Given the following definition: double num [7];
how many values will that array hold?

 a. 7
 b. 6
 c. 8 
 d. infinite
A

ch 8

7

32
Q

Given the definition:
double num[7];
what is the greatest index number?

 a. 7
 b. 6
 c. 8
 d. n/a
A

ch8

6

33
Q

Given the definition,
double num[7];
how many values will that array hold?

 a. 7
 b. 6
 c. 8
A

ch 8

7

34
Q

What is the correct way to initialize values in an array?

 a. my_array [5] = (5,3,4,2,7); 
 b. my_array [5] = {5;3;4;2;7};
 c. my_array [5] = {5,3,4,2,7}; 
  d. my_array [5] = [5,3,4,2,7];
A

ch8

my_array [5] = {5, 3, 4, 2, 7};

35
Q

In my_array [5] = {5, 3, 4, 2, 7}; what is the value of,
my_array [2] ?

a. 7
b. 3
c. 4
d. 2

A

ch8

4

36
Q

What is the most efficient way to assign or print out arrays?

a. loops
b. functions
c. pointers

A

ch8

loops

37
Q

A _____ is a method of locating a specific item in a collection of data.

a. search algorithm
b. linear search
c. binary search
d. bubble sort
e. sorting algorithms
f. ascending

A

ch9

search algorithm

38
Q

The _____ is a very simple alggorithm. Sometimes called a sequential search, it uses a loop to sequentially step through an array, starting with the first element.

a. search algorithm
b. binary search
c. bubble sort
d. sorting algorithms
e. linear search
f. ascending

A

ch9

linear search

39
Q

Instead of testing the array’s first element, this algorithm starts with the element in the middle, in other words this algorithm repeatedly divides the portion of an array being searched in half.

a. search algorithm
b. linear search
c. sorting algorithms
d. binary search
e. bubble sort
f. ascending

A

ch8

binary search

40
Q

_____ are used to arrange data into some order.

a. search algorithm
b. linear search
c. sorting algorithms
d. binary search
e. bubble sort
f. ascending

A

ch8

sorting algorithms

41
Q

Sorting data in _____ order means placing the values in order from lowest to highest.

a. search algorithm
b. linear search
c. sorting algorithms
d. binary search
e. bubble sort
f. ascending

A

ch8

ascending

42
Q

The _____ is inefficient for large arrays because repeated data swaps are often required often required to place a single item in its correct position.a. search algorithm

b. linear search
c. sorting algorithms
d. binary search
e. bubble sort
f. ascending

A

ch8

bubble sort

43
Q

How do we compare different implementations of a program ? (Choose all that apply)

a. Speed
b. Time
c. Size
d. Programming Language

A

ch9-2

Time
Size

44
Q

What is the run time analysis of the below program?
Finish the formula by providing the value that belongs in the (?)

/** Fills the Bottle */
public void fill (double amount) {
     int p = amount;         ----------->  c[1]
     int i = 1;                      ----------->  c[2]      
     int j = 1;                      ----------->  c[2]
     p = p * j;                     ----------->  c[3]
     j++;                             ----------->  c[4]
}
total = c[1] + 2c[2] + c[3] + c[4]                            
f(n) = (_?_) [T]
A

ch9-2

c

or

f(n) = c[T]

NOTES:
* superscript
[] subscript

https://www.youtube.com/watch?v=chZNdhO6Ifw&list=WL&index=3

45
Q

What is the run time analysis of the below program?
Finish the formula by providing the value that belongs in the (_ ? ? _)

/** Fills the Bottle */
public void fill (double amount) {
     int p = amount;         ----------->  c[1]
     int i = 1;                      ----------->  c[2]
     int j = 1;                      ----------->  c[2]
     while (i < n){              ----------->  c[3] x n
          p = p * j;               ----------->  c[4] x n
          i++                       ------------>  c[5] x n
      }
      j++;                            ----------->  c[4] x n}
}
total = c[1] + 2c[2]   + (c[3]  + c[4]  + c[5] )n + c[4]          
f(n) = (_ ? ? _)
A

ch9-2

c[T1]n + c[T2]

or

f(n) = c[T1]n + c[T2]

NOTES:
* superscript
[] subscripts

https://www.youtube.com/watch?v=chZNdhO6Ifw&list=WL&index=3

46
Q

What is the run time analysis of the below program?
Finish the formula by providing the value that belongs in the
(_ ? ? ? _)

/** Fills the Bottle */
public void fill (double amount) {
     int p = amount;           ----------->  c[1]
     int i = 1;                        ----------->  c[2]
     while (i < n){                ----------->  c[3] x n
          int j = 1;                   ----------->  c[2] x n 
          while (j < i){            ----------->  c[3] x n x n
          p = p * j;                 ----------->  c[5] x n x n
          j++;                         ----------->  c[4] x n x n
    }
    j++;                               ----------->  c[4] x n   
 }
}
total = C[1] + C[2]   + ( _ ? ? ? _ ) n + ( c[3] + c[5]+ c[4] ) n^2                    
f(n) = c[T1]n^2 + c[T2]n + c[T3]
A

ch9-2

c[3] + c[2] + c[4]

or

total = c[1] + c[2] + ( c[3] + c[2] + c[4] ) n + ( c[3] + c[5] + c[4]) n^2

https://www.youtube.com/watch?v=chZNdhO6Ifw&list=WL&index=3

47
Q

True/False:

Is it always the case that O(n^3) is worse than O(n)?

A

ch9-2

False

48
Q

True/False

Generally speaking O(n^3) is worse than O(n).

A

ch9-2

True