CompSci U1 P1 2021

You might also like

Download as pdf
Download as pdf
You are on page 1of 12
the following devices should be used to properly close all open files and log off the computer properly when there is an (B) Voltage regulator (©) PDA (D) UPS ‘What is the name of the combinational circuit which converts binary information from n coded inputs to a maximum of 2° unique outputs? (A) Decoder (B) Encoder (C) Logic gate (D) Multiplexer Item 4 refers to the following progr ‘segment written in low-level instructions. LOAD X // load contents of X to accumulator register ADD ine // add contents of ine to accumulator register STORE X // store contents of accumulator register to X Which address instruction format is used by the computer? (A) Zero address (B) One address (C) ‘Two address (D) Three address Item 5 refers to Figure | and Figure 2. ‘The number of clock cycles the CPU executes per second (B) The number of bits transferred 4 across a medium in one second (©) The speed at which the micro- processor executes instructions (D) The speed at which the micro processor transfers data from secondary storage to primary memory 7. The decode part of the fetch-decode- execute cycle in a computer involves (A) determining the operands (B) determining the operation (©) finding the location of an instruction (D) extracting the data for the various instruction fields 8. What is the LARGEST integer that can be represeiited in a 4*bit signed magnitude? (A) +18 A). +15 iO. +7 Q #8 9 The decimal equivalent of the ASCII representation of ‘A’ is65. What isthe decimal equivalent of the ASCII representation of “J”? A) 73 B® 14 Which of the following reduces mi in speeds between CPU and memory ack (A) Memory interleaving (B) Using cache memory (C) Decreasing memory size , (D) Fixing the variable length : Which of the following is NOT an advantage of storage devices over main memory? (A) Less volatility (B) Greater probability (C) _ Greater response time (D) Larger storage capacity Which of the following computers is the MOST portable? (A) Tablet (B) Laptop (C) Microcomputer (D) Supercomputer Which of the following characteristics: only memory (ROM) are correct? It is volatile. 16. ALU Registers ‘What is a sentinel value in an algorithm? A control instruct A print statement. Any input that the users enter ‘A value which helps toterminate a loop 17. 18. end_of_data = aed end_¢ of. While mark <> a total_marks = total_marks ma |_marks = num_marks + 1 Read mark Endwhile avg_mark = total_marks/num_marks Print num_marks, total_marks, marks Which of the following programming constructs is used in the algorithm above? (A) Selection (B) Recursion (©) Bounded iteration (D) _ Unbounded iteration What is the output when the algorithm is executed with the following input values? 45, 56, 79, 84, -1, 76, 31 (A) 4,264, 66 (B) 4,266, 64 (©) 5,370, 93 (D) 5,371, 92 h the following algorithms ‘the sum of all the even divisors of any Positive integer, n? = a sum =0 fori=1ton Line 2: Read B if (i mod 2 = = 0) Line 3: Sum =(B+A)/2 sum = sum +i Line 4: Print ‘Sum is, sum” end if = end for Which line contains an error? print sum (A) Line 1 NB: The mod operator finds the (B) Line 2 remainder when the first number (© Line3 is divided by the second. (D) Line 4 I, sum=0 i=2 end while print sum i. sul while i>0 sum = sum +i i=i-2 end while print sum Tonly Tand II only Mand III only I, Mand IL ve REN sft losing in Diagram 1 into the 1. Move a to Block 1 PRI ArPYVN Move b to Block 1 Move c to Block 1 Move a to Block 2 Move b to Block 2 Move ¢ to Block 2 Move a to Block 3 . Move b to Block 3 . Move ¢ to Block 3 10. Move a to Block 4 11. Move b to Block 4 12. Move c to Block 4 Diagram 1 Block 1 | Block? | Block 3 | Block 4 a c b Diagram 2 Block i | Block 2 | Block 3 | Block 4 £ a b © The following restrictions apply: + Only one variable can fill one block at a time + A variable can move from a filled block to an empty block. A variable can move to an empty nonadjacent block. 2. 24, ‘ems 22-23 are based on the following algorithms. Algorithm 1 AMD FORi=1 to 500 WHILE X> 75 X=X+1 ENDFOR [UNTIL END WHILE Which of the following constructs can be 23. identified in all three algorithms? (A) Selection Tl. Sequence @) Il. Kteration © (A) Land Il only (B) Land Ill only (D) (©) Wand Itt only (D) 1, Mand It Which of the following statements is true? The value of X at the end of Algorithm Ill is 2. The value of X at the end of Algorithm Il is 77. The value of X at the end of Algorithm III is 77. The value of X at the end of Algorithm Lis 501 In the implementation and review stage of the problem-solving process, implementation involves the (A) writing of algorithms (B) installation of software num n=0 WHILE n<5do Item 25 refers to the following algorithm. num = num +n, (© analysis of the problem n=n+2 _(D) evaluation of alternative solutions PRINT num ENDWHILE What is the output produced by the algorithm? (a) (B) © ©) Which of the following algorithms shows the BEST way to print the LARGER of two unique numbers? (A) WHILE (a> b) DO PRINT a (B) WHILE (a>b) DO PRINT b (C) IF (a>b) THEN PRINT b ELSE, PRINT a END IF (D) IF (a 90) ive = price ~ (price*0.15) Else if (price < 89 AND price > 60) ice = price ~ (price*0.13) (price < 59 AND price > 30) rice — (price*0.10) Else if (price <29 AND price > 10) price = price — (price*0.05) Mf (price > 10) * price = price — (price*0.05) “Else if (pfice > 30) price = price ~ (price*0.10) Else if (price > 60) price = price ~(price*0.13) Else price = price ~ (price*0.15) End if eB End if End if If (price > 10) price = price — (price*0.05) end if If (price > 30) price = price — (price*0.10) end if If (price > 60) price = price ~(price*0.13) end if 290) Pe. 29, Tefers to the followin; algorithm: 1g Which counts and displays the number of votes obtained by ten candidates in an election. Each vote is inputted as a number between one and ten, corresponding to one of the candidates. Data is terminated by zero, for i=0 to 9 begin {xX} end for read vote while (vote ! = 0) begin t{Y} read vote end while for i=1 to 10 print(“Votes obtained by candidate” +it “is”) {Z} end for “Which of the following BEST represents X, Y and Z in the algorithm above? arr [vote~ 1] = arr{vote~ 1] +1 int (arr [i— 1]) (©) X:arrfij=0 Y: arr [vote~ 1] = arr [vote~ 1] +1 Z: print (arr{i~ 1}) X: arr [i] =0 _ Y: arr [vote] = arr [vote —1] +1 xed while (x <5) do i‘ t the value of x xtd I. x=3 while (x <4) do { x=x+] print the value of x } m. x4 repeat { print the value of x xextl until (@¢ > 5) Which of the algorithms will print the SAME output? (A) Land Il only (B) [and If only (©) Mand If only (D) 1, Mand 11 Item 31 refers to the following code. To execute a computer program written bigh-level language t mes be tenleed ine re (A) machine language (B) assembly language (C) source code (D) pseudocode 33. Typically, a variable that is declared in a A) a function is accessible (®) a © a (A) __ within the whole file (DP) a=10and b= 10 (B) _ within the function only (©) __ from the calling function (D) within the function and main () 38 _ Whats the correct order ofthe stages ofthe only compilation process listed below? 7 1 Syntax analysis 34. Which of the following process attaches Il. Intermediate code generation other prewritten routines before program III. Semantic analysis ‘execution? IV. Code optimization V. Lexical analysis (A) Linker VI. Code generation (B) Computer (©) “_ Translation A IloIV>lloil>V> VI (D) * Executable (B) t+ Voli IV> VE (©) Voli > > IV VE (0) Voli >l>IV> VE 35. Which of the following is NOT a valid identifier for a variable? _ (A) __hello @) (©) marker_2 ©) me Item 39 refers to the foll code operator. lowing array and Segment where ‘96’ is the modulus while (n>0) { x=ae ey n=n-1; /Line 1 } rG=O;i<7i=1+1){ Line 2 peti! arr [i}, i/Line 3 (A) a If (num% 2! = 0) MLine 4 (B) 8 printf (“%d", num); //Line 5 (©) 16 , //Line 6 (D) 256 BS, Whatoutputisprinted by the code segment? 42. An integer variable, x, has a certain value. ae ses Which of the following statements can be () 45 34 1 used to store the value of x? (B) 34 56 92 ae KG) 423,27 56 92 (A) fp = fprintf (-%d”, x); MD), 23. 45.27 1 (B)__ fprintf (fp, “%d”, x); (©) fprintf (“data.txt”, “%d”, x); (D) _ fprintf (“%d”, x); Item 40 refers to the following code segment. « re 43. The name given to the variable x when peli double num] = 5.6; DEFINING the function displayData Line 2: double num2 = 3.0; (int x) is Line 3: double product = 1.0; Line 4: while (product < 50) { (A) _ sent parameter _ Line 5: printf (“The new product is (B) actual parameter ™ %d\n”, product); (©) __ passed parameter i Line 6: product = product * num2; (D) formal parameter b Line 7: } Which line of the code segment above will Harridan needs to write a program to read from a file called data.txt. Which of the lowing statements would allow h to open the file for reading? ofthe following code segments reads five integers into (A) intmain( ) { int arr [5]; printf (“Please enter a #”); seanf (“%d”, &arr [5]); return 0; 3 (B) —intmain( ) ¢ int num, arr (5); for (num = 4; num >= 0; num——) { printf (“Please enter a #”); scanf (“%d”, &arr [num]); B return 0; 3 (C) — intmain( ) int num = 5, arr [5]; while (num <= 5) { printf (“Please enter a #”); : seanf (“%d", &arr [num]); 4 num+; ; 4 ; return 0; * 5 ) a (D) — intmain( ) { int num; int arr; for (num = 0; num <=5; num++) { - printf (“Please enter a #”); seanf (“%d”, &arr [num]);

You might also like