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

Similar documents
OCBC GREAT EASTERN CO-BRAND CARD FREQUENTLY ASKED QUESTIONS (FAQ) REBATE FEATURES, INTEREST FREE AUTO INSTALMENT PAYMENT PLAN (AUTO-IPP) AND BENEFITS

GARIS PANDUAN PENGENDALIAN DIVIDEN SATU PERINGKAT DALAM LEBIHAN AKTUARI YANG DIPINDAHKAN KEPADA DANA PEMEGANG SAHAM

LIGHTNING AS A NEW RENEWABLE ENERGY SOURCE SARAVANA KUMAR A/L ARPUTHASAMY UNIVERSITI TEKNOLOGI MALAYSIA

KRITERIA BORANG NYATA CUKAI PENDAPATAN (BNCP) TIDAK LENGKAP CRITERIA ON INCOMPLETE INCOME TAX RETURN FORM (ITRF) PEMBERITAHUAN

Kalkulus Fungsi Dua Peubah atau Lebih

NAMA:... Tingkatan :... BAHAGIAN PENGURUSAN SEKOLAH BERASRAMA PENUH DAN SEKOLAH KECEMERLANGAN KEMENTERIAN PELAJARAN MALAYSIA

Page 1 of 1. Page 2 of 2 % &! " '! ( ' ( $) * +, - % -. !" # $

ii) 9 months Plan - Interest Rate at 0.75% per month The minimum transfer amount is RM1,000 and maximum is subject to Cardmember

Student Application Form

Celebrate With PB Cards. Terms and Conditions. 1. The campaign is valid from 1 January 2016 until 30 April 2016 ( Campaign period ).

Student Application Form

JOB AGENT MANAGEMENT SYSTEM LU CHUN LING. A thesis submitted in partial fulfillment of. the requirements for the award of the degree of

PROGRESSIVE INSURANCE BHD (19002-P)

Terms & Conditions Cash Rebate MasterCard

ZERO-INTEREST INSTALMENT PLAN. 1) This programme valid for PB Credit cards issued by Public Bank.

PEMBERIAN WANG TUNAI SEBAGAI GANTIAN BAGI CUTI REHAT YANG TIDAK DAPAT DIHABISKAN OLEH PEGAWAI LANTIKAN SECARA KONTRAK (CONTRACT OF SERVICE)

WEB-BASED PROPERTY MANAGEMENT SYSTEM SAFURA ADEELA BINTI SUKIMAN

Chapter 17 COMPLETION. 1. Receipt of notice from Contractor. 2. Final Inspection. PT

Terms & Conditions Cash Rebate MasterCard

Motor Comprehensive Cover Insurance

TOPIK 1 Konsep Pengukuran dan Skala Pengukuran

Terms & Conditions (Balance Transfer Programme)

PRODUCTIVITY IMPROVEMENT VIA SIMULATION METHOD (MANUFACTURING INDUSTRY) HASBULLAH BIN MAT ISA

Universiti Kuala Lumpur Kampus Kota MALAYSIAN INSTITUTE OF INFORMATION TECHNOLOGY 1016, Jalan Sultan Ismail Kuala Lumpur

(c) the offer is not applicable to kids below 12 years ticket at TGV and Children ticket at GSC;

PRODUCT DISCLOSURE SHEET

FRAMEWORK FOR EVALUATING PROGRAMMING LANGUAGES FOR COMPUTER GRAPHICS

UNIVERSITI TEKNOLOGI MALAYSIA (UTM) SYARAT KEMASUKAN BAGI PROGRAM LEPASAN SPM/SETARAF SESI AKADEMIK 2012/2013

STRESS EFFECT STUDY ON 6 DIFFERENT PATTERN OF TYRES FOR SIZE 175/70 R13 SYAHRIL AZEEM ONG BIN HAJI MALIKI ONG. for the award of the degree of

Maybank One Personal Saver and Flexi Saver Plan

GUIDELINES ON THE STAMPING OF SHARE TRANSFER INSTRUMENTS FOR SHARES THAT ARE NOT QUOTED ON THE KUALA LUMPUR STOCK EXCHANGE.

SPAM FILTERING USING BAYESIAN TECHNIQUE BASED ON INDEPENDENT FEATURE SELECTION MASURAH BINTI MOHAMAD

UNIVERSITI TEKNIKAL MALAYSIA MELAKA FAKULTI TEKNOLOGI MAKLUMAT DAN KOMUNIKASI

SPA BEAUTY MANAGEMENT SYSTEM NAJIHAH BINTI RUSSLI

TRANSFORMATIONAL PROJECT MANAGER: AN ENABLER OF AN ENTERPRISE RESOURCE PLANNING (ERP) IMPLEMENTATION SUCCESS JOHN ONYEKACHI OKUGO

Presented by: FRO Northern

PERATURAN-PERATURAN LEMBAGA PEMBANGUNAN INDUSTRI PEMBINAAN MALAYSIA (PENYAMPAIAN NOTIS) 2015

Maybank 2 Cards Agreement These are the terms & conditions governing the use of your Maybank 2 Cards issued by Maybank Malaysia which is binding on

MODELING AND SIMULATION OF SINGLE PHASE INVERTER WITH PWM USING MATLAB/SIMULINK AZUAN BIN ALIAS

CLIENT SERVER APPLICATION FOR SERVER FARM PERFORMANCE MONITORING ABDIRASHID HASSAN ABDI

Get a Black & Decker Car Vacuum with PB-Petron Visa Gold Credit Card Campaign. Terms and Conditions

BISKUT RAYA INVENTORY MANAGEMENT SYSTEM (BRIMS) NURUL AMIRAH BINTI ROSLAN THESIS SUBMITTED IN FULFILLMENT OF THE DEGREE OF COMPUTER SCIENCE

LEMBAGA HASIL DALAM NEGERI MALAYSIA PERCUKAIAN PEKERJA MALAYSIA YANG DIHANTAR BERTUGAS DI LUAR NEGARA KETETAPAN UMUM NO. 1/2011

Car Rental Management System (CRMS) Lee Chen Yong

REAL TIME SERVER ALERT SYSTEM USING PORT SCANNING AND REACHABILITY TEST FUNCTIONS MUHAMMAD HAFIZ BIN MUHAMAD HENDRI

TERMS AND CONDITIONS CIMB October Spend & Get Cash Back Campaign

UNIVERSITI TEKNOLOGI MALAYSIA (UTM) SYARAT KEMASUKAN BAGI PROGRAM LEPASAN STPM/SETARAF SESI AKADEMIK 2012/2013

Customer Service Charter

Note on the Application Form for the JICA Training and Dialogue Program

TN. MOHD FAKHRUZZAMAN B. TN ISMAIL

How To Get A Free Hotlink Sim Card From Cimb Bank Kwik Kwik

Investment-Linked Takaful Plan Fulfilling your investment and protection needs

LEMBAGA HASIL DALAM NEGERI MALAYSIA

LONPAC INSURANCE BHD ( T)

3. Only PIN based ATM e Debit card transactions are accepted for the Contest.

GARISPANDUAN MENGENAI DUTI SETEM KE ATAS SURATCARA PINDAHMILIK SYER BAGI SYER YANG TIDAK TERSENARAI DI BURSA SAHAM KUALA LUMPUR.

Manpower Planning Utilizing Work Study at Data Storage Manufacturing Company

SUN LIFE MALAYSIA ASSURANCE BERHAD MASTER POLICY GROUP MORTGAGE REDUCING TERM ASSURANCE BUSINESS LOAN

Terms and Conditions for Auto BILLPAY RM30 Cash Rebate Campaign

KEMENTERIAN KEWANGAN MALAYSIA SURAT PEKELILING PERBENDAHARAAN BIL. 3 TAHUN 2008 PELAKSANAAN SYARAT PERUBAHAN HARGA DI DALAM KONTRAK KERJA

LEMBAGA JURUTERA MALAYSIA PENDAFTARAN ENGINEERING CONSULTANCY PRACTICE

SMART SHOES CHARGER TAN CHEE CHIAN

EXPERIMENTAL ANALYSIS OF PASSIVE BANDWIDTH ESTIMATION TOOL FOR MULTIPLE HOP WIRELESS NETWORKS NURUL AMIRAH BINTI ABDULLAH

MOTORCYCLE POLICY TYPES OF COVER ALL ENDORSEMENTS, CLAUSES OR WARRANTIES THAT ARE SEPARATELY ATTACHED TO THIS POLICY SHALL ALSO APPLY.

Al-Ijarah Leasing and Factoring Finance Institution (Schedule Institution) under Section 19(1) Banking and Financial Institution Act (BAFIA) 1989

PRIVATE CAR INSURANCE POLICY

EMPLOYEE ATTENDANCE SYSTEM KOIK SEOW LIN

Motorcycle Insurance. RHB Insurance Berhad

We ensure you are always prepared for unexpected health incidents

MASTER S PROJECT REPORT SUMMARY

AmBank/ AmIslamic Bank Credit Card Acquisition Cash Reward Program Terms and Conditions

Program Mikro Kredit Berasaskan Ar Rahnu. Ar Rahnu-Based Micro Credit Programme

Get 100% Cash Back* on your TNB bill when you pay with your American Express Card

INVENTORY MANAGEMENT SYSTEM USING DISTRIBUTED SYSTEM APPROACH GOH LIRONG

ONLINE RESTAURANT MANAGEMENT SYSTEM (ORMS) HANISAH BINTI MD TAHA

A STUDY ON MOTIVATION TO START UP A BUSINESS AMONG CHINESE ENTREPRENEURS

Program Peralihan Pembantu Makmal (PPPM) WFST1113 ASAS KERJA LAPANGAN KOMPAS, TRIGONOMETRI & MEMBUAT RINTISAN KOMPAS

DEVELOP AND DESIGN SHEMATIC DIAGRAM AND MECHANISM ON ONE SEATER DRAG BUGGY MUHAMMAD IBRAHIM B MD NUJID

UJIAN PENCAPAIAN SEKOLAH RENDAH 2016

KERAJAAN MALAYSIA. Pungutan Hasil Dan Terimaan Bukan Hasil Secara Online

COARSE RESOLUTION DEFECT LOCALIZATION ALGORITHM FOR AN AUTOMATED VISUAL PCB INSPECTION

PRODUCT DISCLOSURE SHEET

AmBank / AmBank Islamic Credit Card Acquisition Apply & Get Cash Programme Terms and Conditions

SULIT /2 MATHEMATICAL FORMULAE RUMUS MATEMATIK

DEVELOPING AN ISP FOR HOTEL INDUSTRY: A CASE STUDY ON PUTRA PALACE HOTEL

01 [pg 3] Set-Top-Box (STB) 02 [pg 5] HyppTV Remote Control. 03 [pg 10] Accessing the TV Guide. 04 [pg 12] Accessing the Video On Demand (VOD)

SWAY REDUCTION ON GANTRY CRANE SYSTEM USING DELAYED FEEDBACK SIGNAL (DFS) NORASHID BIN IDRUS

MOTORCYCLE POLICY TYPES OF COVER OUR AGREEMENT SECTION A - LOSS OR DAMAGE TO YOUR VEHICLE

DEVELOPMENT OF DATA ACQUISITION SOFTWARE FOR CENTRALIZED RADIATION MONITORING SYSTEM

Teori Himpunan. Bagian III

A STUDY OF SECURITY LIMITATIONS IN VIRTUAL LOCAL AREA NETWORK IMPLEMENTATION

IMPLEMENTING CRYPTOGRAPHY IN DATABASE KWAN SHONG HANN

Garis Panduan Pendaftaran dan Pembaharuan Pegawai Keselamatan dan Kesihatan

INTEGRATING CONSUMER TRUST IN BUILDING AN E-COMMERCE WEBSITE NUR ZAILAN BIN OTHMAN

HOME AUTOMATION SYSTEM USING POWER LINE COMMUNICATION DARLENE BINTI MOHAMAD DOUGLAS

OCBC GREAT EASTERN MASTERCARD TERMS AND CONDITIONS

PERATURAN AKADEMIK PROGRAM DIPLOMA DAN SARJANA MUDA SEPENUH MASA

ANT COLONY OPTIMIZATION (ACO) ALGORITHM FOR CNC ROUTE PROBLEM WAN NUR FARHANAR BT WAN ZAKARTA

7.7 Case Study: Calculating Depreciation

Transcription:

