The words you are searching are inside this book. To get more targeted content, please make full-text search by clicking here.

Koleksi Pra PSPM Kolej Kolej Lain ..

Discover the best professional documents and content resources in AnyFlip Document Base.
Search
Published by bm-3054, 2023-04-16 19:57:36

Pra PSPM SC025

Koleksi Pra PSPM Kolej Kolej Lain ..

SULIT SULIT [email protected] SC025 SET A SC025 Computer Science 2 Sains Komputer 2 Semester II Semester II Session 2021/2022 Sesi 2021/2022 2 hours 2 jam No. Matrik Matric No. No. Kad Pengenalan Identity Card No. No. Tempat Duduk Seat No. (Isikan maklumat dengan lengkap) KOLEJ MATRIKULASI KEDAH KEDAH MATRICULATION COLLEGE PRA PEPERIKSAAN SEMESTER PROGRAM MATRIKULASI MATRICULATION PROGRAMME PRE EXAMINATION JANGAN BUKA KERTAS SOALAN INI SEHINGGA DIBERITAHU. DO NOT OPEN THIS QUESTION PAPER UNTIL YOU ARE TOLD TO DO SO. Untuk Kegunaan Pemeriksa For Examiner’s Use No. Soalan Question No. Markah Mark Pemeriksa Examiner KP / KKP 1 11 2 15 3 29 4 15 JUMLAH TOTAL 70 Kertas soalan ini mengandungi 10 halaman bercetak. This question paper consists of 10 printed pages. © Kolej Matrikulasi Kedah S C 0 2 5


SULIT SC025 2 SULIT No. Matrik…………………………………… No. Kad Pengenalan……………………………… [email protected] 1 Problem solving is the act of defining a problem; determining the cause of the problem; identifying, prioritizing, and selecting alternatives for a solution; and implementing a solution. (a) Identify steps for the following explanation. [5 marks] Explanation Steps (i) Showing step by steps to solve the problem. Design a solution (ii) Make sure the user satisfy with the output. Testing (iii) Writing a program. Implementation (iv) As a guideline to the other programmer. Documentation (v) Make the problem statement clearer. Problem analysis (b) Justify the importance of the second step in solving a problem. [2 marks] to show the flow and sequence of steps to solve problem. (c) Name two (2) examples of languages that can be used in step 3. [2 marks] Java C++ (d) Give two (2) ways to perform the last step of problem-solving. [2 marks] Using comments Creating separate text file


SULIT SC025 3 SULIT No. Matrik…………………………………… No. Kad Pengenalan……………………………… [email protected] 2 An algorithm is a series of instructions telling a computer how to transform a set of facts about the world into useful information. (a) Based on the given scenario below, design the algorithm using pseudocode. According to the library rules, a student will not be fined if he/she returns the book(s) borrowed within 14 days. Otherwise, the student will be fined 50 cents a book for each day of late return. Calculate and display the amount of fine that a student has to pay, or display a message “Thank you for early return”. [7 marks] Start Read days, qtyBooks If days > 14 Fine = 0.5 x (days – 14) x qtyBooks Else Print " Thank you for early return" Endif Stop


SULIT SC025 4 SULIT No. Matrik…………………………………… No. Kad Pengenalan……………………………… [email protected] (b) Ahmad decided to sell a shirt that he just bought to his friend. Determine whether he gains profit or suffers a loss or breaks even (i.e not gaining profit nor loss) from the transaction. Based on the given scenario, design the algorithm using a flowchart. [8 marks] Start Read sellPrice, boughtPrice If sellPrice > boughtPrice Status = "Gain profit" Else if sellPrice < boughtPrice Status = "Suffers a loss" Else Status = "Breaks even" Endif Print status Stop


SULIT SC025 5 SULIT No. Matrik…………………………………… No. Kad Pengenalan……………………………… [email protected] 3 Java is a high-level, class-based, object-oriented programming language that is designed to have as few implementation dependencies as possible. (a) Declare a variable based on the description of the primitive data type. (i) Use this data type for simple flags that track true/false conditions. [1 mark] boolean variableName1; (ii) For decimal values, this data type is generally the default choice. [1 mark] double variableName2; (iii) It has a minimum value of -2 31 and a maximum value of 231 -1. [1 mark] int variableName3; (iv) It is a single 16-bit Unicode character. [1 mark] char variableName4; (b) Identify output from the following Java statements. (i) class Value { public static void main (String[] args) { int[] num = {1,3,5,7}; num[0] = 9; num[3] = num[1]; num[0] = num[0] + num[3]; System.out.print (num[0]); } } [1 mark] 12 (ii) y=15; if(y<20) if(y<10) x=5*y; else x=2*y; else x=3*y; System.out.print(x); [1 mark] 30


SULIT SC025 6 SULIT No. Matrik…………………………………… No. Kad Pengenalan……………………………… [email protected] (c) Evaluate the following. (i) 10/3+8%5/2 [1 mark] 4 (ii) 2.5 * (2%3) + 10/6 [1 mark] 6.0 (iii) 7 – 3 + 2 * 7 / 3 * 2 [1 mark] 12 (d) Convert the following expressions into the Java statements. (i) x = 4(a+b) / 2c(2a-1) [1 mark] x=4*(a+b)/2*c*(2*a-1); (ii) = − 35+ √4 5 2√ [1 mark] r = (-Math.pow(b,35)+Math.pow(4*a*c,1/5))/(2*Math.sqrt(a)); (e) Construct expression in correct syntax for the following. (i) Declare grade and mark. Assign a grade to 'A' if the mark is greater than 80. [1 mark] char grade; int mark; if(mark>80) grade='A'; (ii) Define a class named MyClass as public. [1 mark] public class MyClass { } (iii) Declare variable named marks and assign 97.5 to it. [1 mark] double marks = 97.5; (iv) Create an object from the class MyObject. [1 mark] MyObject objectName = new MyObject();


