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

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

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

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

MAT181 Programming For Scientific Applications [Pengaturcaraan Untuk Penggunaan Sains]

MSS 317 Coding Theory [Teori Pengekodan]

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

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

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

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

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

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]

CPT111/CPM111 Principles of Programming [Prinsip Pengaturcaraan]

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

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

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

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

UNIVERSITI SAINS MALAYSIA

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

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

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

Pengenalan Sistem Maklumat Dalam Pendidikan

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

UNIVERSITI SAINS MALAYSIA. CST131 Computer Organisation [Organisasi Komputer]

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

EEE 428 SISTEM KOMPUTER

EEE 348 PENGANTAR REKABENTUK LITAR BERSEPADU

UNIVERSITI SAINS MALAYSIA. CPT103 Struktur Data & Paradigma Pengaturcaraan

MULTIMEDIA COLLEGE JALAN GURNEY KIRI KUALA LUMPUR

UNIVERSITI SAINS MALAYSIA. CST131 Computer Organisation [Organisasi Komputer]

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

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

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

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

UNIVERSITI SAINS MALAYSIA. CPT101 Prinsip-Prinsip Pengaturcaraan

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

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

PANDUAN PENGGUNA (PENSYARAH)

UNIVERSITI SAINS MALAYSIA. CPT101 Prinsip-Prinsip Pengaturcaraan

MULTIMEDIA COLLEGE JALAN GURNEY KIRI KUALA LUMPUR

PANDUAN PENGGUNA (SUPPLIER) e-purchase ORDER FOR SERVICES

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

CCS592 Advanced Algorithms and Complexity [Algoritma Lanjutan & Kekompleksan]

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

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

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

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

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

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

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

MULTIMEDIA COLLEGE JALAN GURNEY KIRI KUALA LUMPUR

DOKUMEN TIDAK TERKAWAL

Registration of Supplier (ROS) TM Supplier Registration Renewal via SUS Portal (Pembaharuan Pendaftaran Pembekal TM melalui SUS Portal)

KOLEJ MULTIMEDIA JALAN GURNEY KIRI KUALA LUMPUR

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

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

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 FOUR (4) structured questions. Answer ALL questions.

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

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

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

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

UNIVERSITI SAINS MALAYSIA. CST234 Network Programming [Pengaturcaraan Rangkaian]

LAB 5: WORKING WITH DATA

Manual Pengguna. PCN Online Service Fulfillment System

MICROSOFT EXCEL. Membina Hamparan Elektronik Fungsi Hamparan Elektronik

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

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

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

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

EEM 312 ROBOTIK & PENGLIHATAN MESIN

Registration of Supplier (ROS) TM Supplier Registration Renewal via SUS Portal (Pembaharuan Pendaftaran Pembekal TM melalui SUS Portal)

TS2963 : Pangkalan Data. Nota Makmal. Makmal 4

UNIVERSITI SAINS MALAYSIA. CPT341 Software Design & Architecture [Reka Bentuk & Seni Bina Perisian]

UNIVERSITI MALAYSIA SARAWAK KOTA SAMARAHAN SARAWAK

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

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

Panduan Pengguna Autodesk Education Community

Panduan Guru Maker UNO/ Arduino

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

UNIVERSITI SAINS MALAYSIA EEE 355 ROBOT DAN PENGAUTOMATAN

CST432 Microprocessors & Embedded Systems [Mikropemproses & Sistem Terbenam]

UNIVERSITI SAINS MALAYSIA. CIT502 Pengaturcaraan dan Kejuruteraan Perisian Berorientasi Objek

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

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

Lab 4 : Sorting Techniques

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

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

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

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

TEKNOLOGI, GADJET & KEIBUBAPAAN

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

Panduan Menggunakan Autoresponder FreeAutobot.com

REGISTRATION GUIDE MCIS CUSTOMER PORTAL. Page 1

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

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

Transcription:

UNIVERSITI SAINS MALAYSIA Second Semester Examination 2009/2010 Academic Session April/May 2010 MAT 181 Programming For Scientific Applications [Pengaturcaraan Untuk Penggunaan Sains] Duration : 3 hours [Masa : 3 jam] Please check that this examination paper consists of FIFTEEN [15] pages of printed material before you begin the examination. [Sila pastikan bahawa kertas peperiksaan ini mengandungi LIMA BELAS [15] muka surat yang bercetak sebelum anda memulakan peperiksaan ini.] Instructions: Answer all TWENTY [20] questions in Section I using the objective answer paper (OMR answer paper) provided. For this section, answers should be written in pencil only. The OMR answer paper together with the question paper of Section I will be collected 1½ hours after the examination starts. Answer all THREE [3] questions in Section II. All answers in this section must be written on the answer script papers provided. [Arahan: Jawab semua DUA PULUH [20] soalan dalam Bahagian I dengan menggunakan kertas jawapan soalan objektif (kertas jawapan OMR) yang disediakan. Bagi bahagian ini, jawapan perlu dituliskan dengan pensel sahaja. Kertas jawapan OMR ini berserta kertas soalan Bahagian I akan dikutip 1½ jam setelah peperiksaan bermula. Jawab semua TIGA [3] soalan dalam Bahagian II. Semua jawapan dalam bahagian ini 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.] 2/-

2 [MAT 181] SECTION I (100 points) Choose one answer only for each question. BAHAGIAN I (100 markah) Pilih hanya satu jawapan untuk setiap soalan. 1. Which of the following is not a valid character constant in C++? Yang manakah di antara berikut bukan aksara malar yang sah dalam C++? A. ''' B. '$' C. '1' D. '\n' E. All of the above are valid character constants in C++. Semua yang disebut di atas adalah aksara malar yang sah dalam C++. 2. Which of the following is not a valid C++ statement? Yang manakah di antara berikut adalah pernyataan C++ yang tidak sah? A. float abc; B. cin >> 'A'; C. cout << ' '; D. 2 + 3 == 5; E. All of the above are not valid. Semua yang disebut di atas tidak sah. 3. Which of the following string initializations is done correctly? Yang manakah di antara pengawalan rentetan berikut dilakukan dengan betul? A. char Color[6] = "green"; B. char Car[ ] = "Proton"; C. char Pet[ ] = 'B', 'I', 'R', 'D', '\0'; D. char Name[5] = 'm', 'a', 'r', 'y', '\0'; E. All of the above. Semua yang disebut di atas....3/-

4. Count the number of syntax errors in the following program. Kira bilangan ralat sintaks dalam program berikut. #include <iostream.h> void main() int a = 2, b = 3; float c; c = a/(float) b cout << " a/b = " >> c; 3 [MAT 181] A. 0 B. 1 C. 2 D. 3 E. 4 5. Based upon the following function prototype Calc and variables declarations, Berdasarkan prototaip fungsi Calc dan pengisytiharan pembolehubah berikut, int Calc (int* a, int* b); int i = 2, j = 4, *pi = &i, *pj = &j; which of the following calls to Calc is not valid? yang manakah di antara panggilan Calc berikut adalah tidak sah? A. j = Calc(pi,&j); B. j = Calc(&i,pj); C. j = Calc(&i,&j); D. j = Calc(pi,pj); E. All of the above are valid. Semua yang disebut di atas adalah sah. 6. What will be printed by the following statement? Apakah yang akan dicetak oleh pernyataan berikut? cout << setiosflags(ios::showpos) << setw(2) << setfill('#') << "S" << setiosflags(ios::left) << "A" << 21; A. #SA#+21 B. #SA +21 C. #SA+21 D. #SA21 E. None of the above....4/-

7. Based upon the following struct definition, Berdasarkan definisi struct berikut, struct TYPE char color; int code[10]; ; 4 [MAT 181] which of the following statements is not valid? yang manakah di antara pernyataan-pernyataan berikut adalah tidak sah? A. TYPE f1; B. TYPE f2[20]; C. TYPE f3; f3.color = 'B'; D. TYPE f4; f4.code = 12345; E. All of the above are valid. Semua yang disebut di atas adalah sah. 8. Which of the following produces the value 0 (zero)? Yang manakah di antara berikut menghasilkan nilai 0 (sifar)? A. 7 9!= 2 B. 7 == 6!= 10 C. 50 > 100 < 1 D. 4 && 5 * 4 > 6 * 4-2 E. 6 * 10 + 1 >!(6 + 1 * 10) 9. Find the value of a[3]if the following program segment is executed. Cari nilai a[3] jika segmen program berikut dilaksanakan. int a[5] = 0,1,2,3,4; for(int k=0; k<4; k++) a[k++]+= k; A. 3 B. 4 C. 6 D. 7 E. 8...5/-

10. Consider the following declaration and initializations. Pertimbangkan pengisytiharan dan pengawalan berikut. int a1 = 22, a2 = 66; int *pt1 = &a1, *pt2 = &a2; 5 [MAT 181] Which of the following statements will swap the values between a1 and a2? Yang manakah antara pernyataan-pernyataan berikut akan menukar nilai antara a1 dan a2? A. *pt2=*pt1; *pt1=*pt2; B. *pt1= a2; *pt2= a1; C. a1 = *pt2; *pt1 = a2; D. All of the above. Semua yang disebut di atas. E. None of the above. 11. Consider the following declarations and initializations. Pertimbangkan pengisytiharan dan pengawalan berikut. const int SIZE = 5; int a[size] = 2,5,9,4,6; Which of the following statements will print the value 4? Yang manakah di antara pernyataan-pernyataan berikut akan mencetak nilai 4? A. cout << *(a+4); B. cout << *a+2; C. int *k; k = a - (1-SIZE); cout << *k; D. All of the above. Semua yang disebut di atas. E. None of the above....6/-

6 [MAT 181] 12. Consider the following flowchart. Pertimbangkan carta-alir berikut. m = 0 n = 0 T m < 3 F T m==n F n++ m++ Which of the following program segments cannot be represented by the flow chart. Yang manakah di antara segmen-segmen program berikut tidak boleh diwakili oleh carta-alir tersebut? A. m = 0; n = 0; while(m<3) if(m==n) n++; else m++; B. n = 0; for(m = 0; m<3; ) (m==n? n++ : m++); C. n = 0; for(m = 0; m<3; ) switch(m==n) case 0: m++; break; case 1: n++; break;...7/-

7 [MAT 181] D. m = 0; n = 0; rpt: if(m<3) if(m==n) n++; else m++; goto rpt; E. All of the above can be represented by the flow chart. Semua yang disebut di atas boleh diwakili oleh carta-alir tersebut. 13. Given that ans = 1 initially and n>k, find the program segment that correctly computes the value of ans = k!(n-k)! Diberikan bahawa ans = 1 pada awalnya dan n>k, cari segmen program yang mengira dengan betul nilai ans = k!(n-k)! A. for (i = 1; i<=k; i++) for (j = 1; j<=(n-k); j++) ans = i*j; B. for (i = 1; i<=k; i++) for (j = 1; j<=(n-k); j++) ans *= i; ans *= j; C. for (i = 1; i<=k; i++) for (j = 1; j<=(n-k); j++) ans *= i; ans *= j; D. for (i = 1; i<=k; i++) ans *= i; for (j = 1; j<=(n-k); j++) ans *= j; E. None of the above....8/-

8 [MAT 181] 14. Which of the following loops will produce the value i = 3 after execution? Yang manakah di antara gelung-gelung berikut akan menghasilkan nilai i = 3 selepas pelaksanaan? A. int i=1; do i++; while(i<=3); B. int i=0; while(i<=3) i++; C. int i=0; for(int j=3; j>0; j--) i++; D. int i=1; for(int j=1; j<=3; j++) i++; E. for(int i=1; i<=3; ) i++; 15. Find the output of the following program segment. Cari output segmen program berikut. int a = 0; do if(a < 1) cout << ++a; else if (a++ < 2) cout << 2*++a; else if (a++ < 3) cout << 3*++a; else cout << 4*++a; while(a < 5); A. 1420 B. 1616 C. 1624 D. 1628 E. None of the above....9/-

9 [MAT 181] 16. If the file input.txt contains the data 10 20 30 initially, find the content of the file when the following program segment is executed once. Jika fail input.txt mengandungi data 10 20 30 pada awalnya, cari kandungan fail tersebut apabila segmen program berikut dilaksanakan sekali. fstream file; int data; for(int i=0; i<3; i++) file.open("input.txt", ios::in); file >> data; file.close(); file.open("input.txt", ios::out ios::app); file << " " << data; file.close(); A. 10 20 30 B. 10 20 30 10 20 30 C. 10 20 30 10 10 10 D. The execution will result in an infinite loop. Pelaksanaan tersebut akan menghasilkan gelung tak terhingga. E. None of the above. 17. Find the output of the following program segment. Cari output segmen program berikut. for(int j=0; j<4; j++) for(int i=0; i<3; i++) if(i<=j) continue; else break; cout << "*"; A. *** B. **** C. ***** D. ****** E. *******...10/-

10 [MAT 181] 18. Consider the following program. Pertimbangkan program berikut. #include <iostream.h> void F(int x, int y) y+=x; x+=y; cout << x << y; void main() int a[4] = 1,2,2,1; int *ptr; for(ptr=a; ptr<a+4; ptr++) F(*ptr, *ptr++); What is the output printed on the screen? Apakah output yang dicetak pada skrin? A. 5343 B. 5385 C. 3534 D. 3435 E. None of the above. 19. What is the output of the following program? Apakah output program berikut? #include <iostream.h> int F(int a, int b, int c) if(b==c) return a; else return c + F(a,b+1,c); void main() cout << F(0,2,4); A. 4 B. 8 C. 12 D. 16 E. 20...11/-

11 [MAT 181] 20. Which of the following program segments will print AOBB? Yang manakah di antara segmen program berikut akan mencetak AOBB? A. for(int index=0; index<3; index++) (index? cout << "A" : cout << "O"); cout << "B"; B. int kes = 0; cout << "A"; if(!kes) goto out; cout << "B"; out: cout << "O"; cout << "AB"; C. for(int index=0; index<4; index++) switch(index) case 1: cout << "A"; break; case 2: cout << "O"; break; case 3: cout << "B"; break; default: cout << "A"; D. for(int index=1; index<4; index++) switch(index) case 1: cout << "A"; switch(index++) case 1: cout<< "O"; case 2: cout << "B"; break; case 2: cout << "O"; switch(index++) case 1: cout<< "A"; case 2: cout << "B"; break; case 3: cout << "B"; switch(index++) case 1: cout<< "O"; case 2: cout << "A"; E. None of the above....12/-

12 [MAT 181] SECTION II (100 points) BAHAGIAN II (100 markah) 1. Write a C++ program that reads a student grade from the screen/keyboard. The program should then use the input grade as a search key to look for the list of students with matching grade in a text file (file.txt). Each record of the student data in the text file consists of matric number and grade. Print the list of matric numbers for students whose grades match the search key value and the number of students with grades A, B, C, D and F on the screen. Do not use array in the program. An example of the text file (file.txt) is as follows. 66756 A 78954 B 64528 A 88756 C 56700 D 59576 F 87412 A 76532 B 63849 A 93769 A 79475 C 73645 B 67355 A If the input grade (i.e. the search key) is A, the input/output screen produced should be displayed as follows. Underlined and bold item is user input. Enter grade (search key): A The matric number of students with grade A: 66756 64528 87412 63849 93769 67355 Number of students with grade A: 6 Number of students with grade B: 3 Number of students with grade C: 2 Number of students with grade D: 1 Number of students with grade F: 1...13/-

13 [MAT 181] 1. Tulis satu program C++ yang membaca satu gred pelajar dari skrin/papan kekunci. Kemudian, program tersebut harus menggunakan gred input tersebut sebagai kunci pencarian untuk mencari senarai pelajar dengan gred yang sama dengan kunci pencarian tersebut dalam satu fail teks (file.txt). Setiap rekod data pelajar dalam fail teks tersebut terdiri daripada nombor matriks dan gred. Cetak senarai nombor matriks untuk pelajar yang mempunyai gred yang sama dengan kunci pencarian dan bilangan pelajar dengan gred A, B, C, D and F pada skrin. Jangan menggunakan tatasusunan dalam program tersebut. Satu contoh fail teks (file.txt) adalah seperti berikut. 66756 A 78954 B 64528 A 88756 C 56700 D 59576 F 87412 A 76532 B 63849 A 93769 A 79475 C 73645 B 67355 A Jika gred input (iaitu kunci pencarian) ialah A, skrin input/output yang terhasil harus dipaparkan seperti berikut. Perkara yang digariskan dan dihitamkan ialah input pengguna. Enter grade (search key): A The matric number of students with grade A: 66756 64528 87412 63849 93769 67355 Number of students with grade A: 6 Number of students with grade B: 3 Number of students with grade C: 2 Number of students with grade D: 1 Number of students with grade F: 1...14/-

14 [MAT 181] 2. Write a C++ program that computes the result of an arithmetic problem specified by the user. The arithmetic problem involves addition (+), subtraction (-), multiplication (*) or division (/) of two values. The main program should read as user input, two values and an operator denoting the operation to be performed on these two values. Use a function float Arithmetic (float value1, float value2, char oprator) to calculate the result of that arithmetic problem. The result calculated by the function Arithmetic should then be displayed by the main program. An example of the input/output screen is as shown below. Underlined and bold items are user input. Usage of global variables is not allowed. Tulis satu program C++ yang mengira hasil pengiraan suatu masalah aritmetik yang ditentukan oleh pengguna. Masalah aritmetik tersebut melibatkan penambahan (+), penolakan (-), pendaraban (*) atau pembahagian (/) dua nilai. Program main harus membaca sebagai input pengguna dua nilai dan satu operator yang menentukan operasi yang hendak dijalankan dengan dua nilai tersebut. Gunakan fungsi float Arithmetic (float value1, float value2, char oprator) untuk mengira hasil pengiraan masalah aritmetik tersebut. Kemudian, hasil pengiraan fungsi Arithmetic harus dipaparkan oleh program main. Suatu contoh skrin input/output ditunjukkan di bawah. Perkara yang digariskan dan dihitamkan ialah input pengguna. Penggunaan pembolehubah global tidak dibenarkan. Enter two values: 58.2 27.5 Enter an arithmetic operator: + Result: 58.2 + 27.5 = 85.7 Do you want to continue? Type 'y' for yes and 'n' for no: y Enter two values: 21.5 6 Enter an arithmetic operator: * Result: 21.5 * 6 = 129 Do you want to continue? Type 'y' for yes and 'n' for no: n...15/-

15 [MAT 181] 3. Write a C++ program that reads a singular noun in English as an input from the user and then display the plural form of the singular noun. Use the following rules to form the plural of the singular noun: a. If a singular noun ends in y, remove the y and add ies ; (E.g. family becomes families) b. If a singular noun ends in s, o, x, z, ch or sh, add es ; (E.g. tax becomes taxes) c. If all other cases, add s. (E.g. computer becomes computers) An example of the input/output screen is as shown below. Underlined and bold item is user input. Enter a noun: lunch The plural form of lunch is lunches. 3. Tulis satu program C++ yang membaca satu kata nama tunggal dalam bahasa Inggeris sebagai input daripada pengguna dan kemudian memaparkan kata nama majmuk untuk kata nama tunggal tersebut. Gunakan peraturan berikut untuk mendapatkan kata nama majmuk untuk kata nama tunggal tersebut: a. Jika suatu kata nama tunggal berakhir dengan y, keluarkan y dan tambahkan ies ; (Cth. family menjadi families) b. Jika suatu kata nama tunggal berakhir dengan s, o, x, z, ch atau sh, tambahkan es ; (Cth. tax menjadi taxes) c. Jika kes-kes lain, tambahkan s. (Cth. computer menjadi computers) Suatu contoh skrin input/output ditunjukkan di bawah. Perkara yang digariskan dan dihitamkan ialah input pengguna. Enter a noun: lunch The plural form of lunch is lunches. - ooo O ooo -...16/-