Docsity

COMP 200 Final.docx....COMP 200 Final.docx, Exams of Nursing

Toggle sidebar
bg1
COMP 200 Final
Consider the following code fragment:
x = 2;
while x < 13
fprintf('We are the music makers, ')
fprintf('and we are the dreamers of dreams.\n')
x = x + 1.6;
end
How many lines of output will display in the Command Window?
a. 8 b. 16 c. 14 d. 7 - correct answer D
What is an issue with trying to time computer code runs?
a. Run times can vary from run to run, especially if other tasks are competing for
time on the processor.
b. The operating system (OS) can make adjustments to the system clock, so using
the system clock for timing presents difficulties.
c. Both A and B are correct.
d. None of the above - correct answer C
n terms of amounts of required storage, how do these data types compare?
a. single < complex number consisting of singles < double
b. single < double < complex number consisting of singles
c. double < complex number consisting of singles = single
d. single < complex number consisting of singles = double - correct answer D
In MATLAB, which relational operator can be used to check if two variables are not
equal to each other?
a. !=
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15
pf16
pf17

Partial preview of the text

Download COMP 200 Final.docx....COMP 200 Final.docx and more Exams Nursing in PDF only on Docsity!

COMP 200 Final

Consider the following code fragment: x = 2; while x < 13 fprintf('We are the music makers, ') fprintf('and we are the dreamers of dreams.\n') x = x + 1.6; end How many lines of output will display in the Command Window? a. 8 b. 16 c. 14 d. 7 - correct answer D What is an issue with trying to time computer code runs? a. Run times can vary from run to run, especially if other tasks are competing for time on the processor. b. The operating system (OS) can make adjustments to the system clock, so using the system clock for timing presents difficulties. c. Both A and B are correct. d. None of the above - correct answer C n terms of amounts of required storage, how do these data types compare? a. single < complex number consisting of singles < double b. single < double < complex number consisting of singles c. double < complex number consisting of singles = single d. single < complex number consisting of singles = double - correct answer D In MATLAB, which relational operator can be used to check if two variables are not equal to each other? a. !=

b. <> c. == d. ~= - correct answer D A sparse matrix is a matrix where: a. The elements are zeros below the diagonal and non-zero above the diagonal. b. Non-zero elements are confined to a diagonal band comprising the main diagonal, and it can have zeros or more diagonals on either side of the main diagonal. c. Most of the elements are zero. d. Most of the elements are non-zero - correct answer C Consider the following code fragment: x = [1 3 6]; j = 0; for i = 1: while j < 3 for k = x % Nothing end if j/3 == 0 j = j + 2; else j = j + 1; end end end What will be the value of j at the end of this code fragment? a. 4 b. 5 c. 3 d. 6 - correct answer C Consider the following code fragment:

y = y +2; end What will be the value of y at the end of a run of this code? a. 7 b. 4 c. 6 d. 3 - correct answer D What statement will print as a result of a run of this code fragment? x = [4 3]; if x == 3 disp('Pikachu') elseif x == 4 disp('Squirtle') elseif x <= 3 disp('Charmander') else disp('Bulbasaur') end a. Pikachu b. Squirtle c. Bulbasaur d. Charmander - correct answer C What is a characteristic of a flowchart? a. It is a verbal description of computer code. b. It is a graphical representation of how computer code flows or progresses, and itis constructed with well-defined conventions. c. It is an intermediate step between everyday language and a programminglanguage. d. None of the above - correct answerB What is the role of continue? a. To skip the rest of the current loop iteration, advancing to the next loop pass b. To force MATLAB to not rest between loop iterations c. To give MATLAB an opportunity to rest between loop iterations

d. To cause the termination of the smallest enclosing loop - correct answerA hat is the advantage of short circuit evaluation? a. When checking the logic you must evaluate all the terms b. When checking the logic you don't evaluate the other terms(s) if you find you do not need to do so c. There is no advantage to short circuiting; it is merely a style preference d. There is no advantage to short circuiting; it forces MATLAB to evaluate the logic instead of permitting it to cut corners - correct answerB In languages that support the do while loop, what distinguishes it from the while loop? a. The do while loop is a pre-test loop b. The do while loop is guaranteed to run at least once c. Both A and B are correct d. None of the above - correct answerB Which of these units of information can store exactly 1 logical variable? a. byte b. kilobyte c. bit d. kilobit - correct answerC Generally, when is a good time to use a while loop instead of a for loop? a. You should always use a for loop; you can always break out of the loop when you are ready for the loop to terminate. b. When you can only know a posteriori ("after the fact") how many times the loop will need to execute. c. Use should always use a while loop; you can always use a counter to keep track of how many times the loop will have to run. d. When you know or can calculate a priori ("before the fact") how many times theloop will need to execute - correct answerB

