CSCI05final.doc

10
SANTIAGO CAMPUS PRELIM EXAM CSCI05 (Data Structures and Algorithm) Instructions: No ID, No test booklet, No permit means NO EXAM. Write your answers and solutions in your test booklet. Too much erasure will deducted from your points. (Perfect score is 50 points) I. Multiple Choices. Write the letter of your choice for each of the items on the answer sheet provided for. Use Capital Letter. Erasure means wrong. (100 points, 1 point each) 1. The values of this type of data are single symbols such as letter, number, or special symbol. a. double c. string b. char d. Long 2. What values is stored in quotient (if quotient is of type int), when the following expression is evaluated. quotient = 12 / 10 % 10 + 10; a. 10.12 c. 12.3 b. 10.10 d. 11 3. What, if anything, prints when each of the following C++ statements is performed? Assume x = 2 and y = 3. cout << x; a. 2 b. 3 c. 5 d. 4 4. What, if anything, prints when each of the following C++ statements is performed? Assume x = 2 and y = 3. cout << x + x; a. 2 b. 4 c. 5 d. 3 5. What, if anything, prints when each of the following C++ statements is performed? Assume x = 2 and y = 3. cout << "x="; a. 2 b. 3 c. x= d. "x=" 6. What, if anything, prints when each of the following C++ statements is performed? Assume x = 2 and y = 3. cout << "x = " << x; a. x=2 b. 2 c. x = x d. 22

Transcript of CSCI05final.doc

Page 1: CSCI05final.doc

SANTIAGO CAMPUSPRELIM EXAM

CSCI05 (Data Structures and Algorithm)Instructions: No ID, No test booklet, No permit means NO EXAM.

Write your answers and solutions in your test booklet.Too much erasure will deducted from your points.

(Perfect score is 50 points)

I. Multiple Choices. Write the letter of your choice for each of the items on the answer sheet provided for. Use Capital Letter. Erasure means wrong. (100 points, 1 point each)

1. The values of this type of data are single symbols such as letter, number, or special symbol.a. double c. string b. char d. Long

2. What values is stored in quotient (if quotient is of type int), when the following expression is evaluated.quotient = 12 / 10 % 10 + 10;a. 10.12 c. 12.3b. 10.10 d. 11

3. What, if anything, prints when each of the following C++ statements is performed? Assume x = 2 and y = 3. cout << x;

a. 2 b. 3 c. 5 d. 4

4. What, if anything, prints when each of the following C++ statements is performed? Assume x = 2 and y = 3. cout << x + x;

a. 2 b. 4 c. 5 d. 3

5. What, if anything, prints when each of the following C++ statements is performed? Assume x = 2 and y = 3. cout << "x=";

a. 2 b. 3 c. x= d. "x="

6. What, if anything, prints when each of the following C++ statements is performed? Assume x = 2 and y = 3. cout << "x = " << x;

a. x=2 b. 2 c. x = x d. 22

7. What, if anything, prints when each of the following C++ statements is performed? Assume x = 2 and y = 3. cout << x + y << " = " << y + x;

a. x+y = y +x b. x+y = 5 c. 5 = 5 d. nothing

8. What, if anything, prints when each of the following C++ statements is performed? Assume x = 2 and y = 3. z = x + y;

a. x + y b. 5 c. 2 d. Nothing

9. What do you call on the error where program runs to completion, but the results are wrong. a. Link error b. Compile error c. Logical error d. Run time

error

Page 2: CSCI05final.doc

10. Which of the following is TRUE about the break in switch statement?a. it is optional c. it is requiredb. enters you to switch d. found before each case

11. The Boolean expression if and if-else statement is always enclosed with what specific symbols?a. braces c. bracketsb. slash d. Parenthesis

12. What is the output of the following when included in a correct and complete program?int x = 5; if ( x <10 ) cout<< x; x = x + 5;

a. 5 c. 10 b. no output d. Error

13. The type of all elements in an array must be the same.a. always c. never

b. sometimes d. can’t determine

14. How do you declare an array named number that could contain 10 integers? a. int number[]; c. int number[10]; b. int[10] number; d. int[] number;

15. Which of the following array initialization statements is valid? a. int array{ } = {1, 2, 3, 4}; c. int array [ ] = [1, 2, 3, 4]; b. int array{ 4 } = {1, 2, 3, 4}; d. int array [ 4] = [1, 2, 3, 4];

16. The following are not correct about statement: sum = num[1] + num [2], except a. sum contains the sum of the first and second element of the array num b. sum contains the sum of 1 and 2 c. sum contains the sum of any two numbers in array num d. sum contains the sum of the second and third element of array num

17. How many elements does the array declared below have?double m[2][4];

a. 2 c. 6 b. 4 d. 8

18. What is the correct value to return to the operating system upon the successful completion of a program?

a. -1 c. 0 b. 1 d. Programs do not return a value.

19. What is the only function all C++ programs must contain? a. start() c. system() b. main() d. program()

20. What punctuation is used to signal the beginning and end of code blocks? a. { } c. -> and <- b. BEGIN and END d. ( and )

Page 3: CSCI05final.doc

21. What punctuation ends most lines of C++ code? a. . c. ; b. : d. ‘

22. Which of the following is not a correct variable type? a. float c. real b. int d. Double

23. Which of the following is the correct operator to compare two variables? a. := c. equal b. = d. = =

24. Which of the following shows the correct syntax for an if statement? a. if expression c. if{ expression } b. if( expression) d. expression if

25. What is the final value of x when the code int x; for(x=0; x<10; x++) {} is run? a. 10 c. 9 b. 0 d. 1

26. When does the code block following while(x<100) execute? a. When x is less than one hundred c. When x is equal to one hundred b. When x is greater than one hundred d. While it wishes

27. Which is not a loop structure? a. For c. While b. Do while d. Repeat Until

28. What is the output when the following code fragment is executed?int i = 5, j = 6, k = 7, n = 3;cout << i + j * k - k % n << endl;cout << i / n << endl;

a. 46 b. 46 c. 76 d. 76 1 1. 667 1 1.667

29. After the following block of code has run, what is the value of each variable? Write values in the box. Show supporting

work for partial credit. double a = 3.9; double z;int n = 3; int y;n = (a/n)*2; y = n + 4; z = (y+1)/2 + a;

What will be the value of n? a. 2.6 b. 2.66 c. 2 d. NONE OF THE ABOVE

30. From the item #29, what will be the value of z? a. 7.4 c. 6.9 b. 6 d. NONE OF THE ABOVE

31. From the item #29, what will be the value of y? a. 7 c. 7.1 b. 6.5 d. NONE OF THE ABOVE

Page 4: CSCI05final.doc

For items 32 -38:From the program below

#include <iostream.h>main(){int n;cout << (n = 4) << endl;cout << (n == 4) << endl;cout << (n > 3) << endl;cout << (n < 4) << endl;cout << (n = 0) << endl;cout << (n == 0) << endl;cout << (n > 0) << endl;cout << (n && 4) << endl;cout << (n || 4) << endl;cout << (!n) << endl;return 0;

}

32. What will be the value of (n || 4)? a. 4 b. 1 c. n d. error

33. What will be the value of (n && 4)? a. 0 b. 1 c. 4 d. Error

34. What will be the value of (!n)? a. 0 b. 1 c. 4 d. error

35. What will be the value of (n>3)? a. 0 c. 4 b. 1 d. Error

36. What will be the value of (n = 4)? a. 0 c. 4 b. 1 d. Error

37. What will be the value of (n == 4)? a. 0 c. 4 b. 1 d. Error

38. What will be the value of (n< 4)? a. 0 c. 4 b. 1 d. Error

For items 39-41:

Answer the questions below concerning the following fragment of code.int n;cout << "Enter an integer: ";cin >> n;if (n < 10)cout << "less than 10" << endl;

Page 5: CSCI05final.doc

else if (n > 5)cout << "greater than 5" << endl;elsecout << "not interesting" << endl;

39. What will be the output of the fragment above if the interactive user enters the integer value 0 ?

a. less than 10 c. greater than 10 b. equal to zero d. error

40. What will be the output of the fragment above if the interactive user enters the integer value 15 ?

a. less than 15 c. equal to 15 b. greater than 15 d. error

41. What will be the output of the fragment above if the interactive user enters the integer value 7 ?

a. less than 10 c. greater than 10 b. equal to zero d. Error

42. Evaluate !(1 && !(0 || 1)). a. True c. Error b. False d. Unevaluatable

43. Assume i = 1, j = 2, k = 3 and m = 2. What does each of the following statements print?

cout << ( i == 1 ) << endl;

a. 1 b. 2 c. i d. Nota

44. Assume i = 1, j = 2, k = 3 and m = 2. What does each of the following statements print?

cout << ( j == 3 ) << endl;

a. 1 b. 2 c. 3 d. 045. Assume i = 1, j = 2, k = 3 and m = 2. What does each of the following

statements print? cout << ( m <= 99 && k < m ) << endl;

a. 1 b. 2 c. 3 d. 0

46. Assume i = 1, j = 2, k = 3 and m = 2. What does each of the following statements print?

cout << ( j >= i || k == m ) << endl;

a. 1 b. 2 c. 3 d. 0

47. Assume i = 1, j = 2, k = 3 and m = 2. What does each of the following statements print?

cout << ( j >= i || k == m ) << endl;

a. 1 b. 2 c. 3 d. 0

48. Assume i = 1, j = 2, k = 3 and m = 2. What does each of the following statements print?

cout << ( k + m < j || 3 - j >= k ) << endl;

Page 6: CSCI05final.doc

a. 1 b. 2 c. 3 d. 0

Page 7: CSCI05final.doc

49. Assume i = 1, j = 2, k = 3 and m = 2. What does each of the following statements print?

cout << ( !m ) << endl;

a. 1 b. 2 c. 3 d. 0

50. Assume i = 1, j = 2, k = 3 and m = 2. What does each of the following statements print?

cout << ( !( j - m ) ) << endl;

a. 1 b. 2 c. 3 d. 0

51. Assume i = 1, j = 2, k = 3 and m = 2. What does each of the following statements print?

cout << ( !( k > m ) ) << endl;

a. 1 b. 2 c. 3 d. 0

52. Write a for loop that counts from 0 to 5. a. for (c = 0; c <= 5; c++) b. for (int c = 0; c <= 6; c++) c. for (c = 0; c < 5; c++) d. for (c = 0; c < 5; c++);

53. Every function in C++ are followed bya.    Parameters c.     Curly bracesb.    Parenthesis d.  None of these

54. Which of the following is false?a.    Cout represents the standard output stream in c++.b.    Cout is declared in the iostream standard filec.    Cout is declared within the std namespaced.    None of above

55. Regarding following statement  which of the statements is true? 

const int pathwidth=100;  a.    Declares a variable pathwidth with 100 as its initial value  b.    Declares a construction pathwidth with 100 as its initial value  c.    Declares a constant pathwidth whose value will be 100.

56. In an assignment statement a=b;Which of the following statement is true?a.    The variable a and the variable b are equal.b.    The value of b is assigned to variable a but the later changes on variable b will not

affect the value of variable ac.    The value of b is assigned to variable a and the later changes on variable b will affect

the value of variable ad.    The value of variable a is assigned to variable b and the value of variable b is

assigned to variable a.

57. To increase the value of c by one which of the following statement is wrong?a. c++; b. c = c + 1; c. c + 1 => c; d. c += 1

58. When following piece of code is executed, what happens? b = 3; a = b++;a. a contains 3 and b contains 4b. a contains 4 and b contains 4c. a contains 4 and b contains 3

Page 8: CSCI05final.doc

d. a contains 3 and b contains 3

59. Which of the following is false for switch statement in C++?a. It uses labels instead of blocksb. we need to put break statement at the end of the group of statement of a conditionc. we can put range for case such as case 1..3d. None of above

60. The difference between while structure and do structure for looping isa. In while statement the condition is tested at the end of first iterationb. In do structure the condition is tested at the beginning of first iterationc. The do structure decides whether to start the loop code or not whereas while statement

decides whether to repeat the code or notd. In while structure condition is tested before executing statements inside loop whereas in

do structure condition is tested before repeating the statements inside loop

Prepared by: Checked by:

Tirso Llantada, ECE Engr. Mary Jane Laranang, MSIT, MCPInstructor College Dean

Prepared by: Approved by:

Mrs. Michelle M. Caranguian, CpE Mr. Jun-jun C. Bucayu,CpEMr. Jay Ventura, CpEMr. Tonison Talaue, CpE