SULIT SC025 7 SULIT No. Matrik…………………………………… No. Kad Pengenalan……………………………… [email protected] (v) Declare a named constant RATE to store 0.125. [1 mark] final double RATE = 0.125; (f) Assuming the input is 3 7 9 5 8 6 0 2 -1, show output from the following program segment. double sum=0, avg=0; int bil=0; int num = sc.nextInt(); while(num >= 0) { sum = sum + num; bil++; num = sc.nextInt(); } avg=sum/bil; System.out.print("The average is "+avg); [2 marks] The average is 5.0


SULIT SC025 8 SULIT No. Matrik…………………………………… No. Kad Pengenalan……………………………… [email protected] (g) Construct a program segment for the following problems. (i) Accept two integers from the user and determine whether both numbers have opposite signs; that is, one of the numbers is positive and the other is negative. Produce an appropriate message. [4 marks] int num1 = sc.nextInt(); int num2 = sc.nextInt(); String status = "Same sign" if(num1*num2 < 0) String status = "Opposite sign" System.out.println(status); (ii) Produce the following output by using a while loop. 21 18 15 12 9 6 3 STOP [5 marks] int i = 21; while(i > 0) { System.out.print(i + "\t"); i = i - 3; } System.out.println("STOP");


SULIT SC025 9 SULIT No. Matrik…………………………………… No. Kad Pengenalan……………………………… [email protected] (h) Write the output from the program segment below. int p=5; while(p>2){ if(p%3==0) System.out.println(p+" is divisible by 3."); else if(p%5==0) System.out.println(p+" is divisible by 5."); else if(p%7==0) System.out.println(p+" is divisible by 7."); else System.out.println(p+" is not divisible."); p--; } [2 marks] 5 is divisible by 5. 4 is not divisible. 3 is divisible by 3.


SULIT SC025 10 SULIT No. Matrik…………………………………… No. Kad Pengenalan……………………………… [email protected] 4 Create a Java program to read n students names and their mark respectively into two arrays name and mark. Find the highest mark with name and the average mark of all students. [15 marks] import java.util.Scanner; public class NameMarks { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); String[] names = new String[n]; double[] marks = new double[n]; for(int i=0; i<n; i++) { names[i] = sc.next(); marks[i] = sc.nextDouble(); } double sum=0, avg=0; for(int i=0; i<n; i++) { sum = sum + marks[i]; } avg = sum / n; String nameHigh = names[0]; double high = marks[0]; for(int i=0; i<n; i++) { if(marks[i] > high) { nameHigh = names[i]; high = marks[i]; } } System.out.println("Name with the highest mark: "+nameHigh); System.out.println("Highest mark: "+high); System.out.println("Average mark: "+avg); } }


SULIT SC025 11 SULIT No. Matrik…………………………………… No. Kad Pengenalan……………………………… [email protected] END OF QUESTIONS KERTAS SOALAN TAMAT


SULIT SULIT [email protected] SC025 SET A SC025 Computer Science 2 Sains Komputer 2 Semester II Semester II Session 2021/2022 Sesi 2021/2022 2 hours 2 jam No. Matrik Matric No. No. Kad Pengenalan Identity Card No. No. Tempat Duduk Seat No. (Isikan maklumat dengan lengkap) KOLEJ MATRIKULASI KEDAH KEDAH MATRICULATION COLLEGE PRA PEPERIKSAAN SEMESTER PROGRAM MATRIKULASI MATRICULATION PROGRAMME PRE EXAMINATION JANGAN BUKA KERTAS SOALAN INI SEHINGGA DIBERITAHU. DO NOT OPEN THIS QUESTION PAPER UNTIL YOU ARE TOLD TO DO SO. Untuk Kegunaan Pemeriksa For Examiner’s Use No. Soalan Question No. Markah Mark Pemeriksa Examiner KP / KKP 1 11 2 15 3 29 4 15 JUMLAH TOTAL 70 Kertas soalan ini mengandungi 10 halaman bercetak. This question paper consists of 10 printed pages. © Kolej Matrikulasi Kedah S C 0 2 5


SULIT SC025 2 SULIT No. Matrik…………………………………… No. Kad Pengenalan……………………………… [email protected] 1 Problem solving is the act of defining a problem; determining the cause of the problem; identifying, prioritizing, and selecting alternatives for a solution; and implementing a solution. (a) Identify steps for the following explanation. [5 marks] Explanation Steps (i) Showing step by steps to solve the problem. (ii) Make sure the user satisfy with the output. (iii) Writing a program. (iv) As a guideline to the other programmer. (v) Make the problem statement clearer. (b) Justify the importance of the second step in solving a problem. [2 marks] (c) Name two (2) examples of languages that can be used in step 3. [2 marks] (d) Give two (2) ways to perform the last step of problem-solving. [2 marks]


SULIT SC025 3 SULIT No. Matrik…………………………………… No. Kad Pengenalan……………………………… [email protected] 2 An algorithm is a series of instructions telling a computer how to transform a set of facts about the world into useful information. (a) Based on the given scenario below, design the algorithm using pseudocode. According to the library rules, a student will not be fined if he/she returns the book(s) borrowed within 14 days. Otherwise, the student will be fined 50 cents a book for each day of late return. Calculate and display the amount of fine that a student has to pay, or display a message “Thank you for early return”. [7 marks]


SULIT SC025 4 SULIT No. Matrik…………………………………… No. Kad Pengenalan……………………………… [email protected] (b) Ahmad decided to sell a shirt that he just bought to his friend. Determine whether he gains profit or suffers a loss or breaks even (i.e not gaining profit nor loss) from the transaction. Based on the given scenario, design the algorithm using a flowchart. [8 marks]


