CSCI 261 Test 3

अब Quizwiz के साथ अपने होमवर्क और परीक्षाओं को एस करें!

a c-string

A character array terminated with the null character is most correctly called a. a c-string b. a character array c. a string d. none of the above

true

A class member function may be recursive.

bytes

A computer's memory consists of numbered locations called __________.

a recursive definition

A definition that defines a concept or a formula in terms of the concept or formula is called a. a recursive definition b. indecision c. iteration d. reduction

calls itself

A recursive function is a function that ______________.

last out first in

A stack exhibits _________ behavior. a. first in first out b. last in last out c. last out first in d. undefined

Lifo

A stack exhibits what behavior?

false

A string variable and a c-string are the same data type.

A and B

A two dimension array can also be thought of as a. a table b. an array of arrays c. a file d. none of the above e. A and C f. A and B

true

A vector v will automatically increase the allocated size when more than v.size( ) elements are inserted with v.push_back( newElement).

the null character

All c-strings must be terminated by ________

array

An _______ is used to process a collection of data all of which is the same type

pass by array

Arrays are always passed to a function using a. pass by value b. pass by reference c. pass by array d. you cannot pass arrays to a function

true

Arrays can be passed to functions.

true

Every recursive definition may be rewritten iteratively.

Activation frame

Every time a recursive function call is executed, a new __________ is put on the top of the stack. a. Activity frame b. Activity record c. program d. Activation frame

iterative

For every recursive solution, there is a(n) ______________ solution.

B and D

Give the following declarations, which of the following is a legal call to this function? int myFunction(int myValue); int myArray[1000]; a. cout << myFunction(myArray); b. cout << myFunction(myArray[0]); c. myArray = myFunction(myArray); d. myArray[1] = myFunction(myArray[0]); e. A and B f. A and C g. B and D

scores[24]

Given an array named scores with 25 elements, what is the correct way to access the 25th element? a. scores+25 b. scores[24] c. scores[25] d. scores[last]

strlen

What is the c-string function to determine the number of characters in a c-string?

cout << str[2];

What is the code to print out the third character in a string variable named str?

strncat will concatenate at most n letters (where n has an appropriate value).

What is the difference between strcat and strncat?

It adds space for 3 integers to the base address of the array

Given an array of integers of size 5, how does the computer know where the 3rd indexed variable is located? a. It adds 3 to the base address of the array b. It adds space for 3 integers to the base address of the array c. It remembers where all the indexed variables of the array are located. d. None of the above

cout << people[9].getAge();

Given the following class and array declaration, how would you print out the age of the 10th person in the array? class personClass { public: void setAge(int newAge); void setGender( char newGender); void setSalary(float newSalary); int getAge(); char getGender(); float getSalary(); private: int age; char gender; float salary; }; personClass people[100]; a. cout << people[10]; b. cout << people[9]; c. cout << people[9].age; d. cout << people[9].getAge();

x<0, y<0

Given the following code fragment, what is the stopping condition(s)? int f1(int x, int y) { if(x<0 || y<0) return x-y; else return f1(x-1,y) + f1(x,y-1); } int main() { cout << f1(1,2)<<endl; return 0; }

str1.insert(4,str2);

Given the following code, what is the correct statement to insert the string str2 into str1, directly after the 'd'? string str1="abcdefg"; string str2="ABCDE"; a. str1.insert(4,str2); b. str2.insert(4,str1); c. insert(str1,4)=str2; d. insert(str2,4)=str1;

A and C

Given the following declarations, which of the following is legal syntax? string str="Your name"; char c_string[20]="My name"; a. str = c_string; b. c_string = str; c. strcpy(c_string, str.c_str()); d. strcpy(c_string, str); e. A and C

result=search(array, target, numberOfElements);

Given the following function definition for a search function, and the following variable declarations, which of the following are appropriate function invocations? const int SIZE=1000; int search(const int array[], int target, int numElements); int array[SIZE], target, numberOfElements; a. search(array[0], target, numberOfElements); b. result=search(array[0], target, numberOfElements); c. result=search(array, target, numberOfElements); d. result=search(array, target, SIZE);

Add another parameter to indicate where to start searching

Given the following function definition, what modifications need to be made to the search function so that it finds all occurrences of target in the array? int search(const int array[], int target, int numElements) { int index=0; bool found=false; while((!found) && (index < numElements)) { if(array[index] == target) found=true; else index++; } if(found==true) return index; else return -1; } a. Add another parameter to indicate where to stop searching b. Add another parameter to indicate where to start searching c. This already can find all occurrences of a given target d. Have the function return the whole array

No

Given the following function definition, will repeated calls to the search function for the same target find all occurrences of that target in the array? int search(const int array[], int target, int numElements) { int index=0; bool found=false; while((!found) && (index < numElements)) { if(array[index] == target) found=true; else index++; } if(found==true) return index; else return -1; } a. Yes b. No c. Impossible to tell without looking at the values of the array d. It depends on the value of target.

numDisks < 1

Given the following recursive function definition, what is the stopping case? void towers(char source, char dest, char help, int numDisks) { if(numDisks<1) { return; } else { towers(source,help,dest,numDisks-1); cout << "Move disk from " << source << " to " <<dest<<endl; towers(help,dest,source,numDisks-1); } } a. numDisks == 1 b. numDisks >1 c. numDisks < 1 d. numDisks =0

strcpy(str,"toaster");

How can you assign the value "toaster" to a c-string name str of size 10? a. str="toaster; b. str=toaster; c. strcpy(str,"toaster"); d. str.strcpy("toaster");

cin.getline(str,80);

How do you call the function to read a whole line of input(up to 80 characters) from the keyboard into a c-string named str?

str1 = str1 + str2;

How do you concatenate two string values (str1, str2)?

add a stopping case.

How do you ensure that your function does not have infinite recursion?

9

How many indexed variables does the following array have? int myArray[]={1,2,3,6,5,4,7,1,2};

12

How many indexed variables does the following array have? int myArray[12]={1,2,3,6,5,4,7,1,2};

3

How many times the function will be called if we use binary search algorithm to search the following array for key 6? 2 5 6 6 8 9 9 10 11 3 2 4 -1

true

If a function is expecting a pass by reference parameter, you can pass an index variable from an array of the same base type to that function.

the last 10 elements are removed

If a vector named numbers has 20 elements in it, what is the result of executing the following statement? numbers.resize(10); a. no change b. the first 10 elements are removed c. the last 10 elements are removed d. this causes a run-time error

none of the above

If the capacity of a vector named names is 20 and the size of names is 19, which of the following statements are legal? a. names.push_back("myName"); b. names[18]="myNmae"; c. all of the above d. none of the above

out_file.open(fileName.c_str());

If the name of a file to open is in the string variable name fileName, which of the following will correctly open the file for output? a. out_file.open(fileName); b. out_file.open("fileName"); c. fileName.open(outfile); d. out_file.open(fileName.c_str());

stack overflow

If the recursive function call does not lead towards a stopping case, you have ______________.

false

If v is a vector and i is an int variable, then in the following the value of i can be any nonnegative int value: v[i] = i;

false

If vector v has fewer than 24 elements and you call v.resize(24) the newly allocated elements are not initialized.

false

If we use an out of range index with a vector, there be an error message from the compiler.

int search(const int array[], int target, int numElements);

If we want a search function to search an array for some value and return either the index where the value was found, or -1 if not found, which of the following prototypes would be appropriate? a. void search(const int array, int target, int numElements); b. void search(const int array, int target); c. int search(const int array[], int numElements); d. int search(const int array[], int target, int numElements);

0

If you declare and initialize an integer array of size 10, but only list 5 values, what values are stored in the remaining 5 indexed variables? a. 0 b. garbage c. 0.0 d. '0'

All sizes except the first dimension

If you need a function that will handle multi-dimensional arrays, you must specify the following sizes inside the square brackets. a. All the sizes b. All sizes except the last dimension c. All sizes except the first dimension d. None of the sizes

ignored

If you put a value in the square brackets of a one-dimension array parameter, this value is _________ by the compiler.

all of the above

If you try to solve a problem recursively, you should a. find all the stopping cases and the values if needed at that case b. find a recursive call that will lead towards one of the stopping cases c. all of the above d. none of the above

false

If you use the const modifier in a function declaration, you do not include it in the function definition.

The size of the c-string -1

