Ready 3 + 4

Ace your homework & exams now with Quizwiz!

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

*

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

0

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 1 0 8 10

1

Given the MATLAB code segment: for k = 1:10 disp(k) k = k - 2; end how many values for k will be output? 1 9 6 infinite 10 2 5

10

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); } 5 50 10 100 0

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

How many elements would be stored in R after the MATLAB command R = 1:3:9 has been executed? 4 0 2 9 1 3

3

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; } 346913 34691319 3913 39 3193

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; } 3193 34691319 39 346913 3913

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 2 1 Nothing because the absence of the array declarator makes the definition of the array invalid 0 5

4

Given the code segment n=0; while n ~= 4 n = input('input number : '); switch n case 0 case 1 disp('less than 3') case 3 disp('equal to 3') otherwise disp('greater than 3') end end what input number will cause the loop to stop? it is an infinite loop 1 4 3 5 2

4

How many elements would be stored in R after the MATLAB command R = 1:2.5:9 has been executed? 0 1 3 5 4 2

4

Given the following data for an array 23 25 27 29 31 33 59 22 24 26 28 30 32 61 35 37 39 41 43 45 63 34 36 38 40 42 46 65 47 49 51 53 55 57 67 If the values were stored in an array called xyz, what would be output by the statement cout<<xyz[3][4]; 46 42 40 41 39

42

What will be the output of the following segment of code? int sum[2][2]; int a[2][2]={{1,2},{3,4}}; int b[2][2] = {{3,4},{5,0}}; for( int i =0; i<2;i++) { for( int j=0; j<2; j++) { sum[i][j]= a[i][j] + b[j][i]; cout<<sum[i][j]; } cout<<endl; } 47 74 nothing because a 2-dimensional array cannot be defined in this manner 46810 47710 44 77 4774 4477

47 74

Given the array X = [3, 5, 10, 8, 2, 7, 15, 6], what would be stored in p by the command [m,p] = min(X); ? 16 1 5 2

5

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

5

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

Given the row vector S = [2 6 8 1 9 3 7 5 4 9 1 6 2] what would be stored in T by the command T = S(8:-2:3)? 5 3 1 Nothing because an error is generated 7 9 8 2 5 3 1 6 8 9 7 4 4 7 9 8 9 7 4

5 3 1

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 15 5 20 0

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

What is the result of the following MATLAB command? 2 * 6 ^ 2 144 4096 72 Nothing because the expression is invalid 64

72

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? 9 2 3 4 0 8 1 2 7

8

Given the matrix z = [1 5 3; 2 4 6; 6 9 3], what would be stored in sumofz after the following MATLAB command is executed? sumofz = sum(z)' -9 18 12 -12 18 9 -9 -12 18 9 -1 5 3 2 4 6 6 9 3 -39 -9 12 18 -9 18 12

9 18 12

Given the matrix z = [1 5 3; 2 4 6; 6 9 3], what would be stored in sumofz after the following MATLAB command is executed? sumofz = sum(z) -12 18 9 -12 18 9 -9 18 12 -39 -9 18 12 -1 5 3 2 4 6 6 9 3 -9 -9 12 18

9 18 12

Given the MATLAB command y = x + 1 .* b .^ 4 / 5 which operation is performed last? ^ = .^ .* + /

=

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

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

Given the array B= [3 2 1 6 4; 4 8 3 5 4; 9 8 2 3 4; 6 7 8 1 2], which command would extract rows 2, 3, and 4 and combine them into a single column vector called C? C = B(2:4,:) C = B(5:17) C = [B(2,:), B(3,:), B(4,:)]' C = B(:,2:4) C = B(2:4) C = [B(2,:)', B(3,:)', B(4,:)']

C = [B(2,:), B(3,:), B(4,:)]'

