UNIVERSITI MALAYSIA PERLIS. DNT 126 Basic Computer Programming [Asas Pengaturcaraan Komputer]

Similar documents
INSTRUCTION: This section consists of FOUR (4) questions. Answer ALL questions. ARAHAN: Bahagian ini mengandungi EMPAT (4) soalan. Jawab SEMUA soalan.

UNIVERSITI SAINS MALAYSIA. CPT111/CPM111 Principles of Programming [Prinsip Pengaturcaraan]

PART A SULIT (EKT 221) BAHAGIAN A. Answer ALL questions. Question 1. a) Briefly explain the concept of Clock Gating.

UNIVERSITI SAINS MALAYSIA. Peperiksaan Semester Pertama Sidang Akademik 2003/2004. September/Oktober 2003

...a- JEE ELEKTRONIK DIGIT II. UNlVERSlTl SAINS MALAYSIA. Peperiksaan Semester Kedua Sidang Akademik FebruarVMac 2003.

INSTRUCTION: This section consists of TWO (2) structured questions. Answer ALL questions.

UNIVERSITI SAINS MALAYSIA. CMT322/CMM323 Web Engineering & Technologies [Kejuruteraan & Teknologi Web]

EEE348 INTRODUCTION TO INTEGRATED CIRCUIT DESIGN (PENGANTAR REKABENTUK LITAR BERSEPADU)

UNIVERSITI SAINS MALAYSIA

UNIVERSITI SAINS MALAYSIA. CPT113 Programming Methodology & Data Structures [Metodologi Pengaturcaraan & Struktur Data]

MAT 181 Programming For Scientific Applications [Pengaturcaraan Untuk Penggunaan Sains]

LAB 5: WORKING WITH DATA

EEE 348 PENGANTAR REKABENTUK LITAR BERSEPADU

EEE 428 SISTEM KOMPUTER

MULTIMEDIA COLLEGE JALAN GURNEY KIRI KUALA LUMPUR

INSTRUCTION: This section consists of TWO (2) structured questions. Answer ALL questions.

INSTRUCTION: This section consists of TWO (2)short answers and TWO (2) structured essays. Answer ALL questions.

UNIVERSITI SAINS MALAYSIA. CPT211-CPM313 Programming Language Concepts & Paradigm [Konsep & Paradigma Bahasa Pengaturcaraan]

UNIVERSITI SAINS MALAYSIA. CPT344 Computer Vision & Image Processing [Penglihatan Komputer & Pemprosesan Imej]

MSS 318 Discrete Mathematics [Matematik Diskret]

UNIVERSITI SAINS MALAYSIA. CST232 Operating Systems [Sistem Pengendalian]

INSTRUCTION: This section consists of FOUR (4) structured questions. Answer ALL questions.

UNIVERSITI SAINS MALAYSIA. CPT103/ CPM211 Struktur Data & Paradigma Pengaturcaraan

INSTRUCTION: This section consists of TWO (2) structured questions. Answer ALL questions.

INSTRUCTION: This section consists of TWO (2) short answer and structured essay questions. Answer ALL questions.

UNIVERSITI SAINS MALAYSIA. CST131 Computer Organisation [Organisasi Komputer]

CPT111/CPM111 Principles of Programming [Prinsip Pengaturcaraan]

MSS 317 Coding Theory [Teori Pengekodan]

MICROSOFT EXCEL. Membina Hamparan Elektronik Fungsi Hamparan Elektronik

Pengenalan Sistem Maklumat Dalam Pendidikan

UNIVERSITI SAINS MALAYSIA. CPT103 Struktur Data & Paradigma Pengaturcaraan

MAT 181 Programming for Scientific Applications [Pengaturcaraan untuk Penggunaan Sains]

INSTRUCTION: This section consists of FOUR (4) structured questions. Answer ALL questions.

UNIVERSITI MALAYSIA PERLIS. EKT 120 Pengaturcaraan Komputer [Computer Programming]

