SECTION B : 55 MARKS BAHAGIAN B : 55 MARKAH INSTRUCTION: This section consists of TWO (2) structured questions. Answer ALL questions. ARAHAN: Bahagian ini mengandungi DUA (2) soalan berstruktur. Jawab semua soalan. QUESTION 1 SOALAN 1 (a) i) Describe TWO (2) types of comment that supported by C++ program. Nyatakan DUA (2) jenis komen yang disokong oleh program C++. ii) Explain THREE (3) types of data used in C++ program. Terangkan TIGA (3) jenis data yang digunakan dalam program C++. (b) i) Identify the most suitable data types for the following variables in Figure B1. Kenalpasti jenis data yang paling sesuai bagi pembolehubah berikut dalam Rajah B1. Age Money Name Grade Variables Figure B1/Rajah B1 Data Type 16 SULIT
ii) By using the answers in (b) (i), write the syntax to declare the variables. Dengan menggunakan jawapan (b) (i), tuliskan sintak pengisytiharaan bagi pembolehubah. [4 marks] [4 markah] iii) Identify the suitable variables for input and output statement based on pseudo code given in Figure B2. Kenalpasti pemboleh ubah yang sesuai untuk kenyataan input dan output berdasarkan psuedo code yang diberikan dalam Rajah B2. Algorithm 1: Determine Sum of two numbers. Start Declare variable/s Read input Operate Sum = a+b Display Sum = End Figure B2/Rajah B2 (c) i) Differentiate these selection statements; if-else and switch. Nyatakan perbezaan bagi pernyataan pemilihan ini; if-else dan switch. ii) State the definition of local and global variables. Nyatakan definisi bagi pembolehubah dalaman dan global. 17 SULIT
iii) Identify the identifier scope for the segment code in Figure B3 below. Kenalpasti skop identifier untuk kod segmen di Rajah B3 di bawah. #include<iostream> int B; FunctionName() int A; /*Block of one or more */ /*C statements*/ Figure B3/Rajah B3 iv) Complete the syntax for switch case statement in Figure B4 below. Lengkapkan sintaks bagi kenyataan switch case di Rajah B4 di bawah. switch (code) 'd': balance = balance + amount; cout << "your balance << balance; ; case 'w': balance = balance - amount; cout << "your balance << ; break; : cout << " code not allowed!\n"; Figure B4/Rajah B4 [4 marks] [4 markah] 18 SULIT
QUESTION 2 SOALAN 2 (a) Describe the following components of array: Jelaskan komponen tatasusunan berikut: (i) (ii) (iii) Index Element Size (b) (i) Define a function. Berikan definisi fungsi. [1 marks] [1 markah] (ii) List TWO (2) types of function. Senaraikan DUA(2) jenis fungsi 19 SULIT
(c) Based on Figure B5, state which LINE is referring to the following: Berdasarkan Rajah B5, nyatakan BARIS yang merujuk kepada berikut: Line 1 Line 2 Line 3 Line 4 Line 5 Line 6 Line 7 Line 8 Line 9 Line 10 Line 11 Line 12 Line 13 Line 14 Line 15 Line 16 (i) (ii) #include <iostream.h> int square (int); int main() for (int x = 1; x <= 10; x++) cout << square(x) << " "; cout << endl; return 0; int square (int y) return y * y; Function header Figure B5/ Rajah B5 Function prototype /declaration (d) State ONE (1) example to declare the following: Nyatakan SATU (1) contoh pengisytiharan untuk yang berikut: (i) (ii) (iii) One dimensional array Pointer Structure. 20 SULIT
(e) Write C++ statement for the following: Tuliskan pernyataan C++ bagi yang berikut: i. Declare array name Student of 6 elements of int data type. Isytihar tatasusunan Student yang mempunyai 6 elemen jenis data int. C3 (f) Identify the outputs for Figure B6 shown below. Kenalpasti output bagi Rajah B6 di bawah. #include <iostream.h> int test (int a, int &b); int main () int a=9, b=4; cout<<"the value of a:"<<a<<" and b:"<<b<<endl; test(a,b); int test(int a, int &b) a++; b--; cout<<"the value of a:"<<a<<" Figure B2/ Rajah and B2 b:"<<b<<endl; return 0; Figure B6/ Rajah B6 [4 marks] [4 markah] 21 SULIT
(g) Based on Figure B7, fill in the blanks with the correct answer. Berdasarkan Rajah B7, isikan tempat kosong dengan jawapan yang betul. #include <iostream.h> void main() char letter[ i ] = 'A', 'B', 'C', 'D', 'E', F, G, H, I, J ; for (int i=0;i <10;i++) cout<< ii cout<< endl; Figure B7/Rajah B7 C3 (h) Design and write a program that declares an integer array called lists [5]. Initialize it to some values. Next, declare two pointers variable(one, two). Then assign the address of the lists variable array to the pointer one. Next assign the address stored in pointer one to the two. Lastly, display the value of lists variable array, one and two variable. Tulis program yang mengisytiharkan integer array dipanggil lists [5]. Berikan sebarang nilai kepada element bagi integer array lists[5]. Kemudian, isytihar dua penunding iaitu one dan two serta umpukkan alamat pembolehubah tatasusunan lists kepada penunding one. Seterusnya tentukan alamat yang disimpan dalam penunding one kepada penunding two. Tunjukkan nilai pembolehubah tatasusunan lists, one dan two. [5 marks] [5 markah] 22 SULIT
(i) Based on Figure B8, fill in the blanks with the correct answer. Berdasarkan Rajah B8, isikan tempat kosong dengan jawapan yang betul. #include<iostream> i // function protoype int main() int number, result; number=5; result= ii //function call cout<<"the result is:"<<result<< endl; return(0); int add( iii ) number=number+100; return(number); Figure B8/Rajah B8 C4 (j) Help Ahmad to write a function named Triangle that return float value and accept two float parameters which are base and height. Next, write the formula to calculate the area of triangle in the Triangle function. Bantu Ahmad untuk menulis fungsi yang bernama Triangle yang memulangkan nilai float dan menerima dua parameter float iaitu base dan height. Tuliskan formula untuk mengira luas segitiga di dalam fungsi Triangle. SOALAN TAMAT 23 SULIT