CS 103 #2 OTHER GUY

CS 103 #2 OTHER GUY - Test 2 CS 103 SPRING 2005 3 Your...

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

View Full Document Right Arrow Icon
Image of page 1

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

View Full Document Right Arrow Icon
Image of page 2
Image of page 3

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

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

Unformatted text preview: AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA Test 2 CS 103 SPRING 2005 . ' 3 Your Sectlon. 51‘ Honor Code Statement: Ipz'edgc my honor that I have neithergz'vcn nor received improper aid on this exam. 5:21;, _ .’ .-"_' i..—/-' . I Signature 1_ If “Ll/33;- W— TS- AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA 1 NOTE: Throughout the test, pm tr__ll answers completely in the gray blanks. l’ri're small r'rmrr 1h m it! Problem 1 (20 points) Write an UPPERCASE letter as your answer choice. I. Predicate means 8 . A. the function defined first in a file that includes more than one function . a function that returns a value that means true or false C. a mixture of your spoken language and Mallab used in program design {/14 a variable that maintains its value between calls ofthe same function Local scope means D. A. de lined in only one directory B. defined in only one file C. able to be calculated without using function calls D. able to be referenced inside only one function or in only the command window The following are in the Five-Step Process for Top—Down Design and in the correct order _ B . A. write the functions, write the scripts that call the functions, test the script B. write algorithm, write program, test program C. initialize counter initialize accumulator enter loop body l). initialize counter enter loop body, initialize accumulator 4. In t‘xlatlab True and False are indicated by 5,. (*K, A. True: ’ T' and False: ’ F’ 13. True : arty positive value and False : any non-positive value C. True : any positive or negative value and False : zero D. True : —l and False1+l N 5. Formal parameter means MB A. the index that is incremented in a for loop B. the variable that determines whether the body ofa whi 1e loop is executed C. a variable that receives an input value when a function is called \/6 3 l). a value that is passed into a function when it is called Persistence is D . A. the attribute ofa loop‘s conditional that permits infinite iteration B. the attribute ofa loop‘s conditional that permits re-entry into the body C. the attribute ofa variable that maintains the same value between loop iterations \/ D. the attribute ofa variable that maintains the same value between function calls 7 Examples of relational operators in Matlab are A . A. ~=, >, and c: B. 5:, l , and - \/ C. if. else. and elseif D. else. elseif. and otherwise 8. Examples of control constructs are C , A. local and global 13. input and output (for functions only) C. sequential and selection D. relational and logical \/9. An example oflogical short-circuiting is L}. A. a = b l l B. while x > y && a ~= b C. if x as y D. all ofthe above N 10. 1t‘lt’hen a function is called from Mallab‘s Command Window it is always true that B . A, each dummy argument receives a value from an argument in the call with the same name B. the name oftlre function in the call is the name given in the function heading C. the number of arguments in the call equals the number of dummy arguments D. none ofthe above AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAMA Problem 2 (25 points) Write a function called EA that takes either one or two input arguments (don‘t worry about the zero- argumenl case) and returns one outpttt argument. lfit is called with only one input argument, it returns the value ofthztt argument. If it is called with two arguments, it returns the smaller of the two. Here are example calls: >> a fA(4) a = >> b = fA(5,6) >> C = fA(8,7) 7 En End Problem 3 (25 points) The function flu) is defined as follows: f0) : 3 f(2) = 5 f(n) = 3f(n—2)—2f(n—l) forn23 So, for example, f(3) = 3f(l) — 2f(2) = 9— l0 = —1 , etc. For large enough in, f(n) is larger than 1000. Write code that will print (only) the first value ofn for \‘r’thhf(Jl) is larger than [000. 2 AtMAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAA Problem 4 (30 points) Suppose a matrix named A will be given to you. Without knowing its size, shape, or contents, you are to write code that will set the value of some ofthe elements ofA to zero. The rule that you are to follow is this: IFA (ii, jj) is greater than 3*ii- j j. then A (ii, jj) must be set to zero. Otherwise it must remain unchanged. So. for example, iii-t t4 , 5) equals 16, then it would be set to zero because 16 > 3 *4 75. On the other hand. it'A (10, 5) equals 20, then it would not be set to zero because 20 is not greater than 3 *10 —5. Precedence Operator Porettttteses E.t‘potterttt'tttiott tmtt' TI‘LtJtSpOJ‘E? Uttot'y -'r, —, and — tl’tttt'tip/imtion and Division Addition road Subtraction Cofott operator Rotational operators & I am WOUNCN'JIAL-Jruk 3 ...
View Full Document

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern