Second CIS 71 Exam - Spring '96 Name__________________________ What is the value (True or False) of expressions 1 - 6 when X = 5, Y = 3, and Flag is 1 (true). 1. (X == Y) || (Y <= 3) T 4. Flag && (X > Y) T 2. (X >= 0) && (X <= Y) F 5. Flag && (!Flag) F 3. (!Flag) || ((X - 2) != Y)F 6. Flag || (!Flag) T 7. If we remove the parentheses in expression 2, the expression will still be valid. (T/F). T 8. In a program with multiple functions, the functions execute in the order in which they are declared. (T/F) F 9. If x is positive, the value of sqr(sqrt(x)) is the same as sqrt(sqr(x)). (T/F) F - no sqr function 10. If x is positive, the value of floor(x + 0.5) is the same as ceil(x - 0.5). (T/F) T 11. The IF statement below displays the string "O.K." (T/F) T var1 = 15.0; var2 = 25.12; if (var2 <= 2 * var1) printf("O.K.\n"); else printf("NOT O.K.\n"); Use the if statements below to answer questions 12 to 18. if (S == '*') if (T > 50) Y = 25; else if (T > 40) Y = 30; else if (T > 30) Y = 35; else Y = 20; else Y = 40; if (Y < 25) then Y = Y + 5; For the values of S and T in questions 12 to 17, pick the LAST value assigned to Y from the list below a. 20 b. 25 c. 30 d. 35 e. 40 12. S = '+', T = 35 e 15. S = '*', T = 0 b 13. S = '*', T = 60 b 16. S = '*', T = 35 d 14. S = '*', T = 50 c 17. S = '*', T = 45 c If Operator is type char, use the switch statement below to answer questions 18 -24 switch (Operator) { case '+': case '*': printf("%c\n", Operator); break; case 'A': case 'a': printf("A"); case 'B': printf("B"); break; default: /* do nothing */ } Pick an answer from the list below for the questions that follow. a. Prints + b. Prints * c. Prints A d. Prints B e. None of above 18. What happens when Operator is '-'? e. 19. What happens when Operator is 'A'? e. 20. What happens when Operator is 'a'? e. 21. What happens when Operator is 'B'? d. 22. What happens when Operator is 'b'? e. 23. What happens when Operator is '*'? b. 24. What happens when Operator is '+'? a. 25. A diagram of the hierarchical organization of the subproblems of a solution is called ______. e. a. stepwise refinement b. divide and conquer c. a top-down approach d. function calls e. a structure chart For questions 26 - 30, pick the correct answer from the list below: a. -15 b. -16 c. 15 d. 16 e. 17 26. ceil(-15.8) a. 29. pow(abs(-4), 2) d 27. floor(fabs(-15.8)) c. 30. ceil(-15.8 - 0.5) b 28. ceil(pow(4.0, 2) + 0.5) e True/False 31. A selection step chooses between alternative actions. T 32. Functions can be called several times from different points in a program because for each call the program keeps track of the statement to which control returns after the function finishes its last step. T 33. If f1 and f2 are the names of functions declared at the beginning of a C program using prototypes void f1(void); void f2(void); then the statement sequence below is legal in function main. T f1(); f2(); f1(); 34. The preprocessor directive #include should be present in a program that calls the fabs library function. T 35. A function that takes no arguments is more versatile than a function that requires arguments. T 36. Functions are permitted to have only one input argument. F 37. After the last statement of a function executes, control is transferred to the next defined function. F 38. The following program segment gives x and y the same value when x is larger than y (True/False) T if (x > y) { y = x; x = y; } 39. The statements on the left always give p the same value as the code on the right, but the code on the right may execute faster. F if (x > 15) if (x > 15) p = p * x; p = p * x; if (x > 30) else if (x > 30) p = 2 * p * x; p = 2 * p * x; Multiple Choice 40. Which one of these is not the name of a C library function? a. printf b. sqrt c. void d. scanf e. log c 41. Which of the following statements calls function abc? Assume abc has a single argument and returns a type double result. a. call abc; b. abc; c. p = abc(q); d. void abc(void); e. none of the above c 42. The effect of the following program segment can best be described as __________. if (x > y) z = x; if (x == y) z = 0; if (x < y) z = y; c a. The smaller of x and y is stored in z. b. The larger of x and y is stored in z. c. The larger of x and y is stored in z unless x and y are equal, in which case z is assigned zero. d. The larger of x and y is stored in z unless x and y are not equal, in which case z is assigned zero. e. none of the above 43. Which statement below best applies to the program fragment in 42. a. This is the most efficient way to perform this operation. b. It would be more efficient to implement this as a switch statement. c. It would be more efficient to implement this as a multiple- alternative if statement. d. This is an example of a nested if statement. e. none of the above. c. 44. If the input to the program segment at the right is 85, what is its output? Read each condition carefully. c. a. A scanf("%d", &s); b. B if (s >= 90) c. C printf("A\n"); d. D else if (s >= 70) e. C printf("C\n"); B else if (s >= 80) printf("B\n"); else printf("D\n"); 45. What will be the value of i after the C statements at the right execute? c. a. 5 i = 3; b. 6 j = 10; c. 8 if ((3 * i) < j) d. 10 i = i + 2; e. 15 i = i + 3;