If you want to read into a c-string, you must ensure that the user does not enter more characters than a. The size of the c-string b. The size of the c-string + 1 c. The size of the c-string -1 d. It doesn't matter.

Index out of range

If your index used to access the indexed variables of the array has the value of a non-existent index, this is called _________

stack overflow

If your program makes too many recursive function calls, your program will cause a ___________ a. stack underflow b. activation overflow c. stack overflow d. syntax error

all of the above

Implementing a task recursively rather than iteratively generally a. is slower b. takes more storage (memory) c. is sometimes easier to program d. all of the above

recursive

In a recursive function, the statement(s) that invoke the function again are called the ______________.

exp=1

In a recursive power function that calculates some base to a positive exp power, at what value of exp do you stop? The function will continually multiply the base times the value returned by the power function with the base argument one smaller.

return base * power(base,exp-1);

In a recursive power function that calculates some base to the exp power, what is the recursive call?

The range of legal index values for a vector is 0 to the value of v.size()-1

In a vector, which of the following statements is true? a) Indexing vector access is range checked. b) The range of legal index values for a vector is 0 to the value of v.size()-1 c) To add a value use the member function v.push_front( ) d) To increase or decrease a vector's size v.new_size(newSize);

the list must be sorted

In order for the binary search to work correctly a. the list must be sorted b. the item must exist c. all of the above d. none of the above

in half

In the binary search program, each time through the list, we cut the list approximately a. in thirds b. in quarters c. by one element d. in half

index

In the expression cout << score[i] << endl; i is called the

base type

In the expression double score[10]; double is called the ___________ of the array

2

In the following function, how many recursive calls are there? void towers(char source, char dest, char help, int numDisks) { if(numDisks<1) { return; } else { towers(source,help,dest,numDisks-1); cout << "Move disk from " << source << " to " <<dest<<endl; towers(help,dest,source,numDisks-1); } } a. 0 b. 1 c. 2 d. 3

0

Indexes are numbered starting at _________

false

Not all recursive definitions may be written iteratively.

false

Only functions that do not return a value may be recursive.

false

Recursive functions always execute faster than an iterative function.

true

Recursive functions may return any type of value

false

Recursive functions must return a value.

string

The ________ class lets you treat string values and variables like other pre-defined data types (such as int).

any data type

The base type for a vector can be a. int b. float or double c. char d. any data type

cstdlib

The c-string to number conversion functions are in the _________ library.

null

The character '\0' is called the __________ character.

the first

The computer remembers the address of which indexed variable(s) in an array?

vector<double> doubleVec;

The declaration of an STL vector doubleVec that can hold values of type double, one writes ______________.

fact(n-1)*n;

The factorial of an integer is the product of that integer multiplied by all the positive non-zero integers less than that integer. So, 5! (! is the mathematical symbol for factorial) is 5 * 4 * 3*2*1. 4! is 4*3*2*1, so 5! could be written as 5*4!. So a recursive definition of factorial is n! is n*(n-1)!, as long as n >1. 1! is 1. What is the recursive call for this function (fact)? a. fact(n)*n; b. fact(n-1)*n; c. (n-1)*fact(n) d. fact(n-2)*(n-1)

n==1

The factorial of an integer is the product of that integer multiplied by all the positive non-zero integers less than that integer. So, 5! (! is the mathematical symbol for factorial) is 5 * 4 * 3*2*1. 4! is 4*3*2*1, so 5! could be written as 5*4!. So a recursive definition of factorial is n! is n*(n-1)!, as long as n >1. 1! is 1. What is the stopping case for this function? a. n<1 b. n==0 c. n==1 d. none of the above

true

The following array declaration is legal double scores[]={0.1,0.2,0.3};

false

The following code declares a vector of characters. vector characters<char>

false

The following code declares a vector of integers named numbers that reserves space for 100 integers. vector<int> numbers(100);

true

The following declares a c-string and initializes it to "speaker" char str[]="speaker";

false

The following declares a c-string variable that will hold 10 letters. char str[10];

false

The following function declaration guarantees the values in the array argument are not changed. void function1(int array[], int numElements);

5

The following function definition has an error in it. What line is this error on? 0. void f1(const double array[], int size) 1. { 2. int i=0; 3. while(i< size) 4. { 5. array[i] += 2; 6. cout <<array[i]; 7. i++; 8. } 9. } a. 0 b. 2 c. 5 d. 6 e. 2

