Comp Sci Readiness Assessment 3

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

Given the statementchar text[15] = "ready 2 go"; What would be stored in y by the following statementchar y = isalpha(text[5]); True False 0 1

0

Given the code segment int x(int&, int);int y(int); void z(double[]); int main() { int a=2, b=3, c=10;double r[3] = {1.2, 3.3, -0.2};a += x(++a, 1);b = y(c) + 5;c = x(c, 1) + y(b);cout << "a = " << a << endl;cout << "b = " << b << endl;cout << "c = " << c << endl;z(r);cout << r[0] << endl;return 0;} int x(int& c, int Z){c++;return Z;} int y(int QQ_){if (QQ_%3 == 1) return 5;else if(QQ_%5 == 0) return 0;else return 1;} void z(double b[ ]){double t;t = b[0];b[0] = b[1];b[1] = b[2];b[2] = t;} What is output by the first cout statement? 5 3.3 6 10 12 0

5

What would be printed by the following code segment? int f(int &); int main(){int n = 5;n = f(n);cout << n << "\n";return 0;} int f(int &i){i = 10;return(5 * i);} 50 10 0 15 20 5

50

Given the code segment int x(int&, int);int y(int); void z(double[]); int main() { int a=2, b=3, c=10;double r[3] = {1.2, 3.3, -0.2};a += x(++a, 1);b = y(c) + 5;c = x(c, 1) + y(b);cout << "a = " << a << endl;cout << "b = " << b << endl;cout << "c = " << c << endl;z(r);cout << r[0] << endl;return 0;} int x(int& c, int Z){c++;return Z;} int y(int QQ_){if (QQ_%3 == 1) return 5;else if(QQ_%5 == 0) return 0;else return 1;} void z(double b[ ]){double t;t = b[0];b[0] = b[1];b[1] = b[2];b[2] = t;} What is output by the third cout statement? 5 3.3 6 10 12 0

6

Given the array definition (declaration)double anotherArray[3][4][2][5][5]; How many values may be stored in the array 6 600 5 2160 96

600

In C++ a index (subscript) of -1 can be used to indicate the last element of an array. True False

False

In C++ if no size declarator is given in the array definition, the array will expand as needed throughout the code. True False

False

In C++ the first element of an array has the index (subscript) or 1. True False

False

Relational operators can be used with both string objects and C-strings True False

False

And that's all folks! Ending Question: Who is the coolest member of cmpsci 201baddies?

MacRay VanKirk

What is output by the following code segment? void F(int , int & , int& ); int main(){int a = 0, b = 1, c = 2, d = 3;F(c+1, c-1, d);cout << d << endl;return 0;} void F(int x, int & y, int & z){z = y = x * x + 1;} 2 10 Nothing because there is an error the function definition 10 2 Nothing because there is an error the function call Nothing because the function prototype does not contain parameters

Nothing because there is an error the function call

Given the array declaration double xyz[20]; which of the following statements are true? The array may hold up to 21 elements which may be accessed by the subscripts 0 through 20 The array may hold up to 19 elements which may be accessed by the subscripts 1 through 19 The array may hold up to 20 elements which may be accessed by the subscripts 0 through 20 The array may hold up to 20 elements which may be accessed by the subscripts 1 through 20 The array may hold up to 20 elements which may be accessed by the subscripts 0 through 19

The array may hold up to 20 elements which may be accessed by the subscripts 0 through 19

Consider the following segment of code. What would be the result? int array[N][N];const int N = 10; The code will not run because a syntax error occurs. Although there are syntax errors the code will still compile and can be executed. The code will compile and the size of the array will change as needed. Although there are warnings the code will still compile and can be executed.

The code will not run because a syntax error occurs.

Which of the following would declare an array that could hold up to 65 floating points numbers (and no more)? float somenumbers[64]; double somenumbers[65]; int somenumbers[65]; float somenumbers[66]; int somenumbers[64]; double somenumbers[64];

double somenumbers[65];

What needs to be corrected in the following code? #include <iostream> using namespace std; int cmpsc(int &, int &); int main(){double x = cmpsc(100,200);cout << x << endl;return 0;} int cmpsc(int& a, int& b){int result;result = a + b; return result;} the function cmpsc should not have a return statement the declaration (prototype) should be int cmpsc(int, int); the arguments in the function call must be variables, not literal values there is nothing wrong with the code the returned value of the function cmpsc cannot be stored in a double variable

the arguments in the function call must be variables, not literal values

The following function is intended to cube a number int cubeNumber(int number) { int answer = 1; for(int i = 0; i < 3; i++) answer *= number; return number; } What is wrong with this function, if anything? the function returns the wrong variable it calculates the number raised to the fourth power nothing is wrong a syntax error occurs because the loop is missing braces it only squares the number