SULIT SC025 5 SULIT No. Matrik…………………………………… No. Kad Pengenalan……………………………… [email protected] 3 Java is a high-level, class-based, object-oriented programming language that is designed to have as few implementation dependencies as possible. (a) Declare a variable based on the description of the primitive data type. (i) Use this data type for simple flags that track true/false conditions. [1 mark] (ii) For decimal values, this data type is generally the default choice. [1 mark] (iii) It has a minimum value of -231 and a maximum value of 231-1. [1 mark] (iv) It is a single 16-bit Unicode character. [1 mark] (b) Identify output from the following Java statements. (i) class Value { public static void main (String[] args) { int[] num = {1,3,5,7}; num[0] = 9; num[3] = num[1]; num[0] = num[0] + num[3]; System.out.print (num[0]); } } [1 mark] (ii) y=15; if(y<20) if(y<10) x=5*y; else x=2*y; else x=3*y; System.out.print(x); [1 mark]


SULIT SC025 6 SULIT No. Matrik…………………………………… No. Kad Pengenalan……………………………… [email protected] (c) Evaluate the following. (i) 10/3+8%5/2 [1 mark] (ii) 2.5 * (2%3) + 10/6 [1 mark] (iii) 7 – 3 + 2 * 7 / 3 * 2 [1 mark] (d) Convert the following expressions into the Java statements. (i) x = 4(a+b) / 2c(2a-1) [1 mark] (ii) = −35+ √4 5 2√ [1 mark] (e) Construct expression in correct syntax for the following. (i) Declare grade and mark. Assign a grade to 'A' if the mark is greater than 80. [1 mark] (ii) Define a class named MyClass as public. [1 mark] (iii) Declare variable named marks and assign 97.5 to it. [1 mark] (iv) Create an object from the class MyObject. [1 mark]


SULIT SC025 7 SULIT No. Matrik…………………………………… No. Kad Pengenalan……………………………… [email protected] (v) Declare a named constant RATE to store 0.125. [1 mark] (f) Assuming the input is 3 7 9 5 8 6 0 2 -1, show output from the following program segment. double sum=0, avg=0; int bil=0; int num = sc.nextInt(); while(num >= 0) { sum = sum + num; bil++; num = sc.nextInt(); } avg=sum/bil; System.out.print("The average is "+avg); [2 marks]


SULIT SC025 8 SULIT No. Matrik…………………………………… No. Kad Pengenalan……………………………… [email protected] (g) Construct a program segment for the following problems. (i) Accept two integers from the user and determine whether both numbers have opposite signs; that is, one of the numbers is positive and the other is negative. Produce an appropriate message. [4 marks] (ii) Produce the following output by using a while loop. 21 18 15 12 9 6 3 STOP [5 marks]


SULIT SC025 9 SULIT No. Matrik…………………………………… No. Kad Pengenalan……………………………… [email protected] (h) Write the output from the program segment below. int p=5; while(p>2){ if(p%3==0) System.out.println(p+" is divisible by 3."); else if(p%5==0) System.out.println(p+" is divisible by 5."); else if(p%7==0) System.out.println(p+" is divisible by 7."); else System.out.println(p+" is not divisible."); p--; } [2 marks]


SULIT SC025 10 SULIT No. Matrik…………………………………… No. Kad Pengenalan……………………………… [email protected] 4 Create a Java program to read n students names and their mark respectively into two arrays name and mark. Find the highest mark with name and the average mark of all students. [15 marks] END OF QUESTIONS KERTAS SOALAN TAMAT


1 Instructions : Answer all the questions. 1) a) State an appropriate step and activities of problem solving in computer programming. Activity Step in problem solving (i) To make sure the program is free from syntax error, logical error and run-time error. Testing (ii) An analysis of a problem statement to identify input, process and output. Analyze the problem (iii) Transform the algorithm into a set of instructions that are understood by the computer. Implementation [3 marks] b) The use appropriate control structures are very important when implement the program code. Identify the most suitable control structures to solve the following problems. Problem Control structure (i) Calculate a book price based on category. Selection (ii) Calculate Raya bonus for each of JJ Naza’s kitchen employees. Repetition [2 marks] c) Identify the input, process and output from the following problems. (i) A shape program read radius and apply formulae to computer and display the area and circumference of the circle. INPUT Radius [1m] PROCESS Calculate the area and circumference based on radius [1m] OUTPUT Area, circumference [1m] [3 marks] d) (ii) int a = sc.nextInt( ); int b=a*4; if (b >=8) System.out.println (“\tWelcome to beautiful Labuan island”); else System.out.print (“\t\tHave a nice day”); INPUT A [1 m] PROCESS To determine suitable message [1 m] OUTPUT Message “Welcome to beautiful Labuan island” or “Have a nice day” [½ m , ½ m] [3 marks] 2) a) The following formula is calculate distance between two coordinates, (x1,y1) and (x2,y2). = √(2 − 1) 2 + (2 − 1) 2 Write a pseudocode to find the distance using two coordinates. Start Read x1,x2,y1,y2 [1 m] = √(2 − 1) 2 + (2 − 1) 2 [1 m] Print distance [1 m] [3 marks] radius