What do you know about E after the MATLAB command E = randn(5) has been executed? E is a column vector containing five randomly distributed values between 0 and 1. E is a row vector containing five randomly distributed values between 0 and 1. E is an array containing 5 rows and 5 columns of Gaussian distributed values with an average of 0 and a standard deviation of 1. E is an array containing 5 rows and 5 columns of randomly distributed values between 0 and 1. E is a row vector containing five Gaussian distributed values between 0 and 1. E is a row vector containing five Gaussian distributed values with an average of 0 and a standard deviation of 1.

E is an array containing 5 rows and 5 columns of Gaussian distributed values with an average of 0 and a standard deviation of 1.

What do you know about E after the MATLAB command E = rand(5) has been executed? E is a row vector containing five Gaussian distributed values with an average of 0 and a standard deviation of 1. E is a column vector containing five randomly distributed values between 0 and 1. E is an array containing 5 rows and 5 columns of randomly distributed values between 0 and 1. E is an array containing 5 rows and 5 columns of Gaussian distributed values with an average of 0 and a standard deviation of 1. E is a row vector containing five randomly distributed values between 0 and 1. E is a row vector containing five Gaussian distributed values between 0 and 1.

E is an array containing 5 rows and 5 columns of randomly distributed values between 0 and 1.

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

In MATLAB every while loop can be rewritten as a for loop. True False False True

False

MATLAB will only allow you to create line plots. True False False True

False

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

False

The MATLAB ________________ window stores commands issued from various sessions in order from first to most recent. Editor History Current Folder Workspace Command

History

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; the incrementation of counter should be post-incrementation rather than pre-incrementation It is an infinite loop because the body of the while loop is actually an empty statement rather than sum += ++counter; The code sum += ++counter; is never executed because the condition of the loop evaluates to false from the beginning. the value of ++counter cannot be added to sum nothing is wrong

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

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]; Jupiter t (lower case) s (lower case) Mars Nothing because only 8 elements were listed and the definition requires 9 elements. S (upper case) nothing because you cannot create an array of string objects in C++

Jupiter

Which of the following statements is true? MATLAB has 2 logical operators: and, or MATLAB has 3 logical operators: and, or not MATLAB has 8 logical operators: and, or, xor, greater than, greater than or equal to, less than, less than or equal to, equal to. MATLAB has 5 logical operators: greater than, greater than or equal to, less than, less than or equal to, equal to. MATLAB has 4 logical operators: and, or, xor, not

MATLAB has 4 logical operators: and, or, xor, not

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; } 10 2 Nothing because the function prototype does not contain parameters Nothing because there is an error the function definition Nothing because there is an error the function call 2 10

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 20 elements which may be accessed by the subscripts 0 through 20 The array may hold up to 21 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 0 through 19 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 1 through 20

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. The code will compile and the size of the array will change as needed. Although there are syntax errors the code will still compile and can be executed. Although there are warnings the code will still compile and can be executed.

The code will not run because a syntax error occurs.

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

True

In MATLAB, the argument of a switch structure may be a string. False True

True

The MATLAB ________________ window lists the current variables and details of those variables. History Command Editor Workspace Current Folder

Workspace

If the result the MATLAB command cumsum(A) produces the array [2 6 12 7], what is stored in A it cannot be determined [2 4 6 -5] [-5 6 4 2] [7 12 6 2] [2 4 6 7]

[2 4 6 -5]

In MATLAB which of the following operators has highest precedence? xor / ^ > * + >=

^

Given the MATLAB command x = 1:0.25:10 which of the following MATLAB commands would generate an array called a that contains the values [1.75, 2.00, 2.25, 2.50, 2.75] using array x? a = x(3:7) a = x[4:8] a = x(5:9) a = x(4:8) a = x[3:8] a = x(3:8)

a = (4:8)

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? x only a only c only a and b b only c and d

a and b

