You are on page 1of 9

SC025 SC025

Computer Science 2 Sains Komputer 2


Semester 2 Semester 2
Session 2022/2023 Sesi 2022/2023
2 hours 2 jam
No. Matrik No. Kad Pengenalan No. Tempat Duduk
Matric No. Identity Card No. Seat No.

(Isikan maklumat dengan lengkap)

KOLEJ MATRIKULASI LABUAN


LABUAN MATRICULATION COLLEGE

PRA PEPERIKSAAN SEMESTER PROGRAM MATRIKULASI


PRE MATRICULATION PROGRAMME SEMESTER EXAMINATION

JANGAN BUKA KERTAS SOALAN INI SEHINGGA DIBERITAHU.


DO NOT OPEN THIS QUESTION PAPER UNTIL YOU ARE TOLD TO DO SO.

S Untuk Kegunaan Pemeriksa


C For Examiner’s Use
0 Markah
No. Soalan
2 Mark
Question
5 Pemeriksa KP /
No.
Examiner KKP
1 4
2 25
3 32
4 9
JUMLAH
70
TOTAL

Kertas soalan ini mengandungi 9 halaman bercetak.


This question paper consists of 9 printed pages.
© Kolej Matrikulasi Labuan

1
1. Programming language is a set of rules that provide a way of telling a computer that operations
to perform. It provides a linguistic framework for describing computations.

a) Identify the types of programming language to write the codes in Code A and Code B.

Code A Code B

[2 marks]

b) Translator is a computer program that performs the translation of a program written in


a programming language into another computer language.

“This translator translates all of the source program into object


program, and saves the object program in a file.”

State the type of translator based on statement above.


[1 mark]

c) Identify the appropriate paradigms of programming languages for the following statements.

Statement Programming Language


Paradigm
(i) The program statement without describing
its control flow and express facts and rules
about problems within a system of formal
logic.
(ii) The program is broken down into small
parts called functions and work on each
piece separately.
[2 marks]

2. Problem Solving is an essential skill that helps to solve problems in programming. There are
specific steps to be carried out to solve problems in computer programming, and the success
depends on how correctly and precisely we define a problem.

a) State an appropriate step and activities of problem solving in computer programming.

Activity Step in problem solving


(i) To make sure the process executing the program
is free from syntax error, logical error and run
time error.
(ii) Process of converting an algorithm to writing
computer program using a programming
language.
(iii) Prepare description of the program codes that
called user manual.
[3 marks]

2
(iv) Based on algorithm below, identify the input, process and output.

Begin
Sum = 0
Counter = 10
While Counter >= 100 then
Sum = Counter
Counter = Counter + 10
EndWhile
Print Sum
End

Input
Process

Output
[3 marks]

Puan Asiah is planning to prepare a healthy Iftar 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 100 and above, 6% of Good and Service Tax (GST) will be imposed.

(v) Identify the input and process.

Input
Process
Output
[4 marks]

2. b) Robomatics 2023 was a big event held by Mac every year. One of the competitions was
soccerTank challenge.

(i) The pseudocode below shows the algorithm to find the winner for the primary school
soccerTank competition in the qualification round. Represent this pseudocode in an
appropriate flowchart.

Start

Read total tank


Set best goal to 0
Set tank to 0
While tank less than total tank
Read goal set1, goal set2
If goal set1 is positive and goal set2 is positive
Read tank id
Increase tank by 1

If goal set1 greater than goal set2


Set goal set1 to tank goal
Otherwise set goal set2 to tank
goal
End if

If tank goal greater than best goal


Set tank goal to best goal
Set tank id to winner id
End if
End if
Repeat / End while
3
Display best goal, winner id

Stop
[8 marks]

(ii) Java Code Challenge was another competition introduce in this event. As we
continue to move into a more connected world with smarter devices in every
household, it’s easy to see how IoT sensors could be used in agricultural
settings. They can be installed along irrigation systems or inside
greenhouses where they then monitor temperature, humidity levels, crop
health and so much more-helping farmers proactively take care of their crops
as opposed to continually reacting when things go wrong. As such
technologies improve and become ever-less expensive over time, smart
farming will undoubtedly change.

Complete the pseudocode given below which will display the maximum
temperature, the message notification of the maximum temperarute and the time
taken for the maximum temperature for an hour temperature reading. The program
will set time for the first reading at 800 am
Note: the temperature reading will be taken every 5 minutes.

4
Message notification Temperature (Celsius)

Red alert Greater than 35

Blue Greater than 16

Green alert 16 and below


[6 marks]

Begin
Set time to 800
Read temp
Set max temp to temp
While time less or equal than 860

End

3. a) (i) Output statement is used to display output on the screen.

Write Java statement to display the message Today is Pre-PSPM.

[2 marks]

(ii) Input statement is used to accept data entered by user into the computer.

Write an input statement to be kept in variable Marks with a char data type. Assume
the scanner object is masuk, and the data type has been declared.

[2 marks]

5
b) Expressions are used to perform arithmetic and logical operations, comparisons, and other
calculations that are necessary in a program. Solve the following expression by analysing
the precedence of the respective operator.

(i) 21 % 5 % 6 % 2 [2 marks]

(ii) ( 48.0 >= 49.5 && 2 == 2.0 ) || (6 ! = 6) [2 marks]

c) (i) Convert the while loop below to for loop. [4 marks]

int a, b, c;
a = 5;
b = 10;
c = 1;
while (c<=10){
System.out.print(a+b+c);
if (c%2 ==0){
a++;
b++; }
c+=3 ;
}

6
(ii) Declare m and n as integer. Using for loop to swap value m and n for 5 times.
[6 marks]

(iii) Trace the output using tracing table from following Java segment of these inputs
2.75, 2.15, 2.85, 2.20, 2.80, 2.45 .

int n = 3, max =0;


for (int i = 0; i<n; i++){
double Jump1 = input.nextInt( );
double Jump2 = input.nextInt( );

if (Jump1 > max)


max = Jump1;

if (Jump2 > max)


max = Jump2;
}
System.out.print ("The longest jump is : " +
max + "(M)");
[5 marks]
max i Jump1 Jump2

Output : ___________________________________________________________

3. d) (i) An array is an ordered sequence of data of the same type. Write a segment of array
to accept 5 integer and display the total the sum of all 5 integers. Use i as your
counter, input as your scanner object, num as your integer variable, total as your
sum variable.
[5 marks]

7
(ii) Write a segment of array code so that it produces an output like these. Use String
as your data type. Use name as your array variable. Use i as your counter. Assume
your scanner object is masuk.
Output : [4 marks]

Enter name : Ali


Enter name : Abu

You entered : Ali and Abu

4. McDonald's restaurant aimed to increase their profitability on McChicken burger for next year.
You have been hired by the McDonald's strategy and marketing team to create a program
which will help them review their McChicken burger sales for the whole year. Given that the
McChicken burger sold at RM 5 per burger on its own, create a method calcBurgerCost which
take the number of burgers sold each month as its parameter and return the total sales for a
month. The program should calculate and display the following information:
a) Total McChicken burger sold for a year.
b) The month with the highest sale of McChicken burger.
c) The month with the lowest sale of McChicken burger.

[9 marks]

8
END OF QUESTIONS

You might also like