the function returns the wrong variable

Given the following code segment what would be the correct heading for the loop to confirm the user entered a valid value for choice? char choice; double x, y; cout<< "Enter 1 to purchase new box, 2 to change box color, " << " 3 to change box height, or 4 to quit. "; cin>>choice; //loop to check _________________________________ // what code should go here { cout<<"You entered an incorrect!\n " <<"Enter 1 to purchase new box, 2 to change box color, " << " 3 to change box height, or 4 to quit. "; cin>>choice; } while (choice != '1' || choice != '2'||choice !='3'|| choice != '4') while (choice != '1' && choice != '2'&&choice !='3'&& choice != '4') while (choice == '1' || '2'|| '3'||'4') while (choice > 4 && choice < 1) while (choice == '1' && '2' && '3'&& '4') while (choice > 4 || choice < 1)

while (choice != '1' && choice != '2'&& choice !='3'&& choice != '4')

Which operator has highest precedence in C++? ^ + || * <

*

Given the code # include <fstream># include <iostream> using namespace std; int main(){int a[10];int i;ifstream infile("input.txt");for(i=0; i<10; i++)infile >> a[10-i-1];ofstream outfile("output.txt");for(i=0; i<10; i++)outfile << a[i] << " "; return 0;} Assume that the file "input.txt" has the numbers 8 2 4 9 7 2 1 10 0 3 in the same order. What is the index of the smallest number in the array 'a'? 9 8 0 1 10

1

What would be printed by the following code segment? int f(int &); int main(){int n = 5;f(n);cout << n << "\n";return 0;} int f(int &i){i = 10;return(5 * i);} 50 100 5 0 10

10

What would be stored in arr[4] after the loop in the following code segment is complete? int arr[10];arr[0] = 1;arr[1] = 2;for (int i = 2; i < 10; i++){if ( (i % 2) == 1 )arr[i] = arr[i-1] + arr[i-2];else arr[i] = 2 * arr[i-1];} 12 9 10 6 5 18

12

Given the code # include <fstream># include <iostream> using namespace std; int main(){int a[10];int i;ifstream infile("input.txt");for(i=0; i<10; i++)infile >> a[10-i-1];ofstream outfile("output.txt");for(i=0; i<10; i++)outfile << a[i] << " "; return 0;} Assume that the file "input.txt" has the numbers 8 2 4 9 7 2 1 10 0 3 in the same order. What is the index of the largest number in the array 'a'? 3 2 8 7 0

2

Given the code segment int x(int&, int); int y(int); void z(double[]); int main() { int a=2, b=3, c=10; double r[3] = {1.2, 3.3, -0.2}; a += x(++a, 1); b = y(c) + 5; c = x(c, 1) + y(b); cout << "a = " << a << endl; cout << "b = " << b << endl; cout << "c = " << c << endl; z(r); cout << r[0] << endl; return 0; } int x(int& c, int Z) { c++;return Z; } int y(int QQ_) { if (QQ_%3 == 1) return 5; else if(QQ_%5 == 0) return 0; else return 1; } void z(double b[ ]) { double t; t = b[0]; b[0] = b[1]; b[1] = b[2]; b[2] = t; } What is output by the final cout statement? 5 3.3 6 10 12 0

3.3

What would be output by the following code segment? int mathFunc( int&, int, int); int mathFunc2( int&, int, int); int main() { int x = 1,y = 2,z; int i = 0; while( i < 10 ){ z = mathFunc2(i,x,y); if( z%2 ) cout << z; x = z; y = z/2; } cout << endl; return 0; } int mathFunc( int& j, int a, int b) { j+=2; return a + b; } int mathFunc2( int& j, int a, int b) { j+=3; return a + b; } 3193 3913 39 346913 34691319

39

What would be output by the following code segment? int mathFunc( int&, int, int); int mathFunc2( int&, int, int); int main() { int x = 1,y = 2,z; int i = 0; while( i < 10 ){ z = mathFunc(i,x,y); if( z%2 ) cout << z; x = z; y = z/2; } cout << endl; return 0; } int mathFunc( int& j, int a, int b) { j+=2; return a + b; } int mathFunc2( int& j, int a, int b) { j+=3; return a + b; } 39 34691319 3913 346913 3193

3913

Given the array definition (declaration) double ratings[ ] = {1.3, 7.8, 2.4, 6.4, 3.6}; what is the index (subscript) of the last element of the array? 4 0 5 1 2 Nothing because the absence of the array declarator makes the definition of the array invalid