MULTIMEDIA COLLEGE JALAN GURNEY KIRI KUALA LUMPUR

Panduan Guru Maker UNO/ Arduino

UNIVERSITI SAINS MALAYSIA. CST131 Computer Organisation [Organisasi Komputer]

UNIVERSITI SAINS MALAYSIA. CST332 Internet Protocols. Architecture & Routing [Protokol, Seni Bina & Penghalaan Internet]

MAT181 Programming For Scientific Applications [Pengaturcaraan Untuk Penggunaan Sains]

UNIVERSITI SAINS MALAYSIA. CST131 Computer Organisation [Organisasi Komputer]

UNIVERSITI SAINS MALAYSIA. CST331 Principles of Parallel & Distributed Programming [Prinsip Pengaturcaraan Selari & Teragih]

MAT 181 Programming For Scientific Applications [Pengaturcaraan Untuk Penggunaan Sains]

INSTRUCTION: This section consists of TEN (10) structured questions. Answer ALL questions.

UNIVERSITI SAINS MALAYSIA. CPT111 Principles of Programming [Prinsip Pengaturcaraan]

[40 marks] [40 marks] Answer all questions. Jawab semua soalan.

KOLEJ MULTIMEDIA JALAN GURNEY KIRI KUALA LUMPUR

UNIVERSITI SAINS MALAYSIA. CIT502 Pengaturcaraan dan Kejuruteraan Perisian Berorientasi Objek

CPT211/CPM313 Programming Language Concepts & Paradigms [Konsep & Paradigma Bahasa Pengaturcaraan]

MULTIMEDIA COLLEGE JALAN GURNEY KIRI KUALA LUMPUR

INSTRUCTION: This section consists of TWO (2) questions. Answer ALL questions. ARAHAN: Bahagian ini mengandungi DUA (2) soalan. Jawab SEMUA soalan.

INSTRUCTION: This section consists of TWO (2) questions. Answer ALL questions. ARAHAN: Bahagian ini mengandungi DUA (2) soalan. Jawab SEMUA soalan.

UNIVERSITI SAINS MALAYSIA. CPT101 Prinsip-Prinsip Pengaturcaraan

Pengguna akan diberikan Username dan Password oleh Administrator untuk login sebagai admin/conference Manager bagi conference yang akan diadakan.

UNIVERSITI SAINS MALAYSIA. CST333 Distributed & Grid Computing [Perkomputeran Teragih & Grid]

MAT 181 Programming For Scientific Applications [Pengaturcaraan Untuk Penggunaan Sains]

UNIVERSITI SAINS MALAYSIA. CPT101 Prinsip-Prinsip Pengaturcaraan

ssk 2023 asas komunikasi dan rangkaian TOPIK 4.0 PENGALAMATAN RANGKAIAN Minggu 11

INSTRUCTION: This section consists of TWO (2) structured questions. Answer ALL questions.

INSTRUCTION: This section consists of FOUR (4) structured questions. Answer ALL questions.

INSTRUCTION: This section consists of TWO (2)structured questions.answer ALL questions.

Lab 4 : Sorting Techniques

CPT212 Design & Analysis of Algorithms [Reka Bentuk & Analisis Algoritma]

UNIVERSITI SAINS MALAYSIA. CMT324 Computer Graphics & Visual Computing [Grafik Komputer & Perkomputeran Visual]

INSTRUCTION: This section consists of TWO (2) structured questions. Answer ALL questions.

EEM 312 ROBOTIK & PENGLIHATAN MESIN

INSTRUCTION: This section consists of FOUR (4) structured questions. Answer ALL questions.

UNIVERSITI MALAYSIA PERLIS. EKT 120 Pengaturcaraan Komputer [Computer Programming]

UNIVERSITI SAINS MALAYSIA. CCS522 Advanced Data Communication & Computer Networks [Rangkaian Komputer & Komunikasi Data Lanjutan]

UNIVERSITI SAINS MALAYSIA. CCS521 Advanced Distributed Systems Concepts and Design [Konsep dan Reka Bentuk Sistem Teragih Maju]

