CS1371_PracticeTest1_Solutions_Fall_2007

# CS1371_PracticeTest1_Solutions_Fall_2007 - ii ‘big...

This preview shows pages 1–3. Sign up to view the full content.

CS 1371 Practice Test – Fall 2007 Problem 1 – Vector Manipulation A. A = [1 3 5 7 9 -1 13 15 17 19] B = [1 2 4 7 8] C = [9 11 13 15 17 19 1 3 5 7 9] D = [12 6 16] B. 1. vec1 = linspace(89, 101, 20) 2. vec2 = [vec1((length(vec1)/2+1):end) vec(1:length(vec1)/2)] 3. [M, L] = min(vec2) C. 1. True 2. False 3. True Problem 2 – String Manipulation A. 1.) function ret = isAnagram(word1, word2) W1 = sort(word1); W2 = sort(word2); ret = strcmp(W1, W2); 2.) ind = find(A == ' ') A(ind) = [] B. 1.) a. a1 = 'z love zz1371!' b. Code produces an error because ret(ind-1:ind) = ‘CS’ in this case tries to access an index of 0

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

View Full Document
2.) a. No b. char Problem 3 – Conditionals A. 1. Between lines 5 and 6, there should be an end to complete the nested if-statement. 2. i.) ‘frugal’
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: ii.) ‘big spender’ ii.) ‘broke’ B. function amnt = paretalAid(stat) switch stat case {'broke', 'in debt'} amnt = 200; case 'fine' amnt = 50; otherwise amnt = 0; end Problem 4 – Iteration A. 1. 3 times 2. 9 3. [3 0 7 4 6 1] 4. The loop would not terminate because prod(vec) would always be positive and not approach zero. B. C = [0 0 0 1 0 1] D = [10 7] E = [1 3 5 8] Problem 5 – Cell Arrays A. 1. a) ‘dppm’ b) Char { [ 1 3 7] } c) Cell 2. a.) 3 b.) {[2 5 0], true, [33 3]} c.) {[2 5 0] [33 3]} B. function vec = longV(ca) vec = ; for ind = 1:length(ca) if isnumeric(ca{ind}) vec = [vec ca{ind}]; end end Thanks to Jacey Planteen for her help on the test. Last Modified: 3:15PM September 16 th 2007 by Shardul Bhatia...
View Full Document

{[ snackBarMessage ]}

### Page1 / 3

CS1371_PracticeTest1_Solutions_Fall_2007 - ii ‘big...

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

View Full Document
Ask a homework question - tutors are online