MAT181 Programming For Scientific Applications [Pengaturcaraan Untuk Penggunaan Sains]

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

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

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

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

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

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

UNIVERSITI SAINS MALAYSIA

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

MSS 317 Coding Theory [Teori Pengekodan]

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

CPT111/CPM111 Principles of Programming [Prinsip Pengaturcaraan]

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

UNIVERSITI SAINS MALAYSIA. CST232 Operating Systems [Sistem Pengendalian]

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

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

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

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

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

UNIVERSITI SAINS MALAYSIA. CST131 Computer Organisation [Organisasi Komputer]

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

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

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

UNIVERSITI SAINS MALAYSIA. CST131 Computer Organisation [Organisasi Komputer]

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

MSS 318 Discrete Mathematics [Matematik Diskret]

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

UNIVERSITI SAINS MALAYSIA. CST131 Computer Organisation [Organisasi Komputer]

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

UNIVERSITI SAINS MALAYSIA. CPT101 Prinsip-Prinsip Pengaturcaraan

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

UNIVERSITI SAINS MALAYSIA. CPT101 Prinsip-Prinsip Pengaturcaraan

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

UNIVERSITI SAINS MALAYSIA. CPT103 Struktur Data & Paradigma Pengaturcaraan

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

EEE 428 SISTEM KOMPUTER

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

UNIVERSITI SAINS MALAYSIA. CPT101 Prinsip-Prinsip Pengaturcaraan

EEE 348 PENGANTAR REKABENTUK LITAR BERSEPADU

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

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

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

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

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

BORANG PENCALONAN HADIAH UNIVERSITI NOMINATION FORM FOR UNIVERSITY AWARD

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

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

PANDUAN PENGGUNA (SUPPLIER) e-purchase ORDER FOR SERVICES

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

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

MULTIMEDIA COLLEGE JALAN GURNEY KIRI KUALA LUMPUR

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

Panduan Pengguna Autodesk Education Community

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

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

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

MULTIMEDIA COLLEGE JALAN GURNEY KIRI KUALA LUMPUR

Pengenalan Sistem Maklumat Dalam Pendidikan

KOLEJ MULTIMEDIA JALAN GURNEY KIRI KUALA LUMPUR

CREATING USER ID AND PASSWORD : NOTA PENTING NOTA PENTING SEBELUM MEMULAKAN PROSES CREATE USER ID & PASSWORD

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

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

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

FIRST TIME LOGIN & SELF REGISTRATION USER GUIDE LOG MASUK KALI PERTAMA & PENDAFTARAN SENDIRI PANDUAN PENGGUNA

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

EEM 312 ROBOTIK & PENGLIHATAN MESIN

UNIVERSITI SAINS MALAYSIA. CST234 Network Programming [Pengaturcaraan Rangkaian]

CCS592 Advanced Algorithms and Complexity [Algoritma Lanjutan & Kekompleksan]

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

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

Lab 4 : Sorting Techniques

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

Panduan Menggunakan Autoresponder FreeAutobot.com

UNIVERSITI SAINS MALAYSIA. CST432 Microprocessors & Embedded Systems [Mikropemproses & Sistem Terbenam]

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

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

MICROSOFT EXCEL. Membina Hamparan Elektronik Fungsi Hamparan Elektronik

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

YAYASAN KUOK BERHAD Arahan Permohonan

MULTIMEDIA COLLEGE JALAN GURNEY KIRI KUALA LUMPUR

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

UNIVERSITI SAINS MALAYSIA. CPT212 Design & Analysis of Algorithms [Reka Bentuk & Analisis Algoritma]

DOKUMEN TIDAK TERKAWAL

UNIVERSITI SAINS MALAYSIA. CST231/CSM331 Data Communications & Networks [Komunikasi Data & Rangkaian]

Manual Pengguna. PCN Online Service Fulfillment System

UNIVERSITI SAINS MALAYSIA. CCS523 Computer Security & Cryptography [Keselamatan Komputer & Kriptografi]

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

CST432 Microprocessors & Embedded Systems [Mikropemproses & Sistem Terbenam]

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

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

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

M2U MANUAL PENGGUNA USER MANUAL M2UNHJ. 0 P a g e BAHAGIAN SIMPANAN DAN PENGELUARAN JABATAN KHIDMAT PENDEPOSIT DAN OPERASI LEMBAGA TABUNG HAJI

UNIVERSITI SAINS MALAYSIA. CMT224/CMM221 Multimedia Systems [Sistem Multimedia]

Visitor Management System

UNIVERSITI MALAYSIA SARAWAK KOTA SAMARAHAN SARAWAK

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

PENGENALAN KEPADA ALGORITMA & STRUKTUR DATA

Panduan Guru Maker UNO/ Arduino

PANDUAN PENGGUNA (SUPPLIER) SINGLE ENVELOPE TENDER

CIRCULAR 2017/02. Dear Valued Members, Warmest greetings from Sara Worldwide Vacations Berhad!

UNIVERSITI SAINS MALAYSIA EEE 355 ROBOT DAN PENGAUTOMATAN

Transcription:

UNIVERSITI SAINS MALAYSIA Second Semester Examination 016/017 Academic Session June 017 MAT181 Programming For Scientific Applications [Pengaturcaraan Untuk Penggunaan Sains] Duration : 3 hours [Masa : 3 jam] Please check that this examination paper consists of EIGHT pages of printed material before you begin the examination. [Sila pastikan bahawa kertas peperiksaan ini mengandungi LAPAN muka surat yang bercetak sebelum anda memulakan peperiksaan ini.] Instructions: Answer all FOUR (4) questions. All answers must be written on the answer script papers provided. [Arahan: Jawab semua EMPAT (4) soalan. Semua jawapan mestilah dituliskan pada kertas skrip jawapan yang disediakan.] In the event of any discrepancies, the English version shall be used. [Sekiranya terdapat sebarang percanggahan pada soalan peperiksaan, versi Bahasa Inggeris hendaklah diguna pakai.] /-

Question 1 - - (a) Write the following algebraic expressions as C++ assignment statements. Assume that all variables are declared correctly and necessary header files are already included. a (i) A a/ 4.5 b5.0 (ii) w 5 4ac z x y x y (b) Given the following declarations: int a, b, c; double d, e, f, g, x, y, z; and the current values of each variable are as follows: a = -10,b = 5,c = 3,d=5.5,e=3.75,f=14.8, g=1.0; x =.3, y = 8.5, z = 1.6; What is the output of each of the following statements in the ordering as shown? cout << (a%(int)e - f ); cout << endl << (pow (d, c%abs(a++))); cout << endl << (a/b + 1/c); cout << endl << (g += 1.5 * 3 + ++g); cout << endl << (z < y+x z - 15 < x*y); (c) Combine the following four if statements to produce only ONE nested if else statement without compound conditions (i.e. conditions without the && operator) if ((ch == 'F') && (pay > 1000)) x + = 1; if ((ch == 'F') && (pay <= 1000)) x + = ; if ((ch == 'M') && (pay > 1000)) x + = 3; if ((ch == 'M') && (pay <= 1000)) x + = 5; (d) Refer to the following program segment for parts (i), (ii) and (iii). : #define SIZE 100 void main() { int V[SIZE]; void Read_in(...); void Sort(...); void Repeating(...); // For question (1)(d)(i) // For question (1)(d)(ii) // For question (1)(d)(iii)...3/-

- 3 - } Read_in(...); Sort(...); Repeating(...); // function definitions : (i) (ii) Write the function definition Read_in which reads in 100 values to the array V[] from a text file called input.txt. The file needs to be processed according to the complete file processing steps; declaration of file, opening of file, verification of file, closing of file, etc. must be within this function. Write the function definition Sort which sorts V[] according to the bubble sort algorithm and prints the sorted values on the screen in descending order. (iii) Write the function definition Repeating which determines whether there are repeated values in the array. If there are, the function should return the value 1. If not, the function should return the value 0. This value should be returned via reference parameter. The execution of this function should be terminated when the first repeated value is encountered. Soalan 1 (a) Tulis ungkapan-ungkapan aljabar berikut sebagai pernyataan umpukan C++. Anggapkan semua pembolehubah telah diisytiharkan dengan betul dan semua fail pengepala yang diperlukan telahpun disertakan. a i. A a/ 4.5 b5.0 ii. w 5 4ac z x y x y (b) Diberi pengisytiharan-pengisytiharan berikut: int a, b, c; double d, e, f, g, x, y, z; dan nilai-nilai terkini bagi setiap pembolehubah adalah seperti berikut: a = -10,b = 5,c = 3,d=5.5,e=3.75,f=14.8, g=1.0; x =.3, y = 8.5, z = 1.6; Apakah output bagi setiap pernyataan berikut mengikut tertib yang ditunjukkan? cout << (a%(int)e - f ); cout << endl << (pow (d, c%abs(a++))); cout << endl << (a/b + 1/c); cout << endl << (g += 1.5 * 3 + ++g); cout << endl << (z < y+x z - 15 < x*y);...4/-

