You are on page 1of 10
CONFIDENTIAL, CSIFEB 2021/6SC126 UNIVERSITI TEKNOLOGI MARA FINAL EXAMINATION COURSE : FUNDAMENTALS OF ALGORITHMS & COMPUTER PROBLEM SOLVING COURSE CODE 2 CSC126 EXAMINATION : FEBRUARY 2021 TIME : 3HOURS INSTRUCTIONS TO CANDIDATES 1 This question paper consists of three (3) parts: PART A (10 Questions) PART B (3 Questions) PART C (1 Question) 2. Answer ALL questions in the Answer Booklet. Start each answer on a new page. 3 ‘Answer ALL questions in English DO NOT TURN THIS PAGE UNTIL YOU ARE TOLD TO DO SO This examination paper consists of 10 printed pages (© Hak Cipta Universiti Teknologi MARA CONFIDENTIAL CONFIDENTIAL, 2 PARTA 1. Identify the relational operator that is INVALID. go> 2. Determine the output for the following program segment: CSIFEB 2021/6SC126 int pl = 20, p2 = 30; if(pl != p2) coute<" if(pl < p2) cout<<” 1"< 100) price = 50; else if (people » 50) price = 70; else price = 80; go> 4, Given that x-10, y-2, 2-3 and m4, predict the output for the given code segment: if (10) x += yr if (y<20) ‘ cout 6. Which of the following is the CORRECT syntax of for loop? ion, condition, updating) initialization; condition) B C. for(initializetion: condition: updating) D. for (updating, initialization, condition) 7. Consider the following function prototype’ float findAvg (int numl, int num2); Which of the following statement describes the function prototype? ‘A. Afunction named £ indavg that takes a parameter of type num and retumsa float value. B. A function named £indavy that takes two parameters of type integer and retums a float value. C. A function named float £indavg that takes two parameters of type integer and retusa float. value. D. A function named 102+ which finds the average of two integers. 8. Define subscript/index in an array A. It indicates the beginning address of a series of elements. Itis a collection of elements that have similar data types and names, B C. tis a number that indicates the position of the array element. D. Itis used to store multiple values in a single identifier. (@ Hak Cipta Universiti Teknologi MARA CONFIDENTIAL CONFIDENTIAL, 5 CSIFEB 2021/6SC126 9. Identify the index for value 2 in the following array initialization statement. int listArray[] ~ {7,6,5,2,4)7 pom> BONO 10. Given the following array declaration and its initialization’ A int studentMark[] = (80,90, 54,60,75): Which of the following statements show how to identify the maximum value of the array? int max = studentMark(0]7 for(int i=0; i<=4; i++) 1 if(studentMark[i] > max) max Mark [i]; ) int max = -999; for(int isl; iced; i++) ‘ if (studentMark[i] > max) max = studentMark [i]? ) int max = studentMark(0]; for(int i=l; i<=5; i++) { if(studentMark[i] > max) max ~ studentMark [i]? } (@ Hak Cipta Universiti Teknologi MARA CONFIDENTIAL CONFIDENTIAL, 6 CSIFEB 2021/6SC126 int max = -999; for(int i-0; icdy i++) { Af(studentwark[i] > max) max = studentMark [i]; (@ Hak Cipta Universiti Teknologi MARA CONFIDENTIAL CONFIDENTIAL, 7 CSIFEB 2021/6SC126 PARTB QUESTION 1 a) Convert the following pseudocode into a C++ program using multi-way selection control structure. BEGIN Prompt the user to input a mark Read mark IF mark >= 90 AND mark <= 100 DISPLAY “Excellent” ELSE IF mark >= 75 AND mark <= 89 DISPLAY “Good” ELSE IF mark >= 60 AND mark <=74 DISPLAY “Average” ELSE IF mark >=50 AND mark <= 60° DISPLAY "Fair" ELSE DISPLAY “Fail” ENDIF END (5 marks) b) Aman Park Sdn. Bhd. provides parking services and charge as follows: TIME: RATE PER HOUR (RM) For the first 2 hours 3 For the next subsequence 1 hour 2 After 8 hours 1 10% discount will be given to the customer who parks more than 5 hours. Write a C++ program segment that calculate and display the actual charge for a customer based on number of hours parked. (5 marks) (@ Hak Cipta Universiti Teknologi MARA CONFIDENTIAL CONFIDENTIAL, 8 CSIFEB 2021/6SC126 QUESTION 2 a) The Amy Recruitment Rally 2021 was held in January 2021 and 300 male candidates: have participated in this rally. During this rally, all of the candidates have been asked to measure their height (m). Based on the information gained from the candidates, write a complete C++ program that will count and display the number of candidates in each height category as given in Table 1 Table 1: Height Category Height Category Short Medium Tall Height Range | Less than 165__| 165 — 164 185 ormore (5 marks) b) Trace the output of the following program segments: for(int isl; ica3; i++) { for (int J=1; j<=47 3+) coute< (43) <<"\e"s coutecendls 1 (5 marks) c) Study the following program segment, then answer questions that follows: int main() { int num, sum = 0; cout<<"Please enter a number:"; cinssnum: while (num != -1) sum = sum + num coutc<"Please enter a numb: t<<"The total sum is "< Local 1 400 Scilla Intemational 2 700 5 f 3 Local i 200 enier inventor Intemational 2 500 b) Write @ function named eariybiraReg ..). In this function, if the participant registers early, he/she entitles for RM100 discount. Otherwise, no discount is given. The function will return the amount of discount to the main) funetion. ©) Write a function named cispiay cotai(..) which displays the total number of Participant and the total fee for all participants. d) Write a main() function which reads the participant code, institution code and early bird code. It will then display the total fee, amount of discount received and total fee after discount for that participant. User may choose to calculate for the next participant. If there is no longer participant to be calculated, the program will display the total number of participant and the total fee for all participants. (15 marks) END OF QUESTION PAPER (@ Hak Cipta Universiti Teknologi MARA CONFIDENTIAL

You might also like