B,8 PERKHIDMATAN KREDIT DAN PERBANKAN. Pemindahan Data PROSEDUR UNIT KOMPUTER. BPKP/KlOK-117 Bilangan Semakan : 0 Tarikh : PERUBAHAN.

PANDUAN PENGGUNA (SUPPLIER) MAINTAIN CERTIFICATES/SUPPLIER DETAILS SUPPLIER RELATIONSHIP MANAGEMENT SUPPLY CHAIN MANAGEMENT SYSTEM (SCMS)

MANAGE COURSE RESOURCES LABEL TEXT PAGE URL BOOK FILE FOLDER IMS CONTENT PACKAGE

Panduan Pengguna Autodesk Education Community

Persekitaran Pengaturcaraan Arduino

[40 marks] [40 markah] Answer all questions. Jawab semua soalan.

UNIVERSITI SAINS MALAYSIA. CST331 Principles of Parallel & Distributed Programming [Prinsip Pengaturcaraan Selari & Teragih]

UNIVERSITI MALAYSIA SARAWAK KOTA SAMARAHAN SARAWAK

PANDUAN PENGGUNA (SUPPLIER) MAINTAIN CERTIFICATES/SUPPLIER DETAILS SUPPLIER RELATIONSHIP MANAGEMENT SUPPLY CHAIN MANAGEMENT SYSTEM (SCMS)

Manual Pengguna. PCN Online Service Fulfillment System

PENGENALAN KEPADA ALGORITMA & STRUKTUR DATA

UNIVERSITI SAINS MALAYSIA. CPT103/CPM211 Struktur Data & Paradigma Pengaturcaraan

UNIVERSITI SAINS MALAYSIA. CCS522 Advanced Data Communication and Computer Networks [Rangkaian Komputer dan Komunikasi Data Lanjutan]

PANDUAN PENGGUNA (SUPPLIER) e-purchase ORDER FOR SERVICES

HARDWARE/SOFTWARE SYSTEM-ON-CHIP CO-VERIFICATION PLATFORM BASED ON LOGIC-BASED ENVIRONMENT FOR APPLICATION PROGRAMMING INTERFACING TEO HONG YAP

TEKNOLOGI, GADJET & KEIBUBAPAAN