true

The following function will work with any size integer array. void function1(int array[], int numElements);

strcat

The function used to 'put two c-strings together into one" is called

false

The indexed variables (members) of an array must be integers.

indexed variables

The individual variables that comprise an array are called __________

false

The locations of the various indexed variables in an array can be spread out all over the memory.

const

The modifier that guarantees that an array argument will not be changed is called ______.

a template class

The notation vector<Base_Type> means that the vector is a. an array b. a template class c. primitive data type d. all of the above

true

The operating system uses a stack to control recursion.

A and B

The recursive definition of a Fibonacci Number is F(n) = F(n-1) + F(n-2), where F(0)=1 and F(1)=1. What is the stopping case in a recursive function that implements this function? a. n=0 b. n=1 c. n=2 d. A and B e. A and C f. A,B and C

2

The recursive definition of a Fibonacci Number is F(n) = F(n-1) + F(n-2), where F(0)=1 and F(1)=1. What is the value of Fib(3)? a. 8 b. 5 c. 2 d. 1

8

The recursive definition of a Fibonacci Number is F(n) = F(n-1) + F(n-2), where F(0)=1 and F(1)=1. What is the value of Fib(5)? a. 8 b. 5 c. 2 d. 1

return fib(n-1)+fib(n-2)

The recursive definition of a Fibonacci Number is F(n) = F(n-1) + F(n-2), where F(0)=1 and F(1)=1. What would be the recursive function call in a recursive implementation of this? a. return; b. return fib(n) + fib(n-1) c. return fib(n-1)+fib(n-2) d. return 1;

n=0

The square of n can be calculated by noting that square(n) = square(n-1) + diff(n-1). diff(n) = diff(n-1)+2. The square(0)=0, diff(0)=1. What is the stopping condition for this recursive definition? a. n=1 b. n=0 c. n=-1 d. unknown

true

There can be more than one stopping case in a recursive function.

numbers.push_back(newValue);

To add an element to a vector of integers named numbers at the next available position in the vector, you would use: a. numbers[numbers.size()+1] = newValue; b. numbers = newValue; c. numbers.pushBack(newValue); d. numbers.push_back(newValue);

resize

To change the size of a vector, one uses the ______________ member function.

member function.

To change the space already allocated for a vector, one uses the ______________

strcmp

To compare two c-strings you use the __________ function.

char s1[10]="phonebook";

To declare a c-string and initialize it to the value of "phonebook",

all of the above

To ensure that your function recurses correctly and the proper result is reached, you must ensure that a. all stopping cases are correct b. all recursive calls lead to one of the stopping cases c. for each case that involves recursion, that case returns the correct value provided all recursive calls in that case return the correct value. d. all of the above e. none of the above

<cstring>

To use the functions for manipulating and comparing c-strings, you must include ___________

<string>

To use the string class, you must include which library?

false

Using the == operator on a string variable results in the same value as using strcmp on two c-strings.

true

Using the [i] on a string variable does not check for illegal values of i.

false

Using the resize member function alone, you can increase the capacity of an STL vector.

true

Vector assignment is well behaved.

false

Vector indexing warns about out-of-bounds index values.

false

Vectors and arrays are the same data type.

true

Vectors can have any type as the base type

0-24

What are the valid indexes for the array shown below? int myArray[25]; a. 0-25 b. 0-24 c. 1-25 d. 1-24

they both compare, one expects an integer for the number of characters to compare.

What is the difference between strcmp and strncmp? a. No difference b. they both compare, one expects an integer for the number of characters to compare. c. one copies, the other compares d. They are in different libraries

atoi

What is the name of the function to convert from a c-string that contains only digits to an integer?

0 1 2 3 1 2 3 4 2 3 4 5 3 4 5 6

What is the output of the following code fragment? int array[4][4], index1, index2; for(index1=0;index1<4;index1++) for(index2=0;index2<4;index2++) array[index1][index2]=index1 + index2; for(index1=0;index1<4;index1++) { for(index2=0;index2<4;index2++) cout << array[index1][index2] << " "; cout << endl; } a. 0 1 2 3 1 2 3 4 2 3 4 5 3 4 5 6 b. 0 1 2 3 0 1 2 3 0 1 2 3 0 1 2 3 c. 0 0 0 0 1 1 1 1 2 2 2 2 3 3 3 3 d. 0 0 0 0 0 1 2 3 0 2 4 6 0 3 6 9

