cs-Practice Test 1

cs-Practice Test 1 - Practice Test 1 Spring 2008 Problem 1...

Info iconThis preview shows pages 1–4. Sign up to view the full content.

View Full Document Right Arrow Icon
Practice Test 1 – Spring 2008 Problem 1 – Multiple Choice [30 Points] 1. If the following script is run in matlab, A = linspace(0,100,100); Which of the following vectors B would be equivalent to A ? A. B = 0:1:100 B. B = 0:100:100 C. B = 1:0.01:100 D. B = 0:(101/100):100 E. It is not mathematically possible to make this conversion. 2. The following script is executed a = true vec = [5 6 2] while a for i = vec disp 'CS rocks' end end How many times will ‘CS rocks’ be displayed? A. 6 times B. 5 times C. 2 times D. 3 times E. Infinite 3. The following MATLAB code is executed: str = 'mATLaB'; for k = length(str):-1:2 if lower(str(k)) > lower(str(k-1)) str(k) = char(str(k)+1); end end What is the value stored in variable str after all of the code above has been executed? A. ' mAULaB ' B. ' mAULAC ' C. ' mAVLaC ' D. ' mAULaC ' E. ' mATLaC '
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
4. Consider the following: A=[6,2,3,9]; B=mod(A,2); C=A(B(4)); A(C)=9; What is the final value of A? A. [6 2 3 9] B. [1 0 1 0] C. [6 2 3 9 0 9] D. [9 0 9 3 2 6] E. Error 5. Consider the following lines of code: A = {1:10, 'CS', [1 3 7 1], 1:10}; A(2)=[]; B=A{1}(2)+A{3} What is the value of B ? A. [4 5 6 7 8 9 10 11 12 13] B. [3 4 5 6 7 8 9 10 11 12] C. [3 5 9 3] D. 2 E. Error 6. Given a string, str, which of the following is a valid method of converting it only lowercase? I str = lower(str) II str = upperToLower(str) III index = find(str<=97) str(index) = str(index) + 32; IV str=str+32 A. I only B. I and IV C. II only D. II and III E. I and III 7. Below are two for loops that find the sum of all the values in x. A = 0; for index = 1:length(x) A = A + x(index); end B = 0; for index = x B = B + index; end What style of for loop does the A and B use? A. A and B uses indexing B. A and B uses direct-access C. A uses indexing; B uses direct-access D. A uses direct-access; B uses indexing
Background image of page 2
E. None of the Above 8. Consider the following code typed into MATLAB: ca={'Superman',7:-1:4,'Batman',1:10}; ca(5)={strcmpi(ca{1}(end:-1:end-3),ca{3}(end:-1:end-3))}; ca{3}=[]; What would the value of ca be at the end program: A. ca = 'Superman' [1x4 double] [] [1x10 double] [1] B. ca = 'Superman' [1x4 double] [1x10 double] [0] C. ca = 'Superman' [1x4 double] [] [1x10 double] [0] D. ca = 'Superman' [1x4 double] [1x10 double] [1] E. ca = 'Superman' [1x4 double] [1x10 double] [] [1] 9. The following MATLAB function is provided:
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 4
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 11

cs-Practice Test 1 - Practice Test 1 Spring 2008 Problem 1...

This preview shows document pages 1 - 4. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online