(c) - 4 - Gabungkan empat pernyataan if berikut untuk menghasilkan hanya SATU pernyataan if else tersarang tanpa syarat-syarat kompaun (i.e. syarat-syarat tanpa operator &&) if ((ch == 'F') && (pay > 1000)) x + = 1; if ((ch == 'F') && (pay <= 1000)) x + = ; if ((ch == 'M') && (pay > 1000)) x + = 3; if ((ch == 'M') && (pay <= 1000)) x + = 5; (d) Rujuk kepada segmen program berikut bagi bahagian (i), (ii) dan (iii). : #define SIZE 100 void main() { int V[SIZE]; void Read_in(...); void Sort(...); void Repeating(...); // Bagi soalan (1)(d)(i) // Bagi soalan (1)(d)(ii) // Bagi soalan (1)(d)(iii) } Read_in(...); Sort(...); Repeating(...); // definisi fungsi : (i) (ii) Tulis definisi fungsi Read_in yang membaca 100 nilai kepada tatasusunan V[] dari satu fail teks bernama input.txt. Fail ini perlu diproses mengikut langkah-langkah pemprosesan fail lengkap; pengisytiharan fail, pembukaan fail, pengesahan fail, penutupan fail, dsb, perlu dibuat dalam fungsi ini. Tulis definisi fungsi Sort yang mengisih V[] mengikut algoritma isih buih dan mencetak nilai-nilai diisih itu pada skrin dalam tertib menurun. (iii) Tulis definisi fungsi Repeating yang menentukan sama ada terdapat nilainilai berulang dalam tatasusunan tersebut. Sekiranya ada, fungsi ini perlu mengembalikan nilai 1. Sekiranya tiada, fungsi ini perlu mengembalikan nilai 0. Nilai ini perlulah dikembalikan melalui parameter rujukan. Pelaksanaan fungsi ini perlu dihentikan apabila nilai berulang pertama ditemui. Question Write a complete C++ program to compute the value p m i1 i n j j....5/-

- 5 - Note: 3 i1 m i = 1 + + 3 6, while j j = x3x4x5x6. Let A =i and B = j. Your program must consist of the following functions: i1 n j i) void main() to input the values of m and n and send them to the respective functions. ii) int Add(int m) to receive the value of m from the main() function and compute the value of A. This value must be returned to main() via the function name. iii) void Multiply(int n, int *B) to receive the value of n from main() and compute the value of B. This value must be returned to main() via a pointer. iv) void Add_Print( )- to receive the values of A and B from main() and add these numbers and prints the sum p with appropriate messages Soalan Tulis satu program C++ yang mengira nilai Nota: 3 i1 p m i1 i n j 6 i = 1 + + 3, manakala j m j. j = x3x4x5x6. Biarkan A =i manakala B = j. Program anda perlu mengandungi fungsi-fungsi i1 n j berikut: i) void main() untuk menginput nilai-nilai m dan n serta menghantar mereka kepada fungsi-fungsi masing-masing. ii) int Add(int m) untuk menerima nilai m dari fungsi main() dan mengira nilai A. Nilai ini perlu dikembalikan kepada main() melalui nama fungsi. iii) void Multiply(int n, int *B) untuk menerima nilai n dari main() dan mengira nilai B. Nilai ini perlu dikembalikan kepada main() melalui penuding. iv) void Add_Print( )- untuk menerima nilai-nilai A dan B dari main() dan jumlahkan mereka serta mencetak hasiltambah p dengan mesej yang bersesuaian. Question 3 (a) Consider the following declarations and assignment statements: int num=100, iarray[6]={10,15,30,-10,-15,-30}; int *ptr_num, *ptr_i; ptr_i = iarray + ; ptr_num = &num;...6/-

- 6 - Based on these statements, state whether the following expressions are TRUE, FALSE or ILLEGAL. Assume that the starting address of array iarray[] is 00AFE0, and the data of type int occupies 4 bytes of memory space. (i) num == *ptr_num (ii) num == &ptr_num (iii) ptr_num == *num (iv) ptr_i == &iarray[0] (v) iarray[4] == ptr_i + (vi) (ptr_i + 1)== 00AFEC (vii) &*ptr_i == 00AFE8 (viii) &ptr_num == &num (ix) *(iarray + 4) == *ptr_i + (x) *(ptr_i + 1)== -10 (b) A record of 50 students consists of the following information: matric number (6 digits) name (maximum 0 characters) gender ( F or M ) CGPA (e.g..0, 3.5, etc.) marks (e.g. 34.4, 78.6, etc.) Write a C++ declaration of an array of structure for the above record. In addition, write a C++ program segment which initializes all the students marks to 0.0. (c) Consider a two dimensional array which is declared as follows: int Matrix[5][6]; Write a nested for loop that will assign the elements in the array Matrix[][] in the position as displayed in the following rows and columns: 0 5 10 15 0 5 1 6 11 16 1 6 7 1 17 7 3 8 13 18 3 8 4 9 14 19 4 9 (d) What will be printed by the following statement? char char1[0] = "PRST"; char char[10]; char char3[10] = "UVW"; double P = 765.88844; double Q = 9.67457; strcat_s(char1,char3); strncpy_s(char, char1, 6);...7/-

- 7 - cout << setiosflags(ios::left) << setiosflags(ios::fixed)<< setw(10)<< setprecision(4) << setfill('*') << P << setw(10) << char << resetiosflags(ios::left) << setw(1) << Q; Soalan 3 (a) Pertimbangkan pernyataan-pernyataan pengisytiharan dan umpukan berikut: int num=100, iarray[6]={10,15,30,-10,-15,-30}; int *ptr_num, *ptr_i; ptr_i = iarray + ; ptr_num = &num; Berdasarkan pernyataan-pernyataan ini, nyatakan sama ada ungkapan-ungkapan berikut adalah BENAR, SALAH atau TIDAK SAH. Anggapkan alamat mula bagi tatasusunan iarray[] adalah 00AFE0, dan data berjenis int mengisi 4 bait ruang ingatan. (i) num == *ptr_num (ii) num == &ptr_num (iii) ptr_num == *num (iv) ptr_i == &iarray[0] (v) iarray[4] == ptr_i + (vi) (ptr_i + 1)== 00AFEC (vii) &*ptr_i == 00AFE8 (viii) &ptr_num == &num (ix) *(iarray + 4) == *ptr_i + (x) *(ptr_i + 1)== -10 (b) Satu rekod 50 orang pelajar mengandungi maklumat berikut: - nombor matrik (6 digit) - nama (maksimum 0 aksara) - jantina ( F atau M ) - PNGK (e.g..0, 3.5, dsb.) - markah (e.g. 34.4, 78.6, dsb.) Tulis satu pengisytiharan C++ untuk satu tatasusunan struktur bagi rekod di atas. Secara tambahan, tulis satu segmen program C++ yang menilai awalkan semua markah pelajar kepada 0.0. (c) Pertimbangkan tatasusunan dua dimensi yang diisytiharkan seperti berikut: int Matrix[5][6];...8/-

- 8 - Tulis satu gelung for tersarang yang akan mengumpukkan elemen-elemen dalam tatasusunan Matrix[][] pada posisi seperti yang paparkan dalam baris dan lajur berikut: 0 5 10 15 0 5 1 6 11 16 1 6 7 1 17 7 3 8 13 18 3 8 4 9 14 19 4 9 (d) Apakah yang akan dicetak oleh segmen berikut? char char1[0] = "PRST"; char char[10]; char char3[10] = "UVW"; double P = 765.88844; double Q = 9.67457; strcat_s(char1,char3); strncpy_s(char, char1, 6); cout << setiosflags(ios::left) << setiosflags(ios::fixed)<< setw(10)<< setprecision(4) << setfill('*') << P << setw(10) << char << resetiosflags(ios::left) << setw(1) << Q; Question 4 Write a C++ program to enter any positive integer and check whether the number is a Strong number or not. A Strong number is a number whose sum of factorial of digits is equal to the original number. For example, 145 is a Strong number since 1! + 4! + 5! = 145 Examples of Strong numbers: 1,, 145, 40585 Soalan 4 Tulis satu program C++ untuk memasukkan sebarang integer positif dan semak sama ada nombor tersebut satu nombor Strong atau tidak. Nombor Strong ialah nombor yang hasiltambah tertisi digitnya bersamaan dengan nombor yang asal. Contohnya, 145 ialah nombor Strong kerana 1! + 4! + 5! = 145 Contoh nombor-nombor Strong: 1,, 145, 40585 - ooo 0 ooo - (100 marks) (100 markah)...9/-