You are on page 1of 13
Integrated Exercise (Unit D) le Choice Questi ions | In the problem-solving procedure, IPO charts, are developed in the stage of A. problem identification problem analysis B. C. algorithm design D, . debugging and testing Which of the following can be used to represent an algorithm during the algorithm design stage? (1) Pseudocode (2) Flowchart (3) IPO chart (1) and (2) only (1) and (3) only (2) and (3) only (1), (2) and (3) pomp When developing a solution, divide and conquer isa strategy of —_____. A. stepwise refinement bottom-up approach B. CC. top-down approach D. step-by-step approach Which of the following statements about test data is correct? A. Test data is speci program testing. B. Alll the test data should be valid. ly designed for ee C. All the test data should be invalid, D. Test data is usually randomly generated, 0 Suppose PASS_RATE is a variable storing the calculated passing rate of students in an English examination. Which of the following is the most appropriate data type for PASS_ RATE? ‘Type Range Precision level Tnteger 0-200 N/A Integer 0-100 N/A Decimal number 0.0 - 200.0 | decimal place pop p> Decimal number 0.0 - 100.0 1 decimal place Which of the following are general rules for designing a good user interface? (1) Appropriate colours should be used for text and background. (2) Different font types should be used for different entries. (3) Concise wording should be used. (1) and @) only (1) and @) only (2) and (3) only (1), (2) and 3) O SOP + Basie Programming Concepts 7. Which of the following pseudocode is best 8. A scientist measured the height of a small plant represented by the flowehart below? 4 times a day for a period of two months. The \ data collected is shown below: 12.5, 12.6, 12.8, 13.1 — << He declared 1,000 variables of real data type to i store the data No Which of the following criticisms of the variable declaration are correct? Vee (1) The number of entries is unnecessarily large. ATP... THEN paar (2) The data type does not mate with the THE collected data. ELSE (3) An array should be used instead of ic those 1,000 variables beiueed A. (1) and (2) only B. REPEAT B. (J) and (3) ont IF ... THEN (1) and (3) only ae C. @)and (3) only ELSE D. (1), @) and @) ENDIF 9, Given that X = 8 andY = 10. Which of the UNTIL .. following logical expressions return true? Cc. DO (Il) (x < ¥) THEN (2) (% >= 8) AND (¥ < 10) ELSE @) (X= ¥) OR (x > 0) oe ‘A. (1) and (2) only ENDIP eee B. (1) and (3) only eee C. @)and (3) only REPEAT D. (1), (2) and (3) LJ UNTIL... 10. Evaluate the following expression ELSE | 6 * 2 - 10 Mod 3 ENDIF boa B. 10 C9 i D. -18 C 11. According to the following truth table, what may the logical expression E be? x x E vRUE | TRUE | FALSE TRUE | FALSE | FALSE FALSE | TRUE | FALSE FALSE | FALSE | TRUE X OR NOT ¥ A B, NOT(X OR Y) C. X AND NOT ¥ D. NOT (X AND ¥) 12. How many times will line 50 be executed’? 10 Ae 8B 20 WHILE A > 0 30 BEGIN 40 IF (A Mod 2) = 0 THEN 50 Output A 60 ENDIF 70 AcA-3 80 END Al B, 2 © 3 D4 Study the following pseudocode and answer questions 13 to 15. 10 Input X 20 Yeo 30 WHILE X > 0 40 BEGIN 50 Yes X* x 60 KexX-21 70 =ND 80 Output ¥ ————-__ Integrated Exercise (Unit D) 13. Assume ¥'isa positive integer. Which of the following mathematical expressions can be used to represent the output of the pseudocode? A (X—1P + (K-2) + (K-37 +. P+ B. Y=(1+24+3+..4X) c 142 +3 +..+X7 $243 4X O 14. Which of the following iteration statements can be used to replace the WHILE-loop in the pseudocode? A. REPEAT ... UNTIL X > 0 B. REPEAT ... UNTIL X <= 1 C. FORX<1T0X D. DO... WHILE X >= 1 15. Which of the following assignment statements should be used to replace line 50 in order to calculate the expression below? patate te A 50 YeY+1/Xx B50 Yey4x /(x+1) C50 Ye ¥+ (K-1)/X D. 50 Ye ¥+ (KX ~ 1)/(X + 1) __ Basic Programming Concepts Long Questio k 1, The algorithm of a game is represented by the following flowchart. : eo ‘ouput Ouput 720 bg" Output Teo sah End {a) State the objective of the game, (1 mark) (b) What type of error can be identified using a flowchart? (mark) (0). State two stages of the problem-solving procedure in which flowchart may be involved. (2 marks) sf -——__Integrated Exercise (Unit D) (Complete the following IPO chart for the game. (2 marks) Input = Process Output (©) Convert the above flowchart into pseudocode using a WHILE-loop. (5 marks) (0 Suggest one improvement on the algorithm to avoid run-time errors, (1 mark) | Basic Programming Concepts 2. (a) Suggest two field validations for an e-mail address which is inputted through a data input form. (mark) (b) @ Complete the following truth table. (2 marks) A B A AND B NOT A VASO By Oa NE A | Complete the following truth table to show that the logical expressions below are equivalent, + (A AND B) OR NOTA + BOR NOTA (2 marks) A B NOT A BOR NOT A (©) Briefly explain why the following logical expressions x and ¥ are identical X: NOT A AND BOR C y: ((NOT A) AND B) OR C (2 marks) (@)_ Given that is an array containing the following data. Ala] |A[2] |AI3] |A(4] |A[5] A[6]|A(7] |A[8] |A(9] |A[20]/A[12]/a(12)/A(13]|at14] c]xuial|u kia y | 8 5 A student has written the following pseudocode to display the name stored in array A in a special format. 38. —_Inlegrated Exercise (Unit D) 10 20 30 40 50 60 70 80 90 100 110 120 130 Ie0 REPEAT Telei SURNAME [T] = A(T] UNTIL A[I] = ' ' Ner-1 REPEAT Ter+i UNTIL A[T] <> ' ' Output AIT], ' ' FOR T< 170 N Output SURNAME [1] NEXT (@ State the appropriate data types for variables 1, Nand SURNAME. (1 mark) (ii) What is the output of the pseudocode? (1 mark) }). What is the purpose of lines 70 to 90? (mark) (iv) Suggest one content of array A that will cause errors for the pseudocode. Briefly explain your answer. (2 marks) a{ii]atai]atsi|a‘ailatsi]atei|a(7i|atei|atsi|atiojla(aiijata2ijataaija tial 3. The following algorithm is known as binary search. It searches an array called NUM sorted in ascending, order for a target value 7. Step 1: START Step 2: Input T Step 3: Fel Step 4: L« the last index of the array Basic Programming Concepts Step 5: Me the integral part of (F + 1) / 2 Step 6: IF NUM[M] = T, show the value of M, GOTO Step 10. Step 7: IF NUM[M] > T, L T THEN 100 Lem-i 110 ELSE 120 See 130 ENDIF 140 ENDIF 150 UNTIL (NUM[M] = T) OR (@) (@) (b) ————_ Integrated Exercise (Unit 0) Modify the pseudocode in part (¢) so that a message ‘Target value not found.’ will be returned if the target value does not exist in the array. (1 mark) For each of the following situations, select the most appropriate loop from the choices below and briefly explain your answer, FOR-loop WHILE-lo REPEAT...UNTIL-loop oP (Count the number of male students from a class of 40, (1 mark) (ii) The outcomes of tossing a dice are inputted into an array. The end of data is marked with the value -1. Count the number of data stored in the array, (mark) (iii) At the end of a game, it prompts a message “Play again? (Y/N)’, Whenever the player inputs °Y°, the game restarts, (1 mark) A student has written the following pseudocode. 10 Input x 20 Loc< 0 30 FOR A «1 TO 100 40 IF BIA] = X THEN 50 Loc + A 60 JUMP TO LINE 90 70 ENDIF 80 NEXT 90 Output Loc (i) Describe the objective of the pseudocode, (1 mark) a Basie Programming Concepts (ii) Suggest one reason why it is not recommended to include the SUMP instruction in the FOR-loop, (mark) (ili) The student then modifies line 60 as follows: 60 Ae 100 How does this affect the program? (1 mark) (iv) Is the change in part (b) (iii) a better alternative to the original pseudocode? Briefly explain your answer. (mark) (v) Remove the JUMP instruction by rewriting the pseudocode using a WHILE-loop. (5 marks) ——_Integrated Exercise (Unit 5. A programmer has written the following pseudocode. 10 Input A 20 FORT+1T70A 30 Sets! 40 FOR J<« 1 TOT 50 SeS+'#! 60 NEXT g 70 output 3 80 NEXT I (Remark of line 50: '#' is appended to the string 8.) (a) Given that the input value of variable A is 3. Dry run the pseudocode and complete the following trace table, (3 marks) ‘Trial on line 50 I a 8 1 2 3 4 5 6 (b) Ifthe input value of a is 5, dry run the pseudocode and write the output inside the following box. (2 marks) | Basic Programming Concepts (2 marks) (© Fill in the missing parts of the flowchart for the above pseudocode, Start Output § (5 marks) (d) Modify the pseudocode so that it produces a pattern as follows. Input yalue of A= 6 ature atte ante =" =*H Input value of A=3 otis =H i 2 e a z =

You might also like