6

What is the output of the following code fragment? int f1(int base, int limit) { if(base > limit) return -1; else if(base == limit) return 1; else return base * f1(base+1, limit); } int main() { cout << f1(2,4)<<endl; return 0; } a. 2 b. 3 c. -1 d. 6

2

What is the output of the following code fragment? int f1(int base, int limit) { if(base > limit) return -1; else if(base == limit) return 1; else return base * f1(base+2, limit); } int main() { cout << f1(2,4)<<endl; return 0; }

8

What is the output of the following code fragment? int f1(int n, int m) { If(n < m) return 0; else if(n==m) return m+ f1(n-1,m); else return n+ f1(n-2,m-1); } int main() { cout << f1(5,4); return 0; } a. 0 b. 2 c. 4 d. 8 e. infinite recursion

8

What is the output of the following code fragment? int f1(int n, int m) { if(n < m) return 0; else if(n==m) return m+ f1(n-1,m); else return n+ f1(n-2,m-1); } int main() { cout << f1(5,4); return 0; } a. 0 b. 2 c. 4 d. 8 e. infinite recursion

0

What is the output of the following code fragment? int f1(int n, int m) { if(n < m) return 0; else if(n==m) return m+ f1(n-1,m); else return n+ f1(n-2,m-1); } int main() { cout << f1(1,4); return 0; } a. 0 b. 2 c. 4 d. 8 e. infinite recursion

5

What is the output of the following code fragment? int f1(int x, int y) { if(x<0 || y<0) return x-y; else return f1(x-1,y) + f1(x,y-1); } int main() { cout << f1(2,1)<<endl; return 0; } a. 0 b. -1 c. 5 d. -5

-1

What is the output of the following code fragment? int f1(int base, int limit) { if(base > limit) return -1; else if(base == limit) return 1; else return base * f1(base+1, limit); } int main() { cout << f1(12,4)<<endl; return 0; } a. 2 b. 3 c. -1 d. 6

-5

What is the output of the following code fragment? int f1(int x, int y) { if(x<0 || y<0) return x-y; else return f1(x-1,y) + f1(x,y-1); } int main() { cout << f1(1,2)<<endl; return 0; } a. 0 b. -1 c. 5 d. -5

4 3 2 1

What is the output of the following function call: printVertical(1234); 4 3 2 1 there is a syntax error there is an infinity recursive call 1 2 3 4

vector<string> names;

What is the proper way to declare a vector of strings named names? a. vector strings names; b. vector<names> string; c. vector<string> names; d. all of the above

100

What is the value of numbers.capacity() after the following code? vector<float> numbers; numbers.reserve(100) a. 0 b. 10 c. 100 d. unknown

0

What is the value of numbers.size() after the following code? vector<float> numbers; a. 0 b. 10 c. 100 d. unknown

0

What is the value of numbers.size() after the following code? vector<float> numbers; numbers.reserve(100) a. 0 b. 10 c. 100 d. unknown

the empty string

What is the value of str after the following code? string str; a. a garbage string b. the empty string c. the null character d. unknown

The values do not constitute a c-string

What is wrong with the following attempted c-string declaration and initialization? char str1[5]={'a', 'b', 'c'}; a. There are only 3 values in the braces b. The single quotes should be double quotes c. The values do not constitute a c-string d. nothing

str1 does not have enough room

What is wrong with the following code fragment? char str1[10]="Mark", str2[15]="What's my name"; strcpy(str1,str2); a. Nothing b. str2 has white space in it c. str1 does not have enough room d. str2 does not have enough room

Array indexes must be less than the size of the array

What is wrong with the following code fragment? const int SIZE =5; float scores[SIZE]; for(int i=0; i<=SIZE;i++) { cout << "Enter a score\n"; cin >> scores[i]; } a. Array indexes start at 1 not 0 b. Arrays must be integers c. Array indexes must be less than the size of the array d. Should be cin >> scores[0];

Nothing