Given the MATLAB command x = [1.1 2.3 5.6; 2.4 9.8 4.9; 7.7 3.3 4.4; 10.2 6.1 8.4;1.5 7.2 5.9]; the variable x is considered to be _______________________________ a column vector containing 15 values a matrix (array) containing 3 columns and 5 rows a row vector containing 15 values a matrix (array) containing 1 column and 5 rows a matrix (array) containing 5 columns and 3 rows

a matrix (array) containing 3 columns and 5 rows

Given the MATLAB command x = [1.1 2.3 5.6; 2.4 9.8 4.9; 7.7 3.3 4.4; 10.2 6.1 8.4;1.5 7.2 5.9]'; x is considered to be ____________ a matrix (array) containing 5 columns and 3 rows a matrix (array) containing 1 column and 5 rows a matrix (array) containing 3 columns and 5 rows a row vector containing 15 values a column vector containing 15 values

a matrix (array) containing 5 columns and 3 rows

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 all the values in the array add up the diagonal of the 2D array from upper right to lower left add up the diagonal of the 2D array from upper left to lower right sum each row and store the sums in an 1-dimensional array add up the diagonal of the 2D array from lower left to upper right sum each column and store the sums in an 1-dimensional array

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

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

consecutively

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

double somenumbers[65];

MATLAB requires that a condition for a while loop and an if to be enclosed in parentheses? True False

false

Given the following data for an array 23 25 27 29 31 33 59 22 24 26 28 30 32 61 35 37 39 41 43 45 63 34 36 38 40 42 46 65 47 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

Which of the following would output a number using a field width of 8 with 3 numbers to left of the decimal point (with a precision field of 3). The number has been stored in the variable feet. fprintf(%f, feet) fprintf(%8.3f,feet) fprintf('%8.3f',feet) fprintf('%0.3f\n',feet) fprintf('#8.3f',feet)

fprintf('%8.3f',feet)

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

function heading

In MATLAB the ______________ command allows the user to use the plot command multiple times adding new lines to the plot. title axes subplot hold off plotmore axis hold on

hold on

Which of the following statements are true? switches, loops, and function definitions may all be nested, but ifs may not be nested. ifs, switches, and function definitions may all be nested, but loops may not be nested. ifs, loops, and function definitions may all be nested, but switches may not be nested. no control structures may be nested. ifs, loops, and switches may all be nested, but function definitions may not be nested. ifs, loops, switches, and function definitions may all 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; else marker = marker - 1; } } } linear search binary search bubble sort selection sort insertion sort

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, int, char, char float, double, char, char double, int, string, char int, double, string, string int, double, string, char int , double, char, string double, double, string, string

int , double, char, string

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

it is faster than a linear search

Given the equation LaTeX: k_0e^{-\frac{Q}{RT}}\:=\:kk0e−QRT=k where k0, Q, and R have been defined as scalar constants and T is a row vector, which of the following MATLAB commands would correctly calculate a row vector for k corresponding to each temperature in the T row vector (no other variables are defined)? k = k0*exp(-Q./(R*T)) k = k0.*exp(-Q/R*T) k0*exp(-Q./(R*T))=k k0e(-Q/R*T) = k k = k0.*e.^(-Q./R*T) k = k0.*exp(-Q./R*T)'

k = k0*exp(-Q./(R*T))

The MATLAB ____________ command can be used to import variables that have been saved previously. load import save insert read

load

