KOLEJ MULTIMEDIA JALAN GURNEY KIRI 54100 KUALA LUMPUR SECOND SEMESTER EXAMINATION, 2010/ 2011 SESSION PSD 2143 INTRODUCTION TO PROGRAMMING II NOR QUSIAH ABDUL RAZAK / ZAKRI MD SALLEH / AZNANI DAUD INSTRUCTION TO STUDENT 12 APRIL 2011 2.30 PM 5.00 PM (2 ½ Hours) 1. This Examination paper has FIFTHTEEN (15) printed pages. 2. This question paper consists of FOUR (4) sections. Section A : Answer ALL questions. Section B : Answer ALL questions. Section C : Answer ALL questions. Section D : Answer ALL question 3. Please write all your answers in the Answer Booklet provided.
PERATURAN PEPERIKSAAN MULTIMEDIA KOLEJ PENYELEWENGAN AKADEMIK 1. Pelajar tidak boleh melakukan mana-mana penyelewengan di bidang akademik seperti berikut atau sebarang arahan peperiksaan yang dikeluarkan oleh Ketua Pengawas Peperiksaan. HUKUMAN 1.1 Pelajar yang meniru hasil kerja orang lain atau tidak mengiktiraf kerja orang lain (plagiat) untuk tujuan tugasan atau ujian akan dikenakan tindakan tatatertib. 1.2 Pelajar juga tidak dibenarkan bersubahat dalam peniruan atau penipuan yang dinyatakan dalam para 1.1. 1.3 Pelajar perlu juga mematuhi peraturan lain mengenai penilaian yang dinyatakan secara lisan atau bertulis. 1. Sekiranya pelajar didapati telah melakukan pelanggaran mana-mana daripada peraturan peperiksaan ini, setelah dibicara dan sabit kesalahannya, maka jawatankuasa Disiplin Pelajar boleh mengambil tindakan dari mana-mana satu, atau apa-apa kombinasi yang sesuai dari dua atau lebih hukuman-hukuman berikut:- (a) sama ada memberimarkah '0' kepada peperiksaan akhir bagi mata pelajaran berkenaan atau memberi markah sifar '0' bagi keseluruhan keputusan peperiksaan mata pelajaran yang berkenaan. (Termasukkerjakursus); (b) Menggantung pengajian pelajar selama tempoh yang difikirkan patut oleh Jawatankuasa Disiplin; (c) Dikenakan hukuman atau denda; (d) lain-lain hukuman yang akan ditetapkan oleh Jawatankuasa Disiplin Pelajar Kolej 2. Pelajar yang melanggar peraturan juga boleh diambil tindakan tatatertib mengikut peruntukan yang terdapat dalam Peraturan & Tatatertib Pelajar, KLT,2000. Dikeluarkan oleh Unit Peperiksaan & Unit Kemasukan dan Rekod Pelajar, Kolej Multimedia, Kuala Lumpur, Julai 2001 NQAR/ZMS/AD Page 2 of 15
BAHAGIAN A : SOALAN OBJEKTIF (10 Markah) SECTION A : OBJECTIVE QUESTIONS (10 Marks) ARAHAN : Jawab SEMUA Soalan INSTRUCTION : Answer ALL Question 1. Apakah keupayaan C++ yang mempunyai kebolehan yang besar berbanding dengan C? What feature in C++ improves the capability of programmers as compared to C? A. Object-structured-programming (OSP) B. Object-oriented-programming (OOP) C. Oriented-based-programming (OBP) D. Oriented-variable-programming (OVP) 2. Syntax C++ yang manakah adalah betul? Which C++ syntax is correct? A. cout << \nthis is the answer ; B. cout >> \nthis is the answer ; C. cout ( \nthis is the answer ); D. cout >> ( \nthis is the answer ); 3. Tatasusunan dengan empat (4) baris dan tujuh (7) lajur mempunyai unsur. A four (4) rows and seven (7) columns array has a total of elements. A. 11 B. 28 C. 20 D. 32 NQAR/ZMS/AD Page 3 of 15
4. Bagaimanakah nilai di masukkan ke dalam array bolehubah dua-dimensi? How do you declare value in a two-dimentional array variable? A. array1[2][3] = ((1,2,3),(4,5,6)); B. array1[2][3] = {{1,2,3,{4,5,6; C. array1[2][3] = ((1,2),(3,4),(5,6)); D. array1[2][3] = {{1,2,{3,4,{5,6; 5. Yang manakah diantara penyataan berikut TIDAK benar? Which of the following statements is NOT correct? A. Array adalah struktur data yang mempunyai jenis data yang sama. Arrays are data structure consisting of related data items of the same type. B. Array adalah entity yang static iaitu saiz array tidak berubah apabila program dilancarkan. Arrays are static entities in that they remain the same size throughout program execution. C. Array adalah satu lokasi memori berkumpulan yang berkaitan dengan pelbagai nama dan jenis data. An array is a group of memory locations related by the fact that they all have different name and different data type. D. Array melingkumi di dalam memori. Pengguna menyatakan jenis elemen dan bilangan elemen di dalam array supaya komputer boleh menyimpan bilangan memori yang mencukupi. Arrays occupy space in the memory. You specify the type of each element and the number of elements in the array so that the computer may reserve the appropriate amount of memory. NQAR/ZMS/AD Page 4 of 15
6. Pertimbangkan segmen kod di bawah: Consider the following code segment: char String[15] = Beautiful ; Apakah nilai bagi String[4]? What is the value of String[4]? A. a B. u C. t D. i' 7. Yang manakah antara berikut adalah pengistiharan pointer? Which of the following is the declaration of pointer? A. int x; B. int &x; C. ptr x; D. int *x; 8. Yang manakah antara berikut memberikan elemen pertama tatasusunan sales bagi alamat memori, dengan 50 elemen tatasusunan? Which of the following gives the memory address of the first element in array sales, an array with 50 elements? A. sales[1]; B. sales; C. sales[0]; D. &sales; NQAR/ZMS/AD Page 5 of 15
9. Untuk menggunakan samada fail input atau output, program mestilah memasukkan. To use either input or output file, the program must include the. A. <ofstream> B. <ifstream> C. <fstream> D. <iostream> 10. Apakah fungsi yang digunakan untuk input data menggunakan papan kekunci? What is the function will used to input data using keyboard? A. printf B. cout C. cin D. scanf NQAR/ZMS/AD Page 6 of 15
BAHAGIAN B : BETUL (B) ATAU SALAH (S) (10 Markah) SECTION B : TRUE (T) OR FALSE (F) (10 Marks) ARAHAN : Jawab SEMUA soalan INSTRUCTION : Answer ALL questions 1. Structure adalah koleksi beberapa variables yang menggunakan nama sama. Structure mungkin mempunyai variable-variable yang pelbagai jenis data type. Structures are collection of related variables under one name. Structures may contain variables of many different data types. 2. Pembolehubah dalam C++ boleh bemula dengan angka. A C++ identifier can start with a digit. 3. Jika pengistiharan adalah int marks[ ] = {75, 45, 80, 60; maka saiz tatasusunan marks adalah 5. If declaration is int marks[ ] = { 75, 45, 80, 60; then the size of array marks is 5. 4. Fungsi cin dalam program C++ adalah sama dengan fungsi scanf dalam program C. cin function in C++ program is the same with scanf function in C program. 5. Indeks terakhir di dalam tatasusunan yang mempunyai 35 elemen ialah 35. The last index number in any array with 35 elements is 35. 6. Elemen yang ke tujuh bagi tatasusunan C merujuk kepada c[6]. The seventh element of an array C is referred to as C[6]. 7. Penyataan for (x=0; x<=9; x++) akan melaksanakan gelung sebanyak sembilan kali. The for (x=0; x<=9; x++) statement will execute the loop for nine (9) times. NQAR/ZMS/AD Page 7 of 15
8. Operator & digunakan untuk mengistiharkan pembolehubah pointer dan untuk mengakses ruang memori yang mana point pembolehubah pointer. The operator & is used to declare a pointer variable and to access the memory space to which a pointer variable points. 9. Ahli-ahli didalam struktur boleh terdiri dari jenis data yang berlainan. Structure members can be of different data types. 10. Takrifan pointer bagi nptr berjenis float ditulis seperti berikut adalah sah. Define a pointer of nptr type float as follows is valid: f loat *nptr; NQAR/ZMS/AD Page 8 of 15
BAHAGIAN C : JAWAPAN PENDEK (50 Markah) SECTION C : SHORT ANSWER (50 Marks) ARAHAN : Jawab SEMUA soalan INSTRUCTION : Answer ALL questions Soalan / Question 1 a) Apakah output bagi program berikut : What is the output of the following program : #include<iostream.h> int main() { int item1 = 7; int item2[5] = {0,1,2,3,4; int item3[2][2] = {{1,2,{3,4; cout << "Item 1 =" << item1 << endl; cout << "Item 2 =" << item2[3]<< endl ; cout << "Item 3 =" << item3[0][1]; (6 markah/marks) b) Diberi takrifan data bagi suatu tatasusunan dua (2) dimensi Number yang mempunyai empat (3) baris dan enam (6) lajur. Given the data definition for Number the two dimensional array which contain 3 row and 6 column as: int Number [3][6] = {30, 06, 07, 02, 16, 09 Apakah nilai bagi unsure berikut? What is the value for the following element? 12, 21, 05, 10, 17, 22 17, 12, 13, 08, 11, 03 ; i) Mark [1][3] ii) Mark [0][5] iii) Mark [2][6] iv) Mark [2][2] (4 markah/marks) NQAR/ZMS/AD Page 9 of 15
Soalan / Question 2 Berikan output bagi keratan aturcara berikut: Give the output for the following program segment: a) char *s1 = ABCDE char *s2 = ABC if (strcmp(s1,s2) < 0) printf( %s < %s \n,s1,s2); else printf( %s >= %s \n,s1,s2); (4 markah/marks) b) void main( ) { int x = 30, y = 50; int *j, *k; j = &x; k = &y; *k = *j + 40; x = x + *j; printf( j is %4d and k is %4d\n, *j, *k); printf( x is %4d and y is %4d\n, x, y); (6 markah/marks) NQAR/ZMS/AD Page 10 of 15
Soalan / Question 3 a) Aturcara berikut mengandungi beberapa ralat sintaksis. Cari dan tulis semula program yang betul. The following programs have few syntax errors. Find the errors and rewrite the correct programs. i) #include [iostream] int main() int num1; num2; total int answer; cout <="Enter first number"; cin >>num1; cout >>"Enter second number"; cin >> num2; total = num1 + num2; cout << total; cin >> answer; if(answer = total) { cout <<"True"; else { cout <<"False"; (5 markah/marks) ii) #include {iostream int main ( int even:odd:number cout >>"Enter number:" cin <<number if(number %2==0) cout >>"Your number is even" ) else cout >>"Your number is odd" cout <<"\n" return 0; (5 markah/marks) NQAR/ZMS/AD Page 11 of 15
Soalan / Question 4 a) Berikan output bagi program berikut : Give the output for the following programs : #include<iostream.h> int main() { int i=100; int *j=&i; int &k=*j; cout << "value i is " << i + k << endl; cout << "value j is " << 2 * k - k << endl; (5 markah/marks) b) Perhatikan keratan aturcara berikut. Tunjukkan output sekiranya n=5. Have a look at the following program segment. Show the output if n=5. #include<iostream.h> int main() { int n,i,total; cout<<"enter value greater than 0 "<<endl; cin>> n; i =n-1; total = 0; while (i!= 0) { jumlah += i; i--; cout<<total<<endl; (5 markah/marks) NQAR/ZMS/AD Page 12 of 15
Soalan / Question 5 a) Berikan output bagi keratan program berikut : Give the output for the following programs segment : i) cout << "Before using showpoint \n" << "1.1100 prints as: " << 1.1100 << endl ; ii) cout << showpoint << "After using showpoint \n" << "1.1100 prints as: " << 1.1100 << endl ; iii) cout << "Use std::left to left justify:\n" << left << setw( 10 ) << 12345<< endl; iv) cout << "Use std::right to right justify:\n" << right<< setw( 10 ) << 12345 << endl; v) cout << uppercase << 123abc << endl; (10 markah/marks) NQAR/ZMS/AD Page 13 of 15
BAHAGIAN D : KAJIAN KES - (30 markah) SECTION D : CASE STUDY - (30 marks) ARAHAN : Jawab SEMUA soalan sahaja. INSTRUCTION : Answer ALL questions. Soalan / Question 1 Tulis sebuah program yang akan menggunakan sequential-access file. Program tersebut akan menyimpan rekod pelajar dan markah peperiksaan yang diperolehi. Berikut adalah diperlukan di dalam program ini. Write a program which uses a sequential-access file. The program will keep records of students and their exam score. The following required in the program:- a) Program memerlukan 4 boleh ubah/array seperti berikut:- Nama boleh ubah Jenis data Nota icnumber double No IC Pelajar name[30] char Nama Pelajar subject[30] char Matapelajaran diambil pelajar score integer Markah yang diperolehi The program shall have 4 variables/array which are as follows:- Variable name Data type Note icnumber double Student s IC number name[30] char Student s Name subject[30] char Subject taken by student score integer Mark obtained for subject b) Data fail yang direka oleh program ini dinamakan exam.txt. The data file created by the program is called exam.txt. c) Untuk keluar dari program ini petunjuk -1 digunakan. The program must have an -1 indicator to exit the program. d) Contoh output adalah seperti berikut: Example of the records written in the file are as follows:- NQAR/ZMS/AD Page 14 of 15
(20 markah/marks) Soalan / Question 2 Tulis sebuah program yang membaca dalam jejari bulatan dan mencetak diameter, lilitan, dan kawasan bulatan. Gunakan nilai 3.142 untuk π. Pastikan output jelas berlabel. Contohnya, jika pengguna memasukkan 15, output anda adalah seperti berikut: Write a program that reads in the radius of a circle and prints the circle s diameter, circumference, and area. Use the constant value 3.142 for π. Be sure that the output is clearly labeled. For example, if the user enters 15, your output should be as following: Note: The formula for the Circumference (C) and Area (A) of a circle are : C= 2πr and A= πr 2 (10 markah/marks) End of Page NQAR/ZMS/AD Page 15 of 15