PANDUAN PENGGUNA (PENTADBIR SYSTEM/SYSTEM ADMINISTRATOR) (INFOTECH, BPPF DAN POLIS

Jawab semua soalan. Nyatakan nilai digit bagi digit yang bergaris. State the digit value of the underlined digit.

INSTRUCTION: This section consists of TWO (2) structured questions. Answer ALL questions.

COMBINING TABLES. Akademi Audit Negara. CAATs ASAS ACL / 1

PANDUAN PENGGUNA (PENSYARAH)

EEE MIKROPEMPROSES II

UNIVERSITI SAINS MALAYSIA. CMT422 Multimedia Information Systems & Management [Sistem & Pengurusan Maklumat Multimedia]

Analysis SPM of year 2007, 2008, 2009, 2010, 2011, 2012, 2013 (Section B & C)

GARIS PANDUAN PERMOHONAN IMBUHAN PENERBITAN JURNAL / PROSIDING / SITASI BERINDEKS SCOPUS

UNIVERSITI SAINS MALAYSIA EEE 355 ROBOT DAN PENGAUTOMATAN

MULTIMEDIA COLLEGE JALAN GURNEY KIRI KUALA LUMPUR

UNIVERSITI SAINS MALAYSIA. CCS513 Computer Vision and Image Analysis [Penglihatan Komputer dan Analisis Imej]

UNIVERSITI SAINS MALAYSIA. CST334 Network Monitoring & Security [Pengawasan & Keselamatan Rangkaian]

UNIVERSITI SAINS MALAYSIA

UNIVERSITI SAINS MALAYSIA

Transcription:

UNIVERSITI MALAYSIA PERLIS Peperiksaan Semester Kedua Sidang Akademik 2015/2016 March 2016 DNT 126 Basic Computer Programming [Asas Pengaturcaraan Komputer] Masa: 3 jam Please make sure that this question paper has TEN(10) printed pages including this front page before you start the examination. [Sila pastikan kertas soalan ini mengandungi SEPULUH (10) muka surat yang bercetak termasuk muka hadapan sebelum anda memulakan peperiksaan ini.] This question paper has SIX (6) questions. Answer all FOUR (4) questions in Section A and ONE (1) question in Section B. Each question contributes 20 marks. [Kertas soalan ini mengandungi ENAM (6) soalan. Jawab kesemua EMPAT(4) soalan di Bahagian A dan SATU (1) soalan di Bahagian B. Markah bagi setiap soalan adalah 20markah.]

-2- Section A [Bahagian A] This section has FOUR (4) questions. Answer ALL questions. [Bahagian ini mengandungi EMPAT (4) soalan. Jawab SEMUA soalan.] Question A1 [Soalan A1] a) The basic control structures are sequence structure, selection structure and repetition structure. Differentiate the THREE (3) types of control structures by showing the flowchart. [Struktur kawalan asas adalah struktur urutan, struktur pilihan dan struktur pengulangan. Bezakan TIGA (3) jenis struktur kawalan dengan menunjukkan carta alir.] (6 Marks/Markah) b) A computer is composed of several parts for it to function. Draw a block diagram of all its parts. [Komputer terdiri daripada beberapa bahagian untuk membolehkannya beroperasi. Lukiskan gambarajah blok bagi semua bahagiannya.] (4 Marks/Markah) c) There are mainly THREE (3) types of programming errors which are syntax errors, run time errors and logic errors. [Terdapat utamanya TIGA (3) jenis ralat pengaturcaraan iaitu ralat sintaks, ralat masa berjalan dan ralatn logik.] (i) Compare the differences between syntax and logic errors with related examples. [Bandingkan perbezaan antara ralat sintaks dan ralat logik beserta contoh-contohnya.] (4 Marks/Markah) (ii) Identify the errors in the following program and rewrite the correct program: [Kenalpasti kesalahan-kesalahan dalam aturcara di bawah dan tulis semula aturcara yang betul.] #include <stdio.h> int main ( ) { int x; float sum; x=1; sum =0; while (x<=10); { sum =+ x; ++x;} scanf( The sum is : %d \n, &sum); return 0; -3- Figure 1 [Gambarajah 1] -3- (6 Marks/Markah)

Question A2 [Soalan A2] Instruction F or f B or b R or r L or l Other alphabets Direction Move Forward Move Backward Turn Right Turn Left Invalid movement direction Figure 2 [Gambarajah 2] a) Based on Figure 2, Write a switch statement that display the movement direction of a robot controlled by pressing specific alphabets on device keyboard. [Berdasarkan Gambarajah 2, Tulis penyataan switch yang memaparkan arah pergerakan bagi sebuah robot kawalan dengan menekan huruf-huruf tertentu di atas papan kekunci peranti.] (6 Marks/Markah) b) Modify the program segment in (a) using if..else statement to display the direction. [Ubahsuai program di (a) munggunakan penyataan if..else untuk memaparkan arahan.] (5 Marks/Markah) c) Rewrite program segment in Figure 3 using do-while that will produce the same output. [Tulis semula program dalam Gambarajah 3 munggunakan do-while yang akan menghasilkan keluaran yang sama.] m=5; for(n=1;n<=6;n++) { printf( %d\n, m); m=m + 3; } Figure 3 [Gambarajah 3] (4 Marks/Markah) -4-...4/-

d) Write a complete program containing a loop to display the numbers as in Figure 4. [Tuliskan aturcara lengkap yang mengandungi gegelung untuk memaparkan nombor-nombor seperti dalam Gambarajah 4.] 2 4 6 Figure 8 3b 10 12 14 16 18 [Rajah 3b] Figure 4 [Gambarajah 4] (5 Marks/Markah) -5-