What is code vectorization? a. A programming technique that uses vector operations instead of element-by- element loop-based operations. b. A programming technique that uses elements stored in vectors instead of multiple scalar variables. c. A programming technique that uses element-by-element loop-based operations instead of vector operations. d. A programming technique that uses multiple scalar vectors instead of elements stored in vectors - correct answerA Consider the following code fragment: k = 1; for i = 1: for j = 3: k = k + 1 end end What will be the value of k at the end of a run of this code? a. 6 b. 3 c. 7 d. 2 - correct answerC Generally, sections of computer code can be categorized into three separate categories.Which of the following is NOT one of those categories?a. Sequences b. Selection structures c. Repetition structures d. Vectorized - correct answerD Consider the following code fragment: w = [1 5 4 3] x = find(w<=3) What will be the value of x at the end of a run of this code? a. x = [1 3]

b. x = [] c. x = [1 4] d. x will not have a value due to (a) syntax error(s) - correct answerC Consider the following code fragment: A = 2; for k = 0:2: A = [A, A*k]; end B = A What will be the value of B at the end of a run of this code fragment? a. B = 2,0,0, b. B = 2 0 4 0 8 0 16 0 c. B = 2 2 0 2 0 0 2 0 0 0 d. B = 2 2 4 8 - correct answerB Which command will delete (i.e. completely remove) the last cell of a cell-array C? a. C[end] = []; b. C{end} = []; c. C(end) = []; d. C{end} = {[]}; - correct answerB Consider the following code fragment: for i=1: for j=i: C(i,j) = i + j; C(j,i)= C(i,j);

Generally, for performance reasons, it is preferable to use built-in MATLAB features such as the find command (when practical) instead of MATLAB loops. a. True b. False - correct answerA If MATLAB finds a true case in a switch, it will continue checking the other cases. a. True b. False - correct answerB An exclusive or evaluates as false when either inputs A or B (but not both) are non- zero. a. True b. False - correct answerB The ' operator and the transpose command both compute transposes, but these two techniques do not behave identically under all circumstances. a. True b. False - correct answerA For personal computers (PCs) or laptops, chars in MATLAB are represented by their ASCII value when stored in memory. a. True b. False - correct answerA Every if needs an else, but not every else needs an elseif. a. True b. False - correct answerB In MATLAB, what would be result of this expression? FALSE || (TRUE && FALSE) a. True b. False - correct answerB

The default numeric data type in MATLAB is the double. a. True b. False - correct answerA Matrix multiplication is commutative for any square matrix. a. True b. False - correct answerB A matrix š“ is invertible if its determinant is not equal to 1. a. True b. False - correct answerB In MATLAB, which relational operator can be used to check if two variables are equal to each other? a. != b. = c. == d. ~= - correct answerC Consider the following code fragment: A = true; B = false; C = ~((A || B) && ~(B && A)); if CD = 'Home Skillet' else D = 0 end What data type will D be at the end of this code fragment? a. char

What statement will print from the following code fragment? x = [2 1]; if x == 2 disp('Bulbasaur') elseif x == 1 disp('Pikachu') elseif x >= 2 disp('Squirtle') elsedisp('Charmander') end a. Charmander b. Bulbasaur c. Pikachu d. Squirtle - correct answerA A dense matrix is a matrix where: a. Non-zero elements are confined to a diagonal band comprising the main diagonal,and it can have zeroes or more diagonals on either or both sides of the main diagonal b. Most of the elements are zero c. Most of the elements are non-zero d. The elements are zeroes below the diagonal, and non-zero above the diagonal - correct answerC What will be the value of y after a run of this code fragment? z = 4; x = 3; y = z == x a. 0 b. 1 c. 4 d. Nothing; due to (a) syntax error(s), this code fragment will fail to fully execute - correct answerA