What is wrong with the following code? float scores[10], total; a. Cannot declare regular and array variables together. b. Arrays must be integers c. The 10 should be replaced with a variable name, whose value is input from the user d. Nothing.

the stopping condition is wrong

What is wrong with the following recursive function? It should print out the array backwards. void print(int array[], int start, int size) { if(start < size) return; else { print(array, start+1,size); cout << array[start] << endl; } } a. infinite recursion b. the stopping condition is wrong c. the recursive call is wrong d. nothing

nothing

What is wrong with the following recursive function? It should print out the array backwards. void print(int array[], int start, int size) { if(start == size) return; else { print(array, start+1,size); cout << array[start] << endl; } } a. infinite recursion b. the stopping condition is wrong c. the recursive call is wrong d. nothing

A and C

Which of the following will print out the value in str? char str[30]; cin >> str; a. cout << str; b. for(int i=0;i<30;i++) cout << str[i]; c. int i=0; while(i<30 && str[i] != '\0') cout << str[i]; d. All of the above e. A and B f. A and C

A and C

What is wrong with the following recursive function? It should print out the array backwards. void print(int array[], int start, int size) { if(start == size) return; else { print(array, start-1,size); cout << array[start] << endl; } } a. infinite recursion b. the stopping condition is wrong c. the recursive call is wrong d. A and C e. nothing

the recursive call is wrong

What is wrong with the following recursive function? It should print out the array backwards. void print(int array[], int start, int size) { if(start == size) return; else { print(array, start-1,size); cout << array[start] << endl; } } a. infinite recursion b. the stopping condition is wrong c. the recursive call is wrong d. nothing

all the values in the vector are copied

When a vector is assigned to another vector a. only the location of the vector is copied b. all the values in the vector are copied c. if there is not enough room in the left-hand vector, then not all the values from the right side are copied d. none of the above

it skips all white spaces

When the extraction operator is used to read data into a string, a. it skips all white spaces b. it skips only new lines c. it reads everything on the line d. it reads as many characters that will fit into the c-string

true

When you have a function that expects an array, it should also expect the size of the array or the number of indexed variables with valid data.

str1 = "toaster";

Which assignment statements will copy the value " toaster" into a string variable (str1)? a. strcpy(str1,"toaster"); b. str1 = "toaster"; c. str1 = toaster; d. str1 += toaster;

str.length()

Which is the proper way to determine how many characters are in the string variable named str? a. str.getLength() b. str.length() c. length(str) d. getLength(str)

size( ) tells how many base type objects have been inserted into the vector

Which of the following are correct statements about vector member functions studied in this chapter? a) push_front (baseTypeObject) puts object on the front of a vector b) indexing uses index values 0 through size( ) c) size( ) tells how many base type objects have been inserted into the vector d) When a vector runs out of space all implementations are required to double the amount of allocated space .

{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}

Which of the following array cannot perform binary search? {2, 8, 6, 4, 10} {1, 2, 3, 4, 5, 6, 7, 8, 9, 10} {1, 2, 3, 4, 5} {5, 4, 3, 2, 1}

All but B

Which of the following array declarations are legal? a. int array[10]; b. int size; cin >> size; int array[size]; c. int array[]={0,0,0}; d. const int size=9; int array[size]; e. All of the above f. All but C g. All but B

float array[3][5];

Which of the following correctly declare an array that can hold up to 3 rows of 5 columns of doubles? a. int array[3],[5]; b. int array[3][5]; c. float array[3][5]; d. float array[3,5];

char s1[10];

Which of the following declarations correctly creates a c-string that can hold the value "phonebook" a. char s1; b. char s1[9]; c. char s1=10; d. char s1[10];

char array[5]={'a','b','c','d','e'}; and char array[5]={''};

Which of the following declare an array of 5 characters, and initializes them to some known values? a. char array[5]={'a','b','c','d','e'}; b. char array[4]={'a','b','c','d','e'}; c. char array[5]={''}; d. char array[]={'a','b','d','e'}; e. char array[5]={'a','b','c','d','e'}; and char array[5]={''}; f. char array[4]={'a','b','c','d','e'}; and char array[]={'a','b','d','e'}; g. all of the above

B and D