2 Stop b) Write pseudocode to determine whether number is even or odd for 14 different positive numbers. Start i=1 [½ m] while (i<=14) [1 m] Read number [½ m] If (number % 2 == 0) [1 m] Print “Even number” [½ m] Else [½ m] Print “Odd number” [½ m] endIF i=i+1 [½ m] endWHILE Stop [5 marks] c) Draw flowchart based on Java segment given. for (n=20; n>=1; n=n-1) if (n%4 == 0) System.out.println (n); [7 marks] 3) a) Trace the output for the Java code below : int num; num = get.nextInt ( ); if (num <= 5) System.out.print (“Hi, today is PRE-PSPM.”); if (num < 10) System.out.println (“Good luck for me.”); else System.out.print (“but today I’m back to hometown”); System.out.print (“\nKML tatap dihati.”); What is the output if num variable as 5 Hi, today is PRE-PSPM.Good luck for me. KML tatap dihati. [2 marks] [1 m] [1 m] [1 m] [1 m] [1 m] [½ m] [½ m] 2 x Partner true/false [½ m, ½ m]


3 b) What is the output of the following code fragment, assuming num is 10? num=num*2; if(num==20) System.out.print (“Wilayah Persekutuan\t”); System.out.print (“Labuan\t”); Wilayah Persekutuan Labuan [½ m] [½ m] [1 mark] c) After execution of the following code, what will be the value of m and n? int n=678; int m=0; while(n!=0) { m=(10*m)+(n%10); n=n/10; } [2 marks] m = 876 [1 m] n = 0 [1 m] b) Given n=9, m=16, a=2, c=7. Evaluate the following statement. (i) m /n + n % m [1 mark] = (16/9) + (9 % 16) = 1 + 9 = 10 [1 m] (ii) m + (n * n – a * m) / 2 * a = 16 + (9 * 9 – 2 * 16) / 2 * 2 = 16 + (81 – 18) /2 * 2 = 16 + 49 / 2 * 2 = 16 + 24 * 2 = 16 + 48 = 64 [1 m] [1 mark] c) Write Java assignment statement for the following algebraic expression. (i) = √(2 − 1) 2 + (2 − 1) 2 = Math.sqrt ( ( Math.pow (x2 – x1),2) + ( Math.pow (y2 – y1),2)); [2 m] [2 marks] (ii) Print 2 System.out.print (3.142 * r * r); [1 m] [1 m] [2 marks] d) An internet service provider has three different subscription packages for its customer: Package A : RM19.95 per month for 10 hours of access are provided. Additional hours are RM2.00 an hour. Package B : RM35.95 per month for 20 hours of access are provided. Additiona hours are RM1.00 an hour. Package C : RM69.95 per month unlimited access are provided. Write a program segment to display the total payment. hour = sc.nextInt ( ); [1 m] package = sc.next( ).chartAt (0); [1 m] [8 marks]


4 if (package == ‘A’) [½ m] if (hour >10) [½ m] total_payment = ((hour-10) * 2) + 19.95; [1 m] else total_payment = 19.95; [½ m] else if (package == ‘B’) [½ m] if (hour > 20) [½ m] total_payment = ((hour -20)* 1) + 35.95; [1 m] else total_payment = 35.95 [½ m] else total_payment = 69.95; [½ m] System.out.print (total_payment); [½ m] e) Complete the given Java to call method highestNumber using main method. public class KMLSC025 { public static void main (String [] args) ____KMLSC025____met = ____new_________ KMLSC025 ( ); [½ m, ½ m] { int x = 3, y=6; _____met____ . ____ highestNumber ____ ( x ,y ); [½ m, ½ m] } void _____ highestNumber ___ (int a, int b) [½ m, ½ m, ½ m] { If ( a > b ) [½ m] system.out.println (“a is highest number”); [½ m] else System.out.println (“b is highest number”); [½ m] } } [5 marks] 4) a) (i) Write Java program segment that will display the area of triangle. The side length input by user. Height = sc.nextdouble (); [½ m] Base = sc.nextdouble (); [½ m] Area_triangle = 0.5 * Height * Base; [½ m] System.out.print (“Area of a triangle is ” + Area_triangle); [½ m] [2 marks] (ii) Modify the program in 4) a) (i) above to allow the user to display area of triangles and program will terminate when the user enter code ‘N’ code = sc.next().charAt(0); [½ m] while (code != ‘N’){ [1 m] Height = sc.nextdouble (); Base = sc.nextdouble (); Area_triangle = 0.5 * Height * Base; System.out.print (“Area of a triangle is ” + Area_triangle); [2 marks]


5 code = sc.next().charAt(0); [½ m] } b) Write a non-static method named convertFah that returns Celsius. The method receives double named Fahrenheit. Converts a temperature from Fahrenheit to Celsius (( 5/9 (F32) where F is the Fahrenheit temperature. Given the class name convertTemp. convertTemp obj = new convertTemp ( ); [1 m] double Fahrenheit = sc.nextDouble( ); [½m] System.out.print (“The temperature in Celsius = “ + obj.covertFah(Fahrenheit)); [1 m] } double convertTemp (double a) [½ m, ½ m, ½ m] { double celsius = ((5/9)*(a-32); [½m] return celsius; [½m] } [5 marks] c) You are required to develop Java program. The program should be able to calculate and display : 1) the average temperature for a week. 2) determine the maximum and minimum temperature. 3) total number that less than average The elements of array are as follows : Temp = {37.9, 37.8, 39.2, 40.1, 36.9, 37.2, 38.3} public class Average { [½ m] Public static void main (String [] args) { [½ m] double [ ] Temp = {37.9, 37.8, 39.2, 40.1, 36.9, 37.2, 38.3}; [½ m] double total = 0, average; [½m, ½ m] double max = 0, min = 99999; [½m, ½ m] int NumLessAverage = 0; [½ m] for (int i=0; i<Temp.length; i++) { [½m, ½ m, ½ m] total = total + Temp [i]; [½ m] if (Temp[i] > max) [½ m] max = Temp[i]; [½ m] if (Temp[i] < min) [½ m] min = Temp [i]; [½ m] } average = total/Temp.length; [½ m] for (int i=0; i<Temp.length; i++) { [½m, ½ m, ½ m] if (Temp [i] < average) [½ m] NumLessAverage = NumLessAverage + 1; [½ m] } System.out.println (“Maximum temperature” + max); [½ m] System.out.println (“Manimum temperature” + min); [½ m] System.out.print(average); [½ m] } close main method [½m] for both } close class close [13 marks]