4

Given the array declarationint cl1[4][5] = {{16, 28, 22, 5, 2},{8, 7, 11, 17, 18}, {21, 3, 15, 31, 28}, {9, 4, 40, 29, 33}}; what would be output by the statementcout<<cl1[3][2]; 40 29 31 31 3 15

40

Given the following data for an array 23 25 27 29 31 33 5922 24 26 28 30 32 6135 37 39 41 43 45 6334 36 38 40 42 46 6547 49 51 53 55 57 67 If the values were stored in an array called xyz, what would be output by the statementcout<<xyz[3][4]; 40 46 39 41 42

42

Given the array definition (declaration)double anotherArray[3][4][2][5][10]; How many dimensions does the array contain? 3 600 2 4 5 270 1 1200 6

5

Given the code # include <fstream># include <iostream> using namespace std; int main(){int a[10];int i;ifstream infile("input.txt");for(i=0; i<10; i++)infile >> a[10-i-1];ofstream outfile("output.txt");for(i=0; i<10; i++)outfile << a[i] << " "; return 0;} Assume that the file "input.txt" has the numbers 8 2 4 9 7 2 1 10 0 3 in the same order. What is the first number read from the file? 4 0 9 3 2 1 7 8 2

8

Introductory comments should be written ____________ After analyzing the problem and developing test data but before writing code. After analyzing the problem, developing test data, and writing code Before the problem is analyzed After testing the program by running it with test data. Never

After analyzing the problem and developing test data but before writing code.

The elements (members) of an array are stored ____________ in memory randomly there is no order in how the elements are stored consecutively reverse order

Consecutively

Welcome to Readiness Assessment 3! Opening Question: During a recitation, Mary referred to sexist kid as what type of dog?

Crusty White Dog

That's all for 3A! Intermission: What has contributed the most to our success in this class?

Helen seducing the TAs

The following segment of code results in a blank black screen when it is compiled and run. You conclude that there is something wrong with the code. What is wrong? int sum = 0; int counter = 0; while(counter < 10); { sum += ++counter; } cout << sum << endl; It is an infinite loop because the body of the while loop is actually an empty statement rather than sum += ++counter; the incrementation of counter should be post-incrementation rather than pre-incrementation nothing is wrong the value of ++counter cannot be added to sum The code sum += ++counter; is never executed because the condition of the loop evaluates to false from the beginning.

It is an infinite loop because the body of the while loop is actually an empty statement rather than sum += ++counter;

And 3B is done! Intermission: In the Great Academic Integrity Crisis of '21, what ended up being our saving grace?

Jacob eating Susie Q's ass

Given the array definition (declaration) string planets[9] = { "Mercury", "Venus", "Earth", "Mars", "Jupiter","Saturn", "Uranus", "Neptune"}; what would be output by the statement cout<<planets[4]; Mars s (lower case) Jupiter t (lower case) S (upper case) Nothing because only 8 elements were listed and the definition requires 9 elements. nothing because you cannot create an array of string objects in C++

Jupiter

The following loop is an infinite loop. for (;;) { cout<<"it is not an infinite loop"<<endl; } False True

True

int cmpsc(int, int); int main(){double x, c = 200, d = 300;x = cmpsc(c,d);cout << x << endl;return 0;} int cmpsc(int a, int b){int result;result = a + b;} Given the code above, what are the formal parameters? b only c and d x only a and b c only a only

a and b

What value is stored in x after the following assignment int x = 10 / (20 % 11 - 9); 0 infinity a runtime error occurs 1 0.5

a runtime error occurs

Given the code segment and assuming the array contains values:int sum = 0;int ARRAY[15][15];for(int x = 0; x < 15; x++){for(int y = 0; y < 15; y++){ if (x == y)sum += ARRAY[x][y];}} the code segment will _________________ sum each row and store the sums in an 1-dimensional array add up the diagonal of the 2D array from upper left to lower right sum each column and store the sums in an 1-dimensional array add up the diagonal of the 2D array from upper right to lower left sum all the values in the array add up the diagonal of the 2D array from lower left to upper right

add up the diagonal of the 2D array from upper left to lower right

Given the following data for an array 23 25 27 29 31 33 5922 24 26 28 30 32 6135 37 39 41 43 45 6334 36 38 40 42 46 6547 49 51 53 55 57 67 Which of the following would change all the values to 1? for (int r = 0; r < 7; r ++){for (int c = 0; c < 5; c++){somearray[r][c] =0;}} for (int r = 0; r < 7; r ++){for (int c = 0; c < 5; c++){somearray[c][r] =1;}} for (int r = 0; r <= 5; r ++){for (int c = 0; c <= 7; c++){somearray[r][c] =1;}} for (int r = 0; r < 5; r ++){for (int c = 0; c < 7; c++){somearray[r][c] =1;}} for (int r = 1; r <= 5; r ++){for (int c = 1; c <= 7; c++){somearray[c][r] =1;}}