How much memory would be required to store a dense 50 x 50 matrix of single precision floating point numbers? a. 10 MB b. 20 KB c. 20 MB d. 10 KB - correct answerD Consider the following code fragment: count = 1; for i = 1: j = 0; count = count + 1; while j < 3 j = j + 1; m = 2; for k = 1: while m < 2m = m + 2; count = count + 1; end end end end disp(count) What will be the value displayed in the Command Window after this code is run? a. Impossible to determine, since this code fragment will result in an infinite loop b. 5 c. 1 d. 15 - correct answerB What will be stored in my_entree at the end of a run of this code fragment? entrees = {'Sole''Chicken''Beef'}

What is the role of continue? a. To skip the rest of the current loop iteration, advancing to the next loop pass b. To force MATLAB to not rest between loop iterations c. To give MATLAB an opportunity to rest between loop iterations d. To cause the termination of the smallest enclosing loop - correct answerA You have two square 2 x 2 matrices A and B. You want to manipulate the matrices so that it has the practical effect of x = [A, B]. Which of these commands would result in the variable y having the same value as x? a. y = vertcat(A,B) b. y = cat(A,B) c. y = horzcat(A,B) d. Both a) and c) would work - correct answerC What is the role of a sentinel value? a. To keep track of - or count of - an event or occurrence b. To keep watch for a specific occurrence so that a loop can be terminated c. To act as a special indicator for the start of a while loop d. To teach children how to count - correct answerB What important consideration do you have to make when you want to study code execution times? a. Due to variances in other processes controlled by the OS, it is a good idea to run your code multiple times to get a true indication of its performance b. Code runs are static in nature; while they do change from machine to machine,they should be identically consistent on any one machine c. Most computer languages are converted to machine language that has similar execution times d. The best measure of wall time is to measure the amount of time each CPU spent on a given task, and then sum those times together - correct answerA

How large is a logical variable? a. 1 byte b. 2 bits c. 2 bytes d. 1 bit - correct answerD You have a system of simultaneous linear equations. You know that once put into the matrix form š“š‘„ = š‘ that š“ is square and non-invertible. Generally speaking, from a computational point of view, which is the best approach to solving this system? a. Using the \ operator b. Such a system has no exact solution c. Using the / operator d. Using the matrix inverse - correct answerB What will be the value of counter at the end of a run of this code fragment? counter = 0 for k = 1: if k < 2 && k > 5 counter = counter + 1; end end a. There is (a) syntax error(s), so the code fragment will not run to completion b. counter = 5 c. counter = 0 d. counter = 1 - correct answerC Consider the following code fragments. If each of those code fragments were to be run, which one would produce a scalar value of S identically equal to 13?

y = y - 1; end end What will be the value of x at the end of a run of this code fragment? a. 15 b. 24 c. 6 d. 3 - correct answerA The magnitude of a vector can be calculated via the built-in function a. abs() b. absolute() c. norm() d. length() - correct answerC Which of the following is true of MATLAB switches? a. Switches can be used any time if statements are used b. Switches have faster evaluation times than if statements c. MATLAB switches will stop checking cases once a true case is discovered d. MATLAB switches check all of the cases, even if a true case is already discovered - correct answerC Chars in MATLAB are represented by what value in memory? You may assume that this question refers to an installation of MATLAB on a personal computer (PC). a. EBCDIC value b. Hexadecimal value c. ASCII value d. Decimal value - correct answerC

Which of the following is a valid for loop index? a. Cell array b. Scalar c. Structure array d. Multidimensional array - correct answerB What is the role of break? a. To skip the rest of the current loop iteration, advancing to the next loop pass b. To force MATLAB to not rest between loop iterations c. To cause the termination of the smallest enclosing loop d. To give MATLAB an opportunity to rest between loop iterations - correct answerC When it is available in a particular language, when is a good time to use a do while loop? a. If you know a priori ("before the fact") how many times the loop will need to execute b. When you can only know a posteriori ("after the fact") how many times the loop will need to execute, but you know the loop will need to run at least once c. When you do not know a priori ("before the fact") how many times the loop will need to execute, but you have a way of calculating the required number of iterations d. When you can only know a posteriori ("after the fact") how many times the loop will need to execute, and you do not know if the loop will even need to run at all - correct answerB In general, for performance reasons it is generally preferable to use built-in functions such as the find command (when practical to use) instead of using loops in MATLAB. a. True b. False - correct answerA