6 END OF QUESTIONS


SECTION A SULIT SC025 Computer Science Semester II Session 2021/2022 2 hours SC025 Sains Komputer Semester II Sesi 2022/2022 2 jam Nama No. Matrik Praktikum (Sila isi maklumat dengan jelas dan lengkap) KOLEJ MATRIKULASI LABUAN LABUAN MATRICULATION COLLEGE PRA-PEPERIKSAAN SEMESTER PROGRAM MATRIKULASI MATRICULATION PROGRAMME TRIAL EXAMINATION SAINS KOMPUTER 2 jam JANGAN BUKA KERTAS SOALAN INI SEHINGGA DIBERITAHU. DO NOT OPEN THIS QUESTION PAPER UNTIL YOU ARE TOLD TO DO SO. Untuk Kegunaan Pemeriksa No. Soalan Markah Pemeriksa KP / KKP 1 (11 M) 2 (15 M) 3 (20 M) 4 (22 M) 70 M Kertas soalan ini mengandungi 5 halaman bercetak This question paper consist of 5 printed pages


1 Instructions : Answer all the questions. 1) a) State an appropriate step and activities of problem solving in computer programming. [3 marks] Activity Step in problem solving (i) To make sure the program is free from syntax error, logical error and run-time error. Testing (ii) An analysis of a problem statement to identify input, process and output. Analyze the problem (iii) Transform the algorithm into a set of instructions that are understood by the computer. Implementation b) The use appropriate control structures are very important when implement the program code. Identify the most suitable control structures to solve the following problems. [2 marks] Problem Control structure (i) Calculate a book price based on category. Selection (ii) Calculate Raya bonus for each of JJ Naza’s kitchen employees. Repetition c) Identify the input, process and output from the following problems. [3 marks] (i) A shape program read radius and apply formulae to computer and display the area and circumference of the circle. INPUT Radius [1m] PROCESS Calculate the area and circumference based on radius [1m] OUTPUT Area, circumference [1m] d) (ii) int a = sc.nextInt( ); int b=a*4; if (b >=8) System.out.println (“\tWelcome to beautiful Labuan island”); else System.out.print (“\t\tHave a nice day”); [3 marks] INPUT a PROCESS To determine suitable message OUTPUT Message “Welcome to beautiful Labuan island” or “Have a nice day” 2) a) The following formula is calculate distance between two coordinates, (x1,y1) and (x2,y2). = √(2 − 1) 2 + (2 − 1) 2 Write a pseudocode to find the distance using two coordinates. [3 marks] Start Read x1,x2,y1,y2 = √(2 − 1) 2 + (2 − 1) 2 Print distance radius


2 Stop b) Write pseudocode to determine whether number is even or odd for 14 different positive numbers. [5 marks] Start i=1 [½ m] while (i<=14) [1 m] Read number [½ m] If (number % 2 == 0) [1 m] Print “Even number” [½ m] Else [½ m] Print “Odd number” [½ m] endIF i=i+1 [½ m] endWHILE Stop c) Draw flowchart based on Java segment given. [7 marks] for (n=20; n>=1; n=n-1) if (n%4 == 0) System.out.println (n); 3) a) Trace the output for the Java code below : [2 marks] int num; num = get.nextInt ( ); if (num <= 5) System.out.print (“Hi, today is PRE-PSPM.”); if (num < 10) System.out.println (“Good luck for me.”); else System.out.print (“but today I’m back to hometown”); System.out.print (“\nKML tatap dihati.”); What is the output if num variable as 5 Hi, today is PRE-PSPM.Good luck for me. KML tatap dihati. [1 m] [1 m] [1 m] [1 m] [1 m] [½ m] [½ m] 2 x Partner true/false [1 m]


3 b) What is the output of the following code fragment, assuming num is 10? num=num*2; if(num==20) System.out.print (“Wilayah Persekutuan\t”); System.out.print (“Labuan\t”); [1 mark] apple orange c) After execution of the following code, what will be the value of m and n? int n=678; int m=0; while(n!=0) { m=(10*m)+(n%10); n=n/10; } [2 marks] m = 6 n = 0 b) Given n=9, m=16, a=2, c=7. Evaluate the following statement. (i) m /n + n % m [1 mark] = (16/9) + (9 % 16) = 1 + 9 = 10 (ii) m + (n * n – a * m) / 2 * a [1 mark] = 16 + (9 * 9 – 2 * 9) / 2 * 2 = 16 + (81 – 18) /2 * 2 = 16 + 63 / 2 * 2 = 16 + 31 * 2 = 16 + 62 =78 c) Write Java assignment statement for the following algebraic expression. (i) = √(2 − 1) 2 + (2 − 1) 2 = Math.sqrt ( ( Math.pow (x2 – x1),2) + ( Math.pow (y2 – y1),2)); [2 marks] (ii) Print 2 System.out.print (3.142 * r * r); [2 marks] d) An internet service provider has three different subscription packages for its customer: Package A : RM19.95 per month for 10 hours of access are provided. Additional hours are RM2.00 an hour. Package B : RM35.95 per month for 20 hours of access are provided. Additiona hours are RM1.00 an hour. Package C : RM69.95 per month unlimited access are provided. Write a program segment to display the total payment. hour = sc.nextInt ( ); [1 m] package = sc.next( ).chartAt (0); [1 m] [8 marks]