Question A3 [Soalan A3] a) Referring to the sample output shown in Figure 5, write a program to enter marks into one dimensional array, sort the array elements and print the arrays in ascending order. Use the following function prototype: [Merujuk kepada contoh keluaran yang ditunjukkan dalam Gambarajah 5, tulis aturcara untuk memasukkan markah dalam tatasusun satu dimensi, susun elemen tatasusun dan cetak tatasusun dalam urutan menaik. Gunakan fungsi prototaip berikut:] (i) void fillarray (int*, int); (ii)void swaparray(int*, int); (iii) void printarray(int*, int); (3 Marks /Markah) (4 Marks /Markah) (3 Marks /Markah) Enter 5 marks: 40 68 20 35 55 Marks in ascending order: 20 35 40 55 68 Figure 5 [Gambarajah 6] b) Consider the two dimensional array given in Figure 6 below. [Pertimbangkan tatasusun dua dimensi yang diberikan dalam Gambarajah 6 di bawah.] A B C Figure 6 [Gambarajah 6] (i) Write function in C to determine the sum of all the elements in each row of matrix A. [Tulis fungsi dalam C untuk menentukan semua jumlah elemen dalam setiap baris matrik A.] (5 Marks/Markah) (ii) If C is the product of A and B,write function in C to calculate the product of matrix C. [Jika C ialah hasil darap A dan B tulis fungsi dalam C untuk mengira hasil darab matrik C.] (5 Marks/Markah)