UNIVERSITI SAINS MALAYSIA First Semester Examination 2010/2011 Academic Session November 2010 CPT111 Principles of Programming [Prinsip Pengaturcaraan] Duration : 2 hours [Masa : 2 jam] INSTRUCTIONS TO CANDIDATE: [ARAHAN KEPADA CALON:] Please ensure that this examination paper contains FOUR questions in FIFTEEN printed pages before you begin the examination. [Sila pastikan bahawa kertas peperiksaan ini mengandungi EMPAT soalan di dalam LIMA BELAS muka surat yang bercetak sebelum anda memulakan peperiksaan ini.] Answer ALL questions. [Jawab SEMUA soalan.] You may answer the questions either in English or in Bahasa Malaysia. [Anda dibenarkan menjawab soalan sama ada dalam bahasa Inggeris atau bahasa Malaysia.] 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-1. (a) State whether each of the following is TRUE or FALSE. (i) During a program execution, the content of a constant variable can be changed. A char variable cannot be used in an arithmetic expression. (iii) The arithmetic operators *, /, + and all have the same level of precedence. (iv) The continue statement can be used to terminate a loop. (v) The expression in a switch statement can be a logical expression. (vi) To use manipulator setprecision, setw, and setfill, the program must include the file iomanip. (6/100) (b) A parking garage charges a $2.00 minimum fee to park for up to three hours. The garage charges an additional $0.50 per hour for each hour additional. The maximum charge for any given 24-hour period is $10.00. Assume that no car parks for longer than 24 hours at a time. Write a function calculatecharge to determine the charge for each user. (7/100) (c) What is the output of the following program segments? (i) int x = 72; if (x > 10) if ((x < 100) (x > 50)) cout << x << endl; if ((x < 100) && (x > 50)) cout << x + 1; cout << x * x; int x = 5; do cout << x << endl; x = x + 2; while (x!= 10); cout << x << endl;...3/-

- 3 - (iii) #include <iostream> using namespace std; int main() char c; c = 'A'; //the ASCII value is 65 while (c <= 80) cout << c; c += 5; (9/100) (d) A binomial coefficient is computed by using the following formula. c(n, k) = n! (n - k)!k! where n n! = i = 1 * 2 * 3... * n i=1 4 example: 4! = i = 1 * 2 * 3 * 4 i=1 (i) Write a for statement to calculate n! (factorial). Write a C++ program that calculates the binomial coefficient. (4/100) (8/100) 2. (a) (i) Convert the following C++ code segment into a post-test loop. int number; cout << "Enter an odd number:"; cin >> number; while (number %7 == 0) cout << "Enter an odd number divisible by 7 again"; cin >> number;...4/-