4 if (package == ‘A’) [1 m] total_payment = (hour * 2) + 19.95; [1 m] else if (package == ‘B’) [1 m] total_payment = (hour * 1) + 35.95; [1 m] else total_payment = 69.95; [1 m] System.out.print (total_payment); [1 m] e) Complete the given Java to call method highestNumber using main method. [5 marks] public class KMLSC025 { public static void main (String [] args) _____________________ met = _____________ KMLSC025 ( ); { int x = 3, y=6; _______________________ . ____________________ ( x , y ); } void _______________________ (__________________ , _______________) { If (_______________) system.out.println (“__________________________number”); else System.out.println (“__________________________ number”); } } 4) a) (i) Write Java program segment that will display the area of triangle. The side length input by user. Height = sc.nextdouble (); [½ m] Base = sc.nextdouble (); [½ m] Area_triangle = 0.5 * Height * Base; [½ m] System.out.print (“Area of a triangle is ” + Area_triangle); [½ m] [2 marks] (ii) Modify the program in 4) a) (i) above to allow the user to display area of triangles and program will terminate when the user enter code ‘N’ code = sc.next().charAt(0); [½ m] while (code != ‘N’){ [1 m] Height = sc.nextdouble (); Base = sc.nextdouble (); Area_triangle = 0.5 * Height * Base; System.out.print (“Area of a triangle is ” + Area_triangle); code = sc.next().charAt(0); [½ m] } [2 marks]


5 b) Write a non-static method named convertFah that returns Celsius. The method receives double named Fahrenheit. Converts a temperature from Fahrenheit to Celsius (( 5/9 (F32) where F is the Fahrenheit temperature. Given the class name convertTemp. convertTemp obj = new convertTemp ( ); [1 m] double Fahrenheit = sc.nextDouble( ); [½m] System.out.print (“The temperature in Celsius = “ + obj.covertFah(Fahrenheit)); [1 m] } double convertTemp (double a) [½ m, ½ m, ½ m] { double celsius = ((5/9)*(a-32); [½m] return celsius; [½m] } [5 marks] c) You are required to develop Java program. The program should be able to calculate and display : 1) the average temperature for a week. 2) determine the maximum and minimum temperature. 3) total number that less than average The elements of array are as follows : Temp = {37.9, 37.8, 39.2, 40.1, 36.9, 37.2, 38.3} public class Average { [½ m] Public static void main (String [] args) { [½ m] double [ ] Temp = {37.9, 37.8, 39.2, 40.1, 36.9, 37.2, 38.3}; [½ m] double total = 0, average; [½m, ½ m] double max = 0, min = 99999; [½m, ½ m] int NumLessAverage = 0; [½ m] for (int i=0; i<Temp.length; i++) { [½m, ½ m, ½ m] total = total + Temp [i]; [½ m] if (Temp[i] > max) [½ m] max = Temp[i]; [½ m] if (Temp[i] < min) [½ m] min = Temp [i]; [½ m] } average = total/Temp.length; [½ m] for (int i=0; i<Temp.length; i++) { [½m, ½ m, ½ m] if (Temp [i] < average) [½ m] NumLessAverage = NumLessAverage + 1; [½ m] } System.out.println (“Maximum temperature” + max); [½ m] System.out.println (“Manimum temperature” + min); [½ m] System.out.print(average); [½ m] } close main method [½m] for both } close class close [13 marks] END OF QUESTIONS


ANSWER SCHEME IQUA COMPUTER SCIENCE 2 – SC025 Question No. Answer Mark 1(a)(i) Testing J1 1(a)(ii) Documentation J1 1(a)(iii) Implementation J1 1(b)(i) Input Process Output total price, member status [J1] Determine and calculate total price after discount based on member status and total price [J2] total price after discount [J1] 1(b)(ii) Input Process Output down payment, price [J1] Calculate monthly payment [J1] monthly payment [J1] 2(a) Start……..J½ Read km…………………………………J1 if km ≤ 500 payment = km * 0.50 else if km > 500 and km ≤ 700 payment = 250.00 + (km - 500) x 0.40 else payment = 250.00 + 80.00 + (km - 700) x 0.30 end if Display payment……………………….J1 Stop……..J½ J6 J1 J1 J1


Question No. Answer Mark 2(b) **Flowlines correct J1 J10 3(a) Hello Guys! [J1] 42 [J1] A [J½] B [J½] J3 3(b)(i) -1 J1 3(b)(ii) 1 J1 3(b)(iii) True / 1 J1 3(c)(i) y = ((10 * x * x) / 5) + 8 * x – 2; J2 3(c)(ii) val = 7 * p * (2 * r + w) J2 J½ J1 J1 J1 J1 J1 J1 J1 J½ J½ J½


Question No. Answer Mark 4(a) if (age < 3) { type = "REAR-FACING CAR SEAT "; finalPrice = 454.00 * 0.9; } else if (age >= 3 && age <= 5) { type = "FORWARD-FACING CAR SEAT "; finalPrice = 178.00 * 2; } else { type = "BOOSTER SEAT "; finalPrice = 178.00; } J6 4(b) while (num > 0) while (num >= 0) OR while (num > -1) num = num + 1 num = sc.nextInt(); J2 4(c)(i) 5.0……J1 5.0……J1 5.0……J1 5.0……J1 J4 4(c)(ii) double num2; for (int num1=20; num1<32; num1=num1+3) { num2 = num1 % 3 + 2; System.out.print(num2 + 1); System.out.println(); } J3 5(a)(i) The code does not create a Rectangle object. OR any acceptable answer. J2 5(a)(ii) Rectangle myRect = new Rectangle(); J1 5(b) 30 50 10 20 Each answer = J1 J4 J1 J1 J1 J½ J½ J½ J½ J½ J½ J1 J1 J½ J1½ J½ J½


Question No. Answer Mark 6 import java.util.Scanner; public class ArrayProgram { public static void main (String [] args) { Scanner input = new Scanner(System.in); J12 J1 All variables are declared - J1 J½ J1 J½ J½ J1 J1 J1 J1 J1 J½


J1 No missing output - J1


SC025 CONFIDENTIAL KOLEJ MATRIKULASI MELAKA COMPUTER SCIENCE 1 IQUA SC025 SEMESTER II & IV, SESSION 2021/2022 NAME : MATRIC NO. : TUTORIAL : Answer all questions. 1 (a) Problem solving is the process of transforming the description of a problem into a solution. State the appropriate step of problem solving in computer programming for each of the following statement. [3 marks] Statement Steps Evaluate the program by entering a specific value. Write a final report for future references. The process of converting the algorithm by writing a computer program using a Java programming language. (b) Identify the input, process and output based on the problem statements below: (i) Raja Workshop will give a discount of 10% from the total price if the amount of total price is more than RM200 and customer is a member of Raja Workshop. Calculate and display the total price after discount that customer has to pay. [4 marks] Input Process Output /70


SC025 CONFIDENTIAL KOLEJ MATRIKULASI MELAKA COMPUTER SCIENCE IQUA SC025 SEMESTER II & IV, SESSION 2021/2022 2 (ii) Raihanah wishes to buy a set of dining table from Impian Furniture. The interest charge, 3 percent is based on the balance of payment after deducting down payment. Calculate the monthly payment for her if she wishes to pay installment for one year. [3 marks] Input Process Output 2 (a) JomHantar Courier Company wants to use a computer program to determine payable sum of their mileage claims. Their programmer asks for your help to write the pseudocode. The payable sum is calculated using this table. KILOMETER (km) Cents per KM First 500 50 Next 200 40 Each extra km 30 Example: • If the mileage is 100 km, the payable sum is RM50.00. • If the mileage is 600 km, the payable sum RM290.00 (that is 250 + 40). • If the mileage is 800 km, the payable sum RM360.00 (that is 250 + 80 + 30). [6 marks]


SC025 CONFIDENTIAL KOLEJ MATRIKULASI MELAKA COMPUTER SCIENCE IQUA SC025 SEMESTER II & IV, SESSION 2021/2022 3 (b) Draw a flowchart to ask the user for the length of their bus/car ride until the user enters 0. Print the average of the lengths. [10 marks]


SC025 CONFIDENTIAL KOLEJ MATRIKULASI MELAKA COMPUTER SCIENCE IQUA SC025 SEMESTER II & IV, SESSION 2021/2022 4 3 (a) What is the output of the following program? [3 marks] (b) An identifier is a word that you make up to refer to a Java programming element by name. Identifiers most commonly used for variables, classes, methods, and parameters. Suppose the value for variables a, b, c, d, e, and f is 1, 3, 5, 7, 9 and 1 respectively. Evaluate the following expressions: (i) b / f – (a + a * b) [1 mark] (ii) 5 - (a + b * f) – a / b [1 mark] (iii) a == b + c || true && d / e >= (f – e) [1 mark]


SC025 CONFIDENTIAL KOLEJ MATRIKULASI MELAKA COMPUTER SCIENCE IQUA SC025 SEMESTER II & IV, SESSION 2021/2022 5 _______________________________________________ _______________________________________________ (c) Convert the following algebraic expression into Java expression. (i) y = 10x 2 + 8x - 2 5 [2 marks] _ (ii) val = 7p (2r + w) [2 marks] _ 4 (a) The use of child car seats has become mandatory in Malaysia since January 2020. To abide this rule, there are three categories of car seats according to the age as below: REAR-FACING CAR SEAT FORWARD-FACING CAR SEAT BOOSTER SEAT Below 3 years old 3 until 5 years old Above 5 years old Write a Java program segment that will determine suitable type of car seat and its final price to a customer [Assume one customer has one child only]. Price of RearFacing car seat is RM454 with a 10% discount, price of Forward-Facing car seat is double the price of Booster seat. Booster seat is sold at RM178. (Assume all variables are already declared) [6 marks]


SC025 CONFIDENTIAL KOLEJ MATRIKULASI MELAKA COMPUTER SCIENCE IQUA SC025 SEMESTER II & IV, SESSION 2021/2022 6 (b) Determine the error(s) in the following program that allows user to repeatedly enter a number until he/she has entered any negative number. Then, give the right coding. [2 marks] (c) (i) What is the output of the following program segment? [4 marks]


SC025 CONFIDENTIAL KOLEJ MATRIKULASI MELAKA COMPUTER SCIENCE IQUA SC025 SEMESTER II & IV, SESSION 2021/2022 7 (ii) Use for statement to rewrite the program segment in 4(c)(i). [3 marks] 5 (a) (i) What's wrong with the following main method program? [2 marks] (ii) Write the correct syntax for error mentioned in 5(a)(i). [1 mark]


SC025 CONFIDENTIAL KOLEJ MATRIKULASI MELAKA COMPUTER SCIENCE IQUA SC025 SEMESTER II & IV, SESSION 2021/2022 8 (b) What is the output from the following Java program fragment? [4 marks] 6 Write a Java program to create a single dimensional array of 9 integers, and print the followings: • sum of elements present at even indexes in array • sum of elements present at odd indexes in array. • sum for all integers in array • sum of even integers exist in the array • average • number of elements below average • maximum integer • minimum integer [12 marks]


SC025 CONFIDENTIAL KOLEJ MATRIKULASI MELAKA COMPUTER SCIENCE IQUA SC025 SEMESTER II & IV, SESSION 2021/2022 9 END OF QUESTIONS Sample of output:


KOLEJ MATRIKULASI NEGERI SEMBILAN SEMESTER : 02 SESI : 2021/2022 Nama Subjek : Sains Komputer Ujian : Excel Exercise 2 Masa : 2 Jam Nama pelajar : Kump. Praktikum : ARAHAN KEPADA CALON Jawab semua soalan. Kalkulator elektronik boleh digunakan. SECTION A (46 MARKAH) Question 1 a) Circle the correct answer either TRUE (T) or FALSE (F) [5 marks] i. An algorithm can be referred as a set of unordered instructions that tells how to solve a particular source. ( T / F ) ii. In algorithm, Read or Get is used to represent the computer operation that receives an information or input from particular source. ( T / F ) iii. The following pseudocode is a CORRECT algorithm that gives RM50 bonus only to a salesperson who sells more than 3 items with the total of at least RM1000 in value. ( T / F ) IF itemSold > 3 THEN bonusGiven = 50 ENDIF IF ValueSold >= 1000 THEN bonusGiven = 50 ENDIF iv. The expression num[1] designates the first element in an array. ( T / F ) v. A variable is also called an identifier. ( T / F ) b) Given the following pseudocode : [4 marks] Start if (inp <= 5) Display “ Hye I am “ inp = inp + 5 endif if (inp < 10) Display “Doraemon” Else Display “Doralin” Endif Stop i) What is the output if the value of inp is as follows: a) 0 - ____________________ b) 5 - ____________________ c) 60 - ____________________ ii) For input c), what is the first value of inp ? _____________________________________________ Question 2 a) Based on the following pseudocode, answer the following questions: The purpose of the above pseudocode is to calculate the sum of number from 10 to 100. Identify the type of errors that occur and write the errors. [4 marks] Begin Sum = 0 While Counter >= 100 then Sum = Counter Add 10 to Counter EndWhile Print “Sum of the Numbers = “,Sum End i) Rewrite the correct pseudocode [3 marks] b) Convert the following JAVA segment program to while structure. [3 marks] Untuk Kegunaan Pemeriksa No. Soalan Markah Section A – 1 9 Section A – 2 12 Section A – 3 10 Section A – 4 15 Section B – 1 14 Section B – 2 14 Section B – 3 11 Section B – 4 15 Jumlah 100


j = 15, t = 10; for (int i = 5; i > j; i = i – j) t= t + i; System.out.print (t); c) Trace the output for question b). [2 marks] Question 3 a) Write Java statement(s) that accomplish the following: [6 marks] i. Write a constant declaration holds the value of PI. ii. Declare and initialize a variable temp to 10 and variable ch to ‘A’ iii. Swap the contents of the integer variables x and y. (Declare additional variables, if necessary) iv. Write a for statement that use a counter named icount has an initial value of 20.0, a final value of 10.0, and increment of -0.5. b) Write Java assignment statements for the following algebraic equations: [4 marks] = √( − ) 2 + ( − ) 2 Print 3 2 Question 4 A Programming language requires expressions to perform calculations and make decisions. a) Explain the difference between the two Java expressions below. [2 marks] Java expressions Explanation X = 2 X == 2 b) i. Give two (2) characteristics of valid identifier. [1 mark] _________________________________________________________________________________________________________ _________________________________________________________________________________________________________ c) ii. List four (4) characteristics of Object Oriented Programming [2 marks] _________________________________________________________________________________________________________ _________________________________________________________________________________________________________ d) Evaluate the following statements. Assume that: [2 marks] int n = 9, m= 16, a = 2, c =7; i. m / n + n % m; ii. m + Math.sqrt ( n * n – a * m) / 2 * a;


e) Show the value of integer variable X after each of the following Java statement is executed. [4 marks] i. X = 12 + 3 * 5 / 2 / 6; ii. X = -8 + 7 % 5 – 5 / 4 % 3; f) Write the output produced by the following Java program segments. [2 marks] (a) int x = 1; int y = 2; if((x == 1) || (y == 2) && (y == 0)) System.out.print(“Excellent”); else System.out.print(“Worst”); ________________________________________________________________________________________________________ ________________________________________________________________________________________________________ (b) char A=’S’; char B=’Z’; if(A > B) System.out.print(A); else System.out.print(B); ________________________________________________________________________________________________________ ________________________________________________________________________________________________________ SECTION B (54 MARKAH) Question 1 a) List the steps in problem solving. [4 marks] i) Problem Analysis ii) iii) iv) v) b) Explain step iii). [2 marks] _________________________________________________________________________________________________________ _________________________________________________________________________________________________________ c) Step v) can be done in two (2) ways, give one (1) of it. [1 mark] _________________________________________________________________________________________________________ d) Give two (2) techniques that can be used in step ii). [2 marks] _________________________________________________________________________________________________________ e) Employees at Syarikat ABC Sdn. Bhd. get bonus at the end of the year. There are N number of employees at the company. Bonus is 50% of the salary. Identify the input, process and output. [3 marks] Input Process Output f) Puan Rose is planning to prepare a healthy breakfast for her family. Calculate the total price based on the price and quantity of an item that she wants to buy. For items with the item code of 5000 and above, 6% of Good and Service Tax (GST) will be imposed. Identify the input and process. (Used your test pad to answer this question). [2 marks] Input Process Output total price Question 2 a) The registration information for programming seminar is as follows: [7 marks] Number of registrants Charge per Person (RM) 1-3 150 4-9 100 10 or more 80 The price per person depends on the number of registrant(s) that a company registers. (For example, if a company registers four people, the amount that should be paid by a company is RM400). This program reads company’s name and number of registrant(s). Then, it should output the company’s name, number of registrants and the amount charged. Write a pseudocode to answer these question. (Used your test pad to answer this question).


Click to View FlipBook Version