Which of the following function declarations can be passed the following array? char myArray[6][8]; a. void f1(char a[][], int sizeOfFirst); b. void f1(char a[][8], int sizeOfFirst); c. void f1(char& a, int sizeOfFirst); d. void f1(char a[6][8], int sizeOfFirst); e. B and D f. A and D

C and D

Which of the following function declarations correctly expect an array as the first argument? a. void f1(int array, int size); b. void f1(int& array, int size); c. void f1(int array[100], int size); d. void f1(float array[], int size); e. All of the above f. C and D g. A and B

void f1(const int array[], int size);

Which of the following function declarations correctly guarantee that the function will not change any values in the array argument? a. void f1(int array[], int size) const; b. void f1(int array[], int size); c. void f1(int &array, int size); d. void f1(const int array[], int size); e. void f1(int array[], const int size);

void input(int array[], int &numElements, int MAX_SIZE);

Which of the following function declarations could be used to input data from the keyboard into the array? a. void input(int array[], int &numElements, int MAX_SIZE); b. void input(int array[], int numElements, int MAX_SIZE); c. void input(int &array[], int numElements, int MAX_SIZE); d. int array[] input(int array[], int &numElements, int MAX_SIZE);

void f1(int pages[][30], int size);

Which of the following function declarations will accept the following two-dimension array? int pages[10][30]; a. void f1(int pages[][], int size); b. void f1(int pages[][30], int size); c. void f1(int pages[10][], int size); d. void f1(int& pages, int size);

str.at(3);

Which of the following returns the fourth character in the string variable named str and checks if there is a fourth character in the string? a. str(3); b. str.at(3); c. str[3]; d. All of the above

All of the above

Which of the following statements are true? a. Array elements may be user-defined types (structs or classes) b. If a function is expecting a variable of the base type of the array, then you can pass an element of the array to the function. c. All of the above. d. None of the above.

for(i=0;i<SIZE;i++) array1[i]=array2[i];

Which of the following will correctly assign all the values in one array to the other array? (Assume both arrays are of the same type and have SIZE elements) a. array1=array2; b. array1[]=array2; c. for(i=0;i<SIZE;i++) array1[i]=array2[i]; d. for(i=0;i<SIZE;i++) array1[]=array2[];

for(i=0;i<SIZE;i++) cin >> array[i]

Which of the following will read values from the keyboard into the array? (Assume the size of the array is SIZE). a. cin >> array; b. cin >> array[]; c. cin >> array[SIZE]; d. for(i=0;i<SIZE;i++) cin >> array[i]

getline(fin, line);

Which of the following would correctly read an entire line from an input file stream named fin into a string variable named line. a. getline(fin, line); b. fin.getline(line); c. fin.getline(line,'\n\'); d. fin.getline(line,80);

selection

Which sort algorithm does the following outline define? for i between 0 and number_used-1 inclusive put the ith smallest element at array[i] a. sequential b. selection c. bubble d. swap

find

Which string function returns the first occurrence of str1 in a string named str?

All of the above

Why should you use a named constant for the size of an array? a. Readability of code b. Makes changes to the program easier c. Helps reduce logic errors d. All of the above

int array[10][20];

Write the code to declare a two dimension array of integers with 10 rows and 20 columns.

double list[10];

Write the code to declare an array of 10 doubles named list;

true

You can explicitly use the vector member function resize to increase the capacity of a vector.

false

You may have at most 1 recursive call in a recursive function.

Vectors

____________ can be thought of as an array that can grow and shrink as needed.

<0 if first < second, 0 if first == second, positive otherwise

strcmp(first, second) returns a. <0 if first < second, 0 if first == second, positive otherwise b. true if first=second, false otherwise c. nothing, it's a void function d. >0 if first < second, 0 if first > second, <0 otherwise


संबंधित स्टडी सेट्स

MNB PassPoint - Postpartum Period

View Set

ACCT 209 CHAPTER 5-9 STUDY QUESTIONS

View Set

G 1 - Plant responses to the enviroment

View Set

List #2 (From Reading and Vocabulary Focus 2 - Unit 1 Reading 2)

View Set

Ethics and Corporate Social Responsibility

View Set

Assignment 8 - Quiz 2: Motivation, Emotion, and Stress

View Set

3.3. Health behaviors, social and behavioral risk factors: 3.3.1 and 3.3.2

View Set