You are on page 1of 8
CONFIDENTIAL CSIMAY 2021/CSC126 UNIVERSITI TEKNOLOGI MARA TEST COURSE : FUNDAMENTALS OF ALGORITHMS AND COMPUTER PROBLEM SOLVING COURSE CODE : CSC126 SEMESTER : MAR 2021 - AUG 2021 TIME : 2HOURS INSTRUCTIONS TO CANDIDATES 1 This question paper consists of three (3) parts: PART A (10 Questions) PART B (4 Questions) PART C (1 Question) 2. Answer ALL questions. 3, This is a take-home test. Therefore, to discuss/share/disseminate the questions and answers amongst your classmates/course mates are strictly prohibited. If you are found to be guilty or have committed one of the actions, your marks will be deducted, and you will be penalized. CONFIDENTIAL 2 CSIDEC 2020/¢8C126 PART A (20 MARKS) 1. The THIRD step in Program Development Life Cycle (PDLC) isto___. analyze the problem design algorithm using flowchart or pseudocode code the algorithm using a programming language plan the algorithm com> 2. The purpose of adding comments in the code is to A. increase the execution time of a code B. provide a secure environment of a code C. make the source code easier for a programmer to understand D. tun the code easily 3. The following C++ code will display #include using namespace std; int main() ( cout<<"Let's Le! cout<<"¥ou can return 0; rn CHt.Mecendl; a good program. ‘endl; Logic error. Let's learn C++. You can write a good program. Run time error. Let's learn C++. You can write a good program. gompr 4. Identify VALID identifiers in C++. _Patient_#ID Me 39cents I. _namezmployee Nw studentNuml (© Hak Cipta Universit Teknolog! MARA. CONFIDENTIAL CONFIDENTIAL 3 CSIDEC 2020/¢8C126 A. Land Ill only. B. Il and Ill only, C. Illand IV only. D.1 I, Illand Iv. 5. The following statements have a syntax error EXCEPT int ys ytts sum = (2 + 37 int total = R300; const int - 4.142 vom,y 6. An expression using the greater-than, less-than, greater-than-or-equal-to, less-than-or- ‘equal-to, equal-to, or not-equal-to operator is called a(n) Boolean expression ‘statement relational expression logical operator poor 7. Inan is-e1se statement, the 2+ part executes its statementiblock if the expression is , and the else part executes its statement/block if the expression is A. FALSE, TRUE B. TRUE, FALSE C. FALSE, FALSE D. TRUE, TRUE 8. Which of the following statement is FALSE about logical expression? The value of logical expression will always be either 0 or 1 && operator returns true if one of the statements in the logical expression is true. L(x > 3 a@ = < 10)i8 evaluated as FALSE, if x = 5. The >= operator is evaluated before the || operator. pomp 9. Which of the following statement is TRUE about selection control structure? A. Selection is @ presentation of a set of instructions to be performed repeatedly, as long as the condition is true. B. Inan OR selection, two or more condition(s) must be met in order for an eventto take place. C. Anested decision or a nested i is a decision inside another decision. D. In C++, there are two selection control structures: is statements and for ‘statements. (© Hak Cipta Universit Teknolog! MARA. CONFIDENTIAL CONFIDENTIAL 4 CSIDEC 2020/¢8C126 10. Whatis the value assigned to variable g=ade if the value of variable mar is 65? if (mark > 40) grade = ‘Cc’; else if (mark > 50) grade = ‘5’; else if (mark > 65) grade = ‘A’; else grade = ‘D!; pomp o>o0 (© Hak Cipta Universit Teknolog! MARA. CONFIDENTIAL CONFIDENTIAL 5 CSIDEC 2020/¢8C126 PART B (20 MARKS) QUESTION 1 Convert the given flowchart into a complete program in C++. ‘Set: MILES_TO_KM = 1.609 Calculate: kilometers = miles * MILES_TO_KM (5 marks) (© Hak Cipta Universit Teknolog! MARA. CONFIDENTIAL CONFIDENTIAL 6 CSIDEC 2020/¢8C126 QUESTION 2 a) Assume that int p = 1nd doubie ¢ = 2.8 and that each expression is independent. What are the results of the following expressions? i p= ig ii p= b) Convert each of the following mathematical formulas into expressions in C++ i B= "fy xmxv? (5 marks) QUESTION 3 Formula given below is used to calculate the distance travelled by a car: s=ut+ ¥/p at® where, s = distance traveled (m) U = initial velocity (m/s) t= time taken(s) a = acceleration (m/s?) Write a complete program in C++ that receives the values of u, t, anda. Then, the program calculates the distance traveled by the car in the time taken. (Note: use the appropriate predefined function in your program.) (5 marks) (© Hak Cipta Universit Teknolog! MARA. CONFIDENTIAL CONFIDENTIAL 7 CSIDEC 2020/¢8C126 QUESTION 4 Given the following program segment: int numbers cin >> number: if (number % 2 if (number & 3 cout << "xxxex"

You might also like