-6- Question A4 [Soalan A4] a) Write a single statement to accomplish each of the following statements. Assume that each of these statements applies to the same program : [Tulis satu penyataan untuk mencapai setiap penyataan yang berikut.andaikan bahawa setiap penyataan-penyataan ini boleh digunakan untuk program yang sama:] (i) Open the file trans.dat for reading and assigns the returned file pointer to tfptr. [Buka fail "trans.dat" untuk membaca dan memberikan fail kembali ke penunjuk tfptr.] (ii) Open the file newmast.dat for writing and assigns the returned file pointer to nfptr. [Buka fail "newmast.dat" untuk menulis dan memberikan fail kembali ke penunjuk nfptr.] (iii)read a record from the file trans.dat. The record consists of integer accountnum and floating point dollarammount. [Baca rekod dari fail "trans.dat". Rekod itu terdiri daripada integer accountnum dan apungan dolarammount.] (iv) Write a record to the file newmast.dat.the record consists of the integer accountnum and floating point currentbalance. [Tulis rekod untuk fail "newmast.dat". Rekod terdiri daripada integer accountnum dan apungan currentbalance.] (4 Marks/Markah) b) Figure 7 shows a text file named Number.txt. The text file consists of a number of numerical data. The numerical data are then to perform several operations. The outputs from the operations are kept in an output file named Result.txt. [Gambarajah 7 menunjukkan fail teks bernama "Number.txt. Fail teks ini mengandungi beberapa data nombor. Data nombor ini kemudiannya melaksanakan beberapa operasi. Keluaran daripada operasi-operasi itu disimpan dalam fail keluaran bernama "Result.txt".] 3 11 45 Figure 7 [Gambarajah 7]

-7-...7/- *************** Result ***************** The number of integers is : 3 The sum of the integers is : 59 The average of the integers is : 19.67 ************************************** Figure 8 [Gambarajah 8] Write C statements based on the above problem statements using the following guidelines: [Tulis penyataan C berdasarkan pernyataan masalah di atas menggunakan panduan-panduan berikut:] (i) Show the syntax to open the input file for reading and the output file for writing. [Tunjukkan sintaks untuk buka fail masukan untuk baca dan fail keluaran untuk menulis.] (3 Marks/Markah) (ii) Open input file Number.txt ; exit if file cannot be oppened. [Buka fail input Number.txt; keluar jika fail tidak boleh dibuka.] (2 Marks/Markah) (iii)read input from Number.txt file and perform the operations: count number of integers,calculate sum and average of integers. [Baca masukan daripada Number.txt fail dan lakukan operasi-operasi ini: kira bilangan integer, kira jumlah dan purata bagi integer.] (5Marks/Markah) (iv) Print the output as shown in Figure 8. [Cetak keluaran seperti yang ditunjukkan dalam Gambarajah 8.] (v) Close all files. [Tutup semua fail]. (4 Marks/Markah) (2 Marks/Markah)

Section B (20 marks) [Bahagian B (20 markah)] -8- This section has TWO (2) questions. Answer ONE questions. [Bahagian ini mengandungi DUA (2) soalan. Jawab SATU soalan.] Question B1 [Soalan B1] Write a complete C program to calculate final price after make purchasing at a Shoes Shop in Pauh. Refer to Table 1 for discount percentage and given rebate for different ranges of purchasing. [Tulis satu aturcara C yang lengkap untuk mengira harga akhir selepas membuat pembelian di Kedai Kasut di Pauh. Rujuk Jadual 1 untuk peratus diskaun dan rebat yang diberikan bagi julat pembelian yang berbeza.] Purchase (RM) Discount Rebate Rebate Price (RM) < 30 - No - 30 59 10% No - 60 99 15% Yes 5 >= 100 20% Yes 10 Table 1 [Jadual 1] Formula: Discount = Discount Percent * Price Final Price = Price Discount Rebate The sample output is given in Figure 9 below: [Contok keluaran ditunjukkan dalam Gambarajah 9 di bawah:] Enter the purchased price : RM60 Discount 15% Discount price Rebate earned Final price : RM9.00 : RM5.00 : RM46.00 Figure 9 [Gambarajah 9]...9/-

Your program should include these functions: [Program anda harus merangkumi fungsi-fungsi ini:] -9- (i) getdiscount This function calculates the discount price of purchased items. [getdiscount - Fungsi ini mengira harga diskaun daripada barangan yang dibeli.] (ii)getrebate This function determines whether the buyer get the rebate or not and the value of rebate earned. [getrebate - Fungsi ini menentukan sama ada pembeli mendapatkan rebat atau tidak dan nilai rebat yang diperolehi.] (iii) finalprice This function calculates the final price of the purchased items. [finalprice - Fungsi ini mengira harga akhir barangan yang dibeli.] (iv) printresult This function prints the discount price, rebate earned and final price. [printresult - Fungsi ini mencetak harga diskaun, rebat yang diperolehi dan harga akhir.] (20 Marks/Markah) -10-

Question B2 [Soalan B2] Write a program that prompts the user for two integers and to perform operations given in Table 2. [Tulis satu aturcara yang meminta pengguna untuk memasukkan dua integer dan untuk melaksanakan operasi-operasi yang diberikan dalam Jadual 2.] Letter A or a S or s M or m D or d Operation Add Subtract Multiply Divide Table 2 [Jadual 2] The function main display the menu and stores the user s input in the variables num1, num2 and operator. The main function checks the letter code. If the letter code is A/a, function main calls the function add with arguments num1 and num2 and similarly for S/s, M/m and D/d. Each of the function add, subtract, multiply and divide calls the function print_result of the arithmetic operation. [Fungsi main memaparkan menu dan menyimpan masukan dari pengguna dalam pembolehubah num1, num2 dan operator. Fungsi main memeriksa kod abjad itu. Jika kod abjad itu ialah A / a, fungsi main memanggil fungsi add bersama num1 dan num2 begitu juga untuk S / s, M / m dan D / d. Setiap satu daripada fungsi menambah, menolak, mendarab dan membahagi memanggil fungsi print_result dari operasi aritmetik.] The sample output is given in Figure 10 below: [Contok keluaran ditunjukkan dalam Gambarajah 10 di bawah:] A or a: Add S or s: Subtract M or m: Multiply D or d: Divide Enter num1 : 10 Enter num2: 15 Enter operator : a The result is 25 Thank you Figure 10 [Gambarajah 10] (20 Marks/Markah) -ooooo-