for (int r = 0; r < 5; r ++){for (int c = 0; c < 7; c++){somearray[r][c] =1;}}

Which of the following is an example of a repetition structure? if switch void function for loop if loop

for loop

The following is an example of a (n) void Print2LInes( ) function body function prototype variable definition (declaration) object definition (declaration) function heading

function heading

Which of the following statements are true? ifs, loops, and function definitions may all be nested, but switches may not be nested. ifs, loops, and switches may all be nested, but function definitions may not be nested. switches, loops, and function definitions may all be nested, but ifs may not be nested. no control structures may be nested. ifs, loops, switches, and function definitions may all be nested ifs, switches, and function definitions may all be nested, but loops may not be nested.

ifs, loops, and switches may all be nested, but function definitions may not be nested.

The following code segment is an example of for (i = 0; i<= last; i++){if (a[i] > a [i + 1]){sorted = false;marker = i;while (!sorted){temp = a[marker];a[marker] = a [marker + 1];a[marker + 1] = temp;if (marker == 0)sorted = true;else if (a[marker]>a[marker-1])sorted = true;elsemarker = marker - 1;}} } binary search selection sort bubble sort insertion sort linear search

insertion sort

What type should x, y, z, and w be if we are going to assign them the values 1, 1.0, '1', and "1", respectively? int, double, string, char int, int, char, char int, double, string, string double, int, string, char float, double, char, char int , double, char, string double, double, string, string

int , double, char, string

The advantage of a binary search is ________ it requires the array to be sorted it is faster than a linear search it is less efficient than the linear search it will use more iterations than a linear search it is simpler to write

it is faster than a linear search

The if-loop belongs to which major control structure? repetition selection (decision/branch) sequence none as the if is NOT a loop function

none as the if is NOT a loop

When the address of argument is passed to a function, the formal parameter is considered to be passed by _____________________ value reference copy xerox inference function

reference

Switches are considered to be an example of which major control structure? for loops repetition if loops selection (decition/branch) ifs functions sequence

selection (decition/branch)

The 4 major control structures are _______________________ switches, selections (decisions/branches), repetitions and functions sequences, selections (decisions/branches), repetitions and functions ifs, switches, for loops and while loops for loops, selections (decisions/branches), repetitions and functions ifs, switches, for loops and functions

sequences, selections (decisions/branches), repetitions and functions

Which of the following should be used to define an array that will hold up to and no more than 15 whole numbers? whole[15] int xyz(15) long abc[14]; long abc(); short gh[15]; int xyz(15); float ab[15]; double ty[14];

short gh[15];

Given the code segment and assuming the array contains values:int sum = 0;int ARRAY[15][15];for(int x = 0; x < 15; x++){for(int y = 0; y < 15; y++){ sum += ARRAY[x][y];}} the code segment will _________________ sum up the elements on the diagonal from lower left to upper right sum up the elements in each column and store in a new array sum up the elements on the diagonal from upper left to lower right sum up all the elements of the array sum up the elements in each row and store in a new array sum up the elements on the diagonal from upper right to lower left

sum up all the elements of the array

What is wrong with the following code segment? void function2(void){int a, b, result = 0;cin >> a >> b;cout << a+b << endl;result = a+b;return result;} "result = a+b" should be above the cout statement this is a void function, and therefore should not return a value "cin >> a >> b;" needs to be separated into 2 separate cin statements "function2" is an invalid function name void is not permissible in the parameter list

this is a void function, and therefore should not return a value

Given the function which is supposed to add up all the elements of an array double SumArray(double a[ ], int howmany){double sum = 0;int i = 0;while(i < howmany){sum = sum + a[i];}return sum;} which would be a valid function call to find the total of all the elements in the array quiz3 which contains 20 values? total = SumArray(a, 19); total = SumArray(quiz3, 20); total = SumArray(a[19], 20); total = SumArray(quiz3[20], 20); total = SumArray(quiz3[20]); total = SumArray(a, 20);

total = SumArray(quiz3, 20);

If a function does not have a return statement, then the return type of the function should be _______ double bool void float int string

void


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

Lesson 4: Collecting and Querying Security Monitoring Data

View Set

PEDS: Chapter 26: School-Aged Child: 6-10 years

View Set

4.4 Protein Denaturation and Folding

View Set