0% found this document useful (0 votes)
851 views8 pages

SC025 ConquerSET1 (Q)

Sc conquer set

Uploaded by

Loga Kumaran
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
851 views8 pages

SC025 ConquerSET1 (Q)

Sc conquer set

Uploaded by

Loga Kumaran
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 8

SC025 SC025

SET 7
Computer Science 2 Sains Komputer 2
Semester II Semester II
Session 2022/2023 Sesi 2022/2023
2 hours
SET 1 2 jam

No. Matrik No. Kad Pengenalan No. Tempat Duduk


Matric No. Identity Card No. Seat No.

(Isikan maklumat dengan lengkap)

KOLEJ MATRIKULASI KEDAH


KEDAH MATRICULATION COLLEGE

CONQUER
TAKLUK

S JANGAN BUKA KERTAS SOALAN INI SEHINGGA DIBERITAHU.


C DO NOT OPEN THIS QUESTION PAPER UNTIL YOU ARE TOLD TO DO SO.
0 Prepared by:
2 Untuk Kegunaan Pemeriksa
5 For Examiner’s Use
…………………………………. Markah
(ONG BOON HAN) No. Soalan
Mark
Question
Pemeriksa KP / KKP
Checked by: No.
Examiner
1 4
……………………………. 2 11
(MOHD AMRAN BIN MD ALI)
3 20
Approved by: 4 8
5 11
…………………………………. 6 16
(NOOR AZZIZARINA BINTI JUMLAH
MEHAT) 70
TOTAL

Kertas soalan ini mengandungi 8 halaman bercetak.


This question paper consists of 8 printed pages.
© Kolej Matrikulasi Kedah
SC025: Computer Science 2

1 (a) Differentiate any two (2) paradigms of programming language.


[2 marks]
Procedural Object-oriented
The program is broken down into The program is divided into small
small parts called functions that parts called entity or object.
perform one task each.
Example of language:
Example of language: Java, C++
C, Pascal

(b) Differentiate any two (2) types of language translator.


[2 marks]
Compiler Interpreter
Translates the entire source code of Translates high-level programming
high-level programming language into language into machine language one
machine language. line at a time.

Example of translator: Example of translator:


Javac for Java PyPy for Python

2 Identify input, process and output based on the given problem statement.

(a) Mangoes, rambutans, and durians are sold at RM8 per kilogram, RM10 per
kilogram, and RM25 per kilogram respectively. Find the total price for all the
fruits bought by a customer.
[3 marks]
Input Process Output
kgMango Calculate totalPrice totalPrice
kgRambutan
kgDurian

2
SC025: Computer Science 2

(b) Jerseys are sold based on the following table. Find the total price of jerseys
bought by a customer.

Quantity RM per pieces


1 – 10 45
11 – 50 40
50 – 100 35
More than 100 29.90
[4 marks]
Input Process Output
qtyJersey Calculate totalPrice totalPrice
based on qtyJersey

(c) Find the total price of items bought by a customer until negative value is
entered.
[4 marks]
Input Process Output
itemPrice Repeat while itemPrice totalPrice
> 0, read itemPrice,
calculate totalPrice.

3
SC025: Computer Science 2

3 Apply appropriate control structures in computational problem solving and create


algorithm (pseudocode / flowchart).

(a) Calculate the sale price of three shirts after given 79% discount.
[6 marks]
Begin
Input shirt1Price, shirt2Price, shirt3Price
salePrice = 21% x (shirt1Price + shirt2Price + shirt3Price)
Display salePrice
End

(b) Determine whether a number entered by user is divisible by 3 only, or


divisible by 5 only, or divisible by both 3 and 5.
[7 marks]
Begin
Input number
If (number%3 = 0 and number%5 = 0)
Display "divisible by both 3 and 5"
Else If (number%3 = 0)
Display "divisible by 3"
Else If (number%5 = 0)
Display "divisible by 5"
Else
Display "Invalid input"
End If
End

(c) Repeat 24 times, read mark, determine status ("Pass" or "Fail") based on mark.
[7 marks]
Begin
Input mark
counter = 0
While (counter < 24)
If (mark ≥ 40)
Display "Pass"
Else
Display "Fail"
End If
counter = counter + 1
End While
End