What would the following recursive function calculate? double Exam2Recur(double x, int n) { double ans; if n = 1; { ans = x; } else { ans = x * n * Exam2Recur(x,n-1); } return ans; The series 1 + x + x2 + x3 + x4 + x5 ........x^n x^n The series 1 * x * x2 * x3 * x4 * x5 ........x^n The series 1 + x + x2 + x3 + x4 + x5 ........x^n-1 n!x^n The series 1 + x + x2 + x3 + x4 + x5 ........x^n+1 x^n!

n!x^n

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

none as the if is NOT a loop

Given the code segment n=0; while n ~= 4 n = input('input number : '); switch n case 0 case 1 disp('less than 3') case 3 disp('equal to 3') otherwise disp('greater than 3') end end what will be output if the user enters 0? -less than 3 equal to 3 greater than 3 -equal to 3 -greater than 3 -less than 3 -nothing

nothing

Suppose we had the two MATLAB commands below: angles = [0: 0.1*pi: 2 * pi] sines = sin(angles) What would be the command to plot angles on the x axis and sines on the y axis? plot(angles,sines) polar(angles,sines) polar(sines, angles) lineplot(sines, angles) plot(sines, angles) lineplot(angles,sines)

plot(angles,sines)

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

In MATLAB the ___________ command will store variables in a *.mat file so they can be imported and used at a later time in another session. store keep you cannot store variables for use in a later session, you must re-issue the commands load save

save

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

selection (decition/branch)

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

selections, 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];

The ___________ function in MATLAB will return the number of rows and columns that an array (matrix) has. capacity length size container rowsandcolumns

size

MATLAB _________ command allows multiple plots of different types to be in the same figure. hold off grid on axis plotmore title subplot hold on grid off

subplot

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 all the elements of the array sum up the elements on the diagonal from upper right to lower left sum up the elements in each row and store in a new array 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 the elements on the diagonal from lower left to upper right

sum up all the elements of the array

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

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? nothing is wrong it only squares the number the function returns the wrong variable it calculates the number raised to the fourth power a syntax error occurs because the loop is missing braces

the function returns the wrong variable

Given the truth table where T is true and F is false condition 1 condition 2 condition 1 ? condition 2 T T T T F T F T T F F F what operator the ? represent? the logical operator not the relational operator not the relational operator xor the logical operator xor the relational operator greater than the logical operator or the relational operator or the logical operator and

the logical operator or

Given the truth table where T is true and F is false condition 1 condition 2 condition 1 ? condition 2 T T F T F T F T T F F F what operator the ? represent? the logical operator not the relational operator and the relational operator greater than the logical operator and the relational operator not the logical operator xor the relational operator xor the logical operator or

the logical operator xor

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 "function2" is an invalid function name "cin >> a >> b;" needs to be separated into 2 separate cin statements void is not permissible in the parameter list this is a void function, and therefore should not return a value

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);

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

true

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

void

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' || '2'|| '3'||'4') while (choice != '1' && choice != '2'&& choice !='3'&& choice != '4') while (choice > 4 || choice < 1) while (choice > 4 && choice < 1) while (choice == '1' && '2' && '3'&& '4') while (choice != '1' || choice != '2'|| choice !='3'|| choice != '4')

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

Given the MATLAB command x = 1:0.25:10 which of the following MATLAB commands would generate the same array for x? x = linspace(0, 10, 36) x = linspace(1:10: 0.25) x = linspace(1, 10, 40) x = linspace(0, 10, 0.25) x = linspace(1, 10, 0.25) x = linspace(1, 10, 37) x = linspace(0, 0.25, 10)

x = linspace(1, 10, 37)

Given the MATLAB command x = 10:-0.25:0 which of the following MATLAB commands would generate the same array for x? x = linspace(0,10,-40) x = linspace(10, 1, -0.25) x = linspace(10:0: -0.25) x = linspace(10, 0, 40) x = linspace(10, 0, 37) x = linspace(10, 0, 41) x = linspace(0, 10, -0.25) x = linspace(10, -0.25, 0)

x = linspace(10, 0, 41)


Related study sets

CAPITOLUL 1 Introducere în anatomie și fiziologie. Celulele și fiziologia celulară

View Set

AP Psych: Unit 13 LearningCurve Questions

View Set

Fitness Components and Principles Unit

View Set

Kinematics Concept Questions (Bloom)

View Set

Chapter 12 Business Policy Final, Chapter 11 Business Policy Final, chapter 9 Business Policy Final, Chapter 10 Business Policy Final

View Set