- 4 - Convert the following if- statement into a switch statement. int age; if ((age > 0) && (age <= 2) cout << "This is a baby" << endl; if (age > 2) && (age <= 4) cout << "This is a toddler" << endl; if (age > 4) && (age <= 6) cout << "This is a child" << endl; cout << "You are not a child anymore" << endl; (4/100) (b) Find the syntax and/or semantics error(s) in each of the following code segments and explain how to correct them. (i) x = 1 while (x <= 10); x++; for (y =.1; y!= 1.0; y +=.1) cout << y << endl; switch (n) case 1: cout << "The number is 1" << endl; case 2: cout << "The number is 2: << endl; break; default: cout << "The number is not 1 or 2" << endl; break int x = 1, total; while (x <= 10) total += x; ++x; (iii) if (gender == 1) cout << "Woman" << endl; cin >> gender; cout << "Man" << endl; (6/100)...5/-

- 5 - (c) Determine the values of all variables after the expression is executed. Assume that, when each statement begins its execution; all variables have the integer value of 5. All question are independent of each other. (i) product *= x++; quotient /= ++x; (iii) (x++ < ++x)? cout << "No": cout << "YES"; (6/100) 3. (a) (i) Declare two (2) arrays in C++ that may be used in parallel to store 10 employee identification numbers and 10 weekly gross pay. Write a loop in C++ that use these arrays in Question 3(a)(i) to print each employee's identification number and weekly gross pay. (8/100) (b) (i) Given the following C++ array definition. int numbers [] = 2, 4, 6, 8, 10; What will the following statement display? cout << *(numbers + 3) << endl; Write a function whose prototype is void exchange (int *p, int *q); that takes two pointers of integer variables and exchanges the values in those variable. (9/100)...6/-

- 6 - (c) Given the following C++ program, show the output and explain the purpose of function whatisit. #include <iostream> using namespace std; const int ROWS=2; const int COLS=3; typedef int Array[ROWS][COLS]; //defines the type Array void whatisit(array, int, int); void print(const Array); int main() Array a = 11, 33, 55, 22, 44, 66 ; print(a); whatisit (a, 1, 2); print(a); void whatisit (Array a, int c1, int c2) for (int i = 0; i < ROWS; i++) int temp = a[i][c1]; a[i][c1] = a[i][c2]; a[i][c2] = temp; void print (const Array a) for (int i = 0; i < ROWS; i++) for (int j = 0; j < COLS; j++) cout << a[i][j] << " "; cout << "\n"; cout << "\n"; (8/100)...7/-

- 7-4. (a) Write a function named outoforder that takes as parameters an array of double and an int parameter named size and returns a value of type int. This function will test this array for being out of order, meaning that the array violates the following condition: a[0] <= a[1] <= a[2] <=... The function returns -1 if the elements are not out of order; otherwise, it will return the index of the first element of the array is out of order. For example, consider the declaration double a[10] = 1.2, 2.1, 3.3, 2.5, 4.5, 7.9, 5.4, 8.7, 9.9, 1.0; In the array above, a[2] and a[3] are the first pair out of order and a[3] is the first element out of order, so the function returns 3. If the array were sorted, the function would return -1. (16/100)...8/-

- 8 - (b) Write the correct C++ statements in the following program. //Demonstrate pointers and references #include <iostream> using namespace std; (i) //prototype using pointer //prototype using reference int main() int x, y; //Pass the addresses to the pointers. (iii) //function call //Use variable names when passing to references. //The addresses are actually passed. (iv) //function call return 0; //Call-by-reference using pointers and indirection operator. void AskForXandY(int *px, int *py) cout << "\n enter x and y "; cin >> (v) //Call-by-reference using reference parameters. void AskForXandY(int &rx, int &ry) cout << "\n enter x and y "; cin >> (vi) ) (9/100)...9/-

KERTAS SOALAN DALAM VERSI BAHASA MALAYSIA - 9-1. (a) Nyatakan sama ada setiap satu yang berikut adalah BENAR atau PALSU. (i) Semasa atur cara dilaksanakan, kandungan pemboleh ubah pemalar boleh ditukar. Pemboleh ubah char tidak boleh digunakan dalam ungkapan aritmetik. (iii) Semua operator aritmetik *, /, + dan berada pada paras keutamaan yang sama. (iv) Kenyataan continue boleh digunakan untuk memberhentikan gelung. (v) Ungkapan data pernyataan switch boleh jadi ungkapan logikal. (vi) Untuk menggunakan manipulator setprecision, setw, dan setfill, atur cara mesti memasukkan fail iomanip. (6/100) (b) (c) Sesuatu tempat parkir mengenakan kadar bayaran minima $2.00 untuk setiap tiga jam pertama. Bagi setiap jam tambahan, kadar bayaran sebanyak $0.50 akan dikenakan. Kadar bayaran maksima bagi 24 jam ialah $10.00. Anggapkan yang tiada kereta di parkir lebih dari 24 jam pada satu-satu masa. Tulis satu fungsi calculatecharge untuk menentukan kadar bayaran untuk setiap pengguna. (7/100) Apakah output bagi segmen atur cara berikut? (i) int x = 72; if (x > 10) if ((x < 100) (x > 50)) cout << x << endl; if ((x < 100) && (x > 50)) cout << x + 1; cout << x * x; int x = 5; do cout << x << endl; x = x + 2; while (x!= 10); cout << x << endl;...10/-

- 10 - (iii) #include <iostream> using namespace std; int main() char c; c = 'A'; //the ASCII value is 65 while (c <= 80) cout << c; c += 5; (9/100) (d) Satu koefisien bionomial dikira dengan menggunakan formula berikut. c(n, k) = n! (n - k)!k! di mana contoh: n n! = i = 1 * 2 * 3... * n i=1 4 4! = i = 1 * 2 * 3 * 4 i=1 (i) Tulis pernyataan for untuk mengira n! (faktorial). Tulis atur cara C++ yang mengira koefisien binomial. (4/100) (8/100) 2. (a) (i) Tukarkan segmen kod C++ berikut menjadi gelung pasca-ujian. int number; cout << "Enter an odd number:"; cin >> number; while (number %7 == 0) cout << "Enter an odd number divisible by 7 again"; cin >> number;...11/-

- 11 - Tukarkan pernyataan if- kepada pernyataan switch. int age; if ((age > 0) && (age <= 2) cout << "This is a baby" << endl; if (age > 2) && (age <= 4) cout << "This is a toddler" << endl; if (age > 4) && (age <= 6) cout << "This is a child" << endl; cout << "You are not a child anymore" << endl; (4/100) (b) Cari kesalahan-kesalahan sintaksis dan/atau semantik bagi kod segmen berikut dan jelaskan bagaimana membetulkannya. (i) x = 1 while (x <= 10); x++; for (y =.1; y!= 1.0; y +=.1) cout << y << endl; switch (n) case 1: cout << "The number is 1" << endl; case 2: cout << "The number is 2: << endl; break; default: cout << "The number is not 1 or 2" << endl; break int x = 1, total; while (x <= 10) total += x; ++x; (iii) if (gender == 1) cout << "Woman" << endl; cin >> gender; cout << "Man" << endl; (6/100)...12/-

- 12 - (c) Tentukan nilai semua pemboleh ubah selepas pelaksanaan dibuat. Anggapkan bahawa semua pemboleh ubah mempunyai nilai 5 apabila setiap pernyataan memulakan pelaksanaannya. Setiap soalan tidak bergantung pada satu sama lain. (i) product *= x++; quotient /= ++x; (iii) (x++ < ++x)? cout << "No": cout << "YES"; (6/100) 3. (a) (i) Isytihar dua (2) tatasusunan dalam C++ yang boleh digunakan secara selari untuk menyimpan 10 nombor pengenalan pekerja dan 10 gaji kasar mingguan pekerja. Tulis gelung dalam C++ yang menggunakan tatasusunan dalam Soalan 3(a)(i) untuk mencetak setiap nombor pengenalan pekerja dan gaji kasar mingguan pekerja. (8/100) (b) (i) Diberi definisi tatasusunan C++ berikut. int numbers [] = 2, 4, 6, 8, 10; Apakah yang akan dipapar oleh kenyataan berikut? cout << *(numbers + 3) << endl; Tulis suatu fungsi di mana prototaipnya ialah void exchange (int *p, int *q); yang menerima dua pemboleh ubah penuding berjenis integer dan menukar ganti nilai-nilai pemboleh ubah tersebut. (9/100)...13/-

- 13 - (c) Diberi atur cara C++ seperti berikut, tunjukkan output dan jelaskan tujuan fungsi whatisit. #include <iostream> using namespace std; const int ROWS=2; const int COLS=3; typedef int Array[ROWS][COLS]; //defines the type Array void whatisit(array, int, int); void print(const Array); int main() Array a = 11, 33, 55, 22, 44, 66 ; print(a); whatisit (a, 1, 2); print(a); void whatisit (Array a, int c1, int c2) for (int i = 0; i < ROWS; i++) int temp = a[i][c1]; a[i][c1] = a[i][c2]; a[i][c2] = temp; void print (const Array a) for (int i = 0; i < ROWS; i++) for (int j = 0; j < COLS; j++) cout << a[i][j] << " "; cout << "\n"; cout << "\n"; (8/100)...14/-

- 14-4. (a) Tulis fungsi bernama outoforder yang menerima tatasusunan berjenis double dan pemboleh ubah bernama size berjenis int sebagai parameter dan fungsi ini kembalikan nilai berjenis int. Fungsi ini akan menguji sama ada tatasusunan tidak tersusun, bermaksud tatasusunan tidak menepati keadaan berikut: a[0] <= a[1] <= a[2] <=... Fungsi ini mengembalikan -1 jika elemen tidak tersusun, jika tidak ia mengembalikan indeks elemen pertama tatasusunan tidak tersusun. Sebagai contoh, diberi pengisytiharan double a[10] = 1.2, 2.1, 3.3, 2.5, 4.5, 7.9, 5.4, 8.7, 9.9, 1.0 Dalam tatasusunan di atas a[2] dan a[3] adalah pasangan pertama yang tidak tersusun dan a[3] adalah elemen pertama yang tidak tersusun, maka fungsi mengembalikan 3. Jika tatasusunan tersusun, fungsi mengembalikan -1. (16/100)...15/-

- 15 - (b) Tulis kenyataan C++ yang betul dalam atur cara berikut. //Demonstrate pointers and references #include <iostream> using namespace std; (i) //prototype using pointer //prototype using reference int main() int x, y; //Pass the addresses to the pointers. (iii) //function call //Use variable names when passing to references. //The addresses are actually passed. (iv) //function call return 0; //Call-by-reference using pointers and indirection operator. void AskForXandY(int *px, int *py) cout << "\n enter x and y "; cin >> (v) //Call-by-reference using reference parameters. void AskForXandY(int &rx, int &ry) cout << "\n enter x and y "; cin >> (vi) ) (9/100) - ooooooo -