4
SC025: Computer Science 2

4 (a) Describe four (4) components of a Java program.


[2 marks]
Components Description
Comments A part of a program that contains information about the
program.
Class A user defined blueprint or prototype from which objects are
created.
main method A program driver, which marks the entry point of the program.

Body Encloses with braces, { } represents a set of executable


statements.

(b) Use output and input statements including output string.


(i)
System.out.print("Hello\n\tWorld!");
System.out.println("Hello, World!");
// System.out.println("\n\tHello,\n\tWorld!\");
System.out.print("Hello, World!");

[1 mark]
Hello
World!Hello, World!
Hello, World!

(ii) Read a symbol and store it into a variable. (Assume Scanner object is
sc)
[1 mark]

char variableName = sc.next().charAt(0);

5
SC025: Computer Science 2

(c) Differentiate primitive data types and their usage.


[2 marks]
Primitive data types Usage
int Used to declare variables to store whole numbers.

float / double Used to declare variables to store floating-point


numbers.
char Used to declare variables to store a single 16-bit
Unicode character.
boolean Used to declare variables to store true or false value.

(d) Convert algebraic expression into Java statement.

(i) z = mx ÷ cy2
[1 mark]
z = m*x / (c*y*y);

−𝑏𝑏+√𝑏𝑏 2 −4𝑎𝑎𝑎𝑎
(ii) root 1 = 2𝑎𝑎
[1 mark]
root1 = (-b + Math.sqrt(b*b-4*a*c)) / (2*a);

5 (a) Construct program segment by using sequence control structure to find the
total and the average of three (3) marks. (Assume the Scanner object is obj)
[3 marks]
double mark1, mark2, mark3, total, average;
mark1 = obj.nextDouble();
mark2 = obj.nextDouble();
mark3 = obj.nextDouble();
total = mark1 + mark2 + mark3
average = total / 3;
System.out.println("The total is " + total)
System.out.println("The average is " + average)

6
SC025: Computer Science 2

(b) Construct program segment by using selection control structure to find the
status of a student ("Pass" or "Fail") based on mark. (Assume the Scanner
object is input)
[4 marks]
double mark;
mark = input.nextDouble();
if(mark < 40)
System.out.println("Fail");
Else
System.out.println("Fail");

(c) Convert the following program segment by using a while repetition to


produce the same output.

int i=0
for(int a=3; a<57; a++) {
System.out.println("\n\tHello, World!");
i = i + 1;
}

[4 marks]
int i=0;
int a=0;
while(a <57) {
System.out.println("\n\tHello, World!");
i = i + 1;
a++;
}

6 (a) Method and Array.


(i) Write a method definition to return the result to the caller determining
whether a given shape is a square shape or not based on the given
length and width.
[5 marks]
static boolean determineSquare(int length, int width) {
boolean result;
if(length == width)
result = true;
return result;
}

(ii) Write a method call for the above method definition answered in
6(a)(i).
[2 marks]
boolean status = determineSquare(length, width);

(b) Construct programs that perform one-dimensional array operations to find the
average, maximum and minimum value among 100 numbers.

7
SC025: Computer Science 2

[9 marks]
import java.util.*;
class Numbers {
static Scanner input = new Scanner(System.in);
public static void main(String[] args) {
// Variable declaration
double[] numbers = new double[100];
double total=0, average=0, max, min;

// User-friendly message
System.out.print("Enter twelve (100) rain falls:
");

// Input statement
for(int i=0; i<100; i++) {
numbers[i] = input.nextDouble();
}

// Process (SEQ / SEL / REP)


for(int i=0; i<100; i++) {
total = total + numbers[i];
}
average = total / 100;

max = numbers[0];
min = numbers[0];
for(int i=0; i<100; i++) {
if(numbers[i] > max) {
max = numbers[i];
}
if(numbers[i] < min) {
min = numbers[i];
}
}
// Output statement
System.out.println("The average is " + average);
System.out.println("The maximum is " + max);
System.out.println("The minimum is " + min);
}
}

END OF QUESTIONS
KERTAS SOALAN TAMAT

You might also like