CPT113/CPM213 Programming Methodology & Data Structures [Metodologi Pengaturcaraan & Struktur Data]

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

UNIVERSITI SAINS MALAYSIA

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

UNIVERSITI SAINS MALAYSIA. CPT103/ CPM211 Struktur Data & Paradigma 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. CPT103 Struktur Data & Paradigma Pengaturcaraan

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

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

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

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

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

CPT111/CPM111 Principles of Programming [Prinsip Pengaturcaraan]

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

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

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

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

UNIVERSITI SAINS MALAYSIA. CST131 Computer Organisation [Organisasi Komputer]

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

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

UNIVERSITI SAINS MALAYSIA. CST232 Operating Systems [Sistem Pengendalian]

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

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

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]

MAT181 Programming For Scientific Applications [Pengaturcaraan Untuk Penggunaan Sains]

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

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

EEE 428 SISTEM KOMPUTER

MSS 317 Coding Theory [Teori Pengekodan]

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

UNIVERSITI SAINS MALAYSIA. CPT101 Prinsip-Prinsip Pengaturcaraan

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

MICROSOFT EXCEL. Membina Hamparan Elektronik Fungsi Hamparan Elektronik

UNIVERSITI SAINS MALAYSIA. CST131 Computer Organisation [Organisasi Komputer]

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

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

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

Pengenalan Sistem Maklumat Dalam Pendidikan

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

EEE 348 PENGANTAR REKABENTUK LITAR BERSEPADU

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

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

UNIVERSITI SAINS MALAYSIA. CPT101 Prinsip-Prinsip Pengaturcaraan

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

UNIVERSITI SAINS MALAYSIA. CIT502 Pengaturcaraan dan Kejuruteraan Perisian Berorientasi Objek

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

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

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

CCS592 Advanced Algorithms and Complexity [Algoritma Lanjutan & Kekompleksan]

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

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

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

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

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

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

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

UNIVERSITI SAINS MALAYSIA. CPT101 Prinsip-Prinsip Pengaturcaraan

Lab 4 : Sorting Techniques

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

Panduan Guru Maker UNO/ Arduino

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 MALAYSIA PERLIS. DNT 126 Basic Computer Programming [Asas Pengaturcaraan Komputer]

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

UNIVERSITI SAINS MALAYSIA. CST234 Network Programming [Pengaturcaraan Rangkaian]

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

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

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.

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

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

KOLEJ MULTIMEDIA JALAN GURNEY KIRI KUALA LUMPUR

Panduan Menggunakan Autoresponder FreeAutobot.com

Tutorial Letter 102/1/2012 Programming: Data Structures

LAB 5: WORKING WITH DATA

CST432 Microprocessors & Embedded Systems [Mikropemproses & Sistem Terbenam]

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

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

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

EEM 312 ROBOTIK & PENGLIHATAN MESIN

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

Information Security Management System ISO/IEC 27001:2013

Manual Pengguna. PCN Online Service Fulfillment System

PANDUAN PENGGUNA (PENSYARAH)

MULTIMEDIA COLLEGE JALAN GURNEY KIRI KUALA LUMPUR

UNIVERSITI SAINS MALAYSIA. CPT201 Reka Bentuk & Analisis Algoritma

TEKNOLOGI, GADJET & KEIBUBAPAAN

Semasa buku ini ditulis XAMPP mengandungi empat versi:

Persekitaran Pengaturcaraan Arduino

UNIVERSITI SAINS MALAYSIA EEE 355 ROBOT DAN PENGAUTOMATAN

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

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

UNIVERSITI MALAYSIA SARAWAK KOTA SAMARAHAN SARAWAK

CST234 Network Programming [Pengaturcaraan Rangkaian]

MULTIMEDIA COLLEGE JALAN GURNEY KIRI KUALA LUMPUR

Visitor Management System

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

EEE 355 ROBOTIC & AUTOMATION [Robotik & Pengautomatan]

Transcription:

Second Semester Examination 2016/2017 Academic Session June 2017 CPT113/CPM213 Programming Methodology & Data Structures [Metodologi Pengaturcaraan & Struktur Data] Duration : 2 hours [Masa : 2 jam] INSTRUCTIONS TO CANDIDATE: [ARAHAN KEPADA CALON:] Please ensure that this examination paper contains THREE questions in FOURTEEN printed pages before you begin the examination. [Sila pastikan bahawa kertas peperiksaan ini mengandungi TIGA soalan di dalam EMPAT 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) (i) What is the purpose of constructor and destructor in an object oriented program? State when constructor and destructor are executed in a program. Apakah tujuan pembina dan pemusnah di dalam atur cara berorientasikan objek? Nyatakan bila pembina dan pemusnah dilaksanakan dalam atur cara. Write a class definition named XYZ and write the related function/method implementation for the class XYZ. Variables should be defined as a private members and function/method should be defined as public members of the class XYZ. Class XYZ consists of the following class members: Tulis takrifan kelas yang bernama XYZ dan tulis implementasi fungsi/kaedah yang berkenaan untuk kelas XYZ. Pemboleh-pemboleh ubah perlu diisytiharkan sebagai ahli private dan fungsi/kaedah perlu diisytiharkan sebagai ahli public bagi kelas XYZ. Kelas XYZ mempunyai ahli-ahli seperti berikut: Three (3) integer variables W, D and L. Tiga (3) pemboleh ubah integer W, D dan L. setvalue(..) function/method which receives three (3) integer parameters and assign the received parameters to the private members of the class XYZ. Fungsi/kaedah setvalue(..) yang menerima tiga (3) parameter integer dan umpukan parameter yang diterima kepada ahli-ahli private kelas XYZ. result(..) function/method which receives an integer parameter and increase the related variable value accordingly. If the received parameter is 1 then increase W by 1, if the received parameter is 0 then increase D by 1 and if the received parameter is -1 then increase L by 1. Fungsi/kaedah result(..) yang menerima satu parameter integer dan menambah nilai pemboleh ubah yang berkenaan. Jika nilai parameter yang diterima adalah 1, maka tambah 1 kepada W, jika nilai parameter yang diterima adalah 0, maka tambah 1 kepada D dan jika nilai parameter yang diterima adalah -1, maka tambah 1 kepada L....3/-

- 3 - Default constructor which initializes all values to 0 and alternate constructor. Pembina lalai yang mengawalkan semua nilai kepada 0 dan pembina alternatif. showval() function/method which will display the values of W, D and L. Fungsi/kaedah showval() yang akan memaparkan nilai W, D dan L. (iii) Based on 1(a), for each the given main() function, state the output and explain how you get the output. If there is any error, state a reason which causes the error. Berdasarkan 1(a), untuk setiap fungsi main() yang diberi, nyatakan output dan jelaskan bagaimana anda mendapat output. Jika terdapat ralat, nyatakan sebab terjadi ralat tersebut. main() function Output and reason int main() XYZ m1(3,2,1); cout << Win: << m1.w << endl; cout << Draw: << m1.d << endl; cout << Lose: << m1.l << endl; system("pause"); int main() XYZ m1; m1.showval(); m1.setvalue(3,1,2); m1.result(-1); m1.showval(); system("pause"); (40/100)...4/-

- 4 - (b) Given the following class definition and class implementation: Diberi takrifan kelas dan implementasi kelas seperti berikut: #include <iostream> using namespace std; class ABC private: int x; int y; public: void setval(int j,int k) x=j;y=k; ABC()x=1;y=1; ABC(int,int); void show(); ; ABC::ABC(int a,int b) x=a;y=b; void ABC::show() cout << x <<" " << y << endl; class ICE:public ABC int z; public: void incval(); void show(); ICE()z=0; int sum(); ~ICE() ; int ICE::sum() return (x + y + z); void ICE::show() ABC::show(); cout << z << endl; (i) Is there any error in the class definition and the class implementation in 1(b)? If yes, states which statements cause the error and explain on how to correct the error. Adakah terdapat ralat dalam takrifan kelas dan implementasi kelas dalam 1(b)? Jika ya, nyatakan penyataan-penyataan mana yang menyebabkan ralat dan berikan penjelasan untuk membetulkan ralat tersebut. Write an alternate constructor for the derived class ICE which will initiate the values of variables x,y and z. Tulis pembina alternatif untuk kelas pewarisan ICE yang akan mengawal nilai pemboleh ubah x,y dan z....5/-

- 5 - (iii) Give the output of the given main() function: Beri output untuk fungsi main() berikut: int main() ICE ice1; ICE ice2(2,3,6); ice1.show(); cout <<"\n\n..." <<endl; ice2.show(); system("pause"); (iv) Modify the class definition in 1(b) so that the class ICE has one (1) friend function named frendisplay( ) and write frendisplay( ) function definition to display the values of variables x,y and z. Ubahsuai takrifan kelas dalam 1(b) supaya kelas ICE mempunyai satu (1) fungsi kawan yang bernama frendisplay( ) dan tulis definisi fungsi frendisplay( ) untuk memaparkan nilai-nilai pemboleh ubah x,y dan z. (30/100) (c) Given the following class definition and the class implementation: Diberi takrifan kelas dan implementasi kelas seperti berikut: #include <iostream> using namespace std; class Infor private: int no_stu; int no_prog; public: Infor() no_stu=0; no_prog=0; ~Infor() void setinfor(int,int); void printinfor(); ; void Infor::printInfor() cout <<"No. of Programme: " ; cout << no_prog << endl; cout <<"No. of student: " ; cout << no_stu << endl; void Infor::setInfor (int p,int s) no_prog=p; no_stu=s; class School private: string schcode; int acadstaff;. public: School() acadstaff=0; schcode="null"; ~School() void setdata(string,int,int,int); ;...6/-

- 6 - (i) Modify the class definition in 1(c) so that the class School consists of the additional class members as follow: Ubahsuai takrifan kelas dalam 1(c) supaya kelas School mempunyai ahliahli kelas tambahan seperti berikut: an object typed of the class Infor. satu objek berjenis kelas Infor. displaydata() function/method that display all related information. Fungsi/kaedah displaydata() yang memaparkan semua maklumat berkenaan. Write setdata() function/method implementation to set number of student, number of programme, school code and number of academic staff. Tulis implementasi fungsi/kaedah setdata() untuk menetapkan bilangan pelajar, bilangan rancangan, kod pusat pengajian dan bilangan staf akademik. (iii) Write displaydata() function/method implementation to display all related information. Tulis implementasi fungsi/kaedah displaydata() untuk memaparkan semua maklumat berkenaan. (iv) Give the output of the following main() function: Beri output fungsi main() berikut: int main() School sch1; sch1.displaydata(); sch1.setdata("cs",45,6,460); sch1.displaydata(); system("pause"); (30/100)...7/-

- 7-2. (a) (i) Explain what is dynamic array and how it is different with static array? Jelaskan maksud tata susunan dinamik dan bagaimana ia berbeza dengan tata susunan statik? Given the incomplete program below: Diberi atur cara tidak lengkap di bawah: #include<iostream> using namespace std; int main() int input; (i).... // declare pointer type int named ptr cout<<"how many items you want to enter : "<<endl; cin>>input;... // create dynamic array based on user input as above for (int counter=0; counter < input; counter++) (iii)... //prompt user to fill array with numbers typed in from user input //display items entered cout<<"the items you have entered are : "<<endl; for (int counter=0; counter < input; counter++) cout<<counter+1<<"item is : "<<*(ptr+counter)<<endl; (iv)...; //destroy the dynamic array return 0; Write the correct C++ statements for (i),, (iii) and (iv). Tulis kenyataan- kenyataan C++ yang betul untuk (i),, (iii) dan (iv). (25/100)...8/-

- 8 - (b) Given the following diagram: Diberikan gambar rajah seperti berikut: Figure 1/Rajah 1 (i) What are the content of the two pointers above? Fill in the blank box. Apakah maklumat bagi dua penunjuk di atas? Isi kotak kosong. What is the type of linked list? Apakah jenis senarai berpaut di atas? (iii) Explain the function of the following pointers: first, last, next and back. Terangkan fungsi bagi setiap penunjuk berikut: first, last, next and back. (iv) Declare the structure of the nodes. Isytiharkan struktur nod-nod. (v) Write statement to print the value of the nodes in reverse order. Tulis kenyataan untuk mencetak nilai bagi nod-nod dalam turutan terbalik. (20 /100)...9/-

- 9 - (c) You are to write a program to store data for the 14th Malaysian General Election (GE14). The information to store are: name, IC, gender, age and codearea. The following is the definition of the struct nodetype and abstract class linkedlisttype as ADT: Anda dikehendaki menulis atur cara untuk menyimpan data bagi Pilihan raya Umum Malaysia ke-14 (GE14). Maklumat untuk disimpan adalah: name, IC, gender, age dan codearea. Berikut adalah definisi struct nodetype dan kelas abstrak linkedlisttype sebagai ADT: template <class Type> struct nodetype Type info; nodetype<type> *link; ; template <class Type> class linkedlisttype public: const linkedlisttype<type>& operator= (const linkedlisttype<type>&); void initializelist(); bool isemptylist() const; void print() const; void displayvotersic(string IC); int length() const; void destroylist(); Type front() const; Type back() const; bool search(const Type& searchitem); void insertinfo(const Type& newitem); deletenode(const Type& deleteitem); linkedlisttype(); ~linkedlisttype(); protected: int count; nodetype<type> *first; nodetype<type> *last; ; Assume that the following structure is used to store the voter information: Anggapkan struktur berikut digunakan untuk menyimpan maklumat pengundi: struct VotersInfo string name; string IC; string gender; int age; string codearea; ;...10/-

- 10 - (i) Write a displayvotersic()function to display all voters info based on search criteria IC. Tulis satu fungsi displayvotersic() untuk memaparkan semua maklumat pengundi berpandukan kriteria pencarian IC. Write a complete function insertinfo()to insert data in ascending order into the linked list based on voter s age. Tulis fungsi lengkap insertinfo() untuk menyelit data dalam susunan menaik ke dalam senarai berpaut berdasarkan umur pengundi. (15/100) (d) Given is the main function of the program: int main() // set structure typed VotersInfo to be stored in the node (info // part of the nodetype) in the linkedlist (iii) ; VotersInfo vote; int choice; bool flag=true; do system ("cls"); cout <<"\n 1. Input Voters"; cout <<"\n 2. Display the oldest voter: "; cout <<"\n 3. Exit"; cout <<"\n Your choice: "; cin >> choice; switch (choice) case 1: // store name, IC, gender, age and codearea to the struc // vote declared in main() (iv) ; // call function to insert voters info and send vote as // actual parameter (v) ; break; case 2: // call function to display the oldest voter (vi) ; cout <<"First data: \n"; cout <<vote.name << " " << vote.name << endl; system("pause"); break; case 3: flag=false; break; default: cout <<"Input not valid...";...11/-

- 11 - Write the correct statements for number (iii), (iv), (v) and (vi) above. Tulis kenyataan yang betul untuk (iii), (iv), (v) and (vi) di atas. (40/100) 3. You are given the abstract class as ADT for Stack and Queue. Anda diberi kelas abstrak sebagai ADT untuk Tindanan dan Baris Gilir. Stack template <class Type> class linkedstacktype: public stackadt<type> public: const linkedstacktype<type>& operator=(const linkedstacktype <Type>&); void initializestack(); bool isemptystack() const; bool isfullstack() const; void push(const Type& newitem); Type top() const; void pop(); linkedstacktype(); linkedstacktype(const linkedstacktype<type>& otherstack); ~linkedstacktype(); private: nodetype<type> *stacktop; void copystack(const linkedstacktype<type>& otherstack); ; Queue template <class Type> class linkedqueuetype: public queueadt <Type> public: const linkedqueuetype<type> & operator= (const linkedqueuetype <Type>&); bool isemptyqueue() const; bool isfullqueue() const; void initializequeue(); void deletequeue(); Type front()const; Type back() const; void addqueue(type& newitem); linkedqueuetype(); linkedqueuetype (const linkedqueuetype<type>&otherqueue); ~linkedqueuetype(); private: nodetype<type> *queuefront; nodetype<type> *queurear; ; (a) (i) For each of the following situations, which of these ADTs (1 through 4) would be most appropriate: (1) queues; (2) stacks; (3) lists; (4) none of these? Untuk setiap situasi berikut, yang mana satu ADTs ini (1 hingga 4) yang paling sesuai: (1) baris gilir; (2) tindanan; (3) senarai; (4) tiada yang sesuai? The customers at bank who take numbers to mark their arrival. Pelanggan di bank yang mengambil nombor untuk menandakan ketibaan mereka. Integers that need to be sorted. Integer yang perlu disusun. Arrangement of flowers in a vase. Susunan bunga dalam pasu....12/-

- 12 - Airplanes that are waiting to land at a busy airport. Kapal terbang yang sedang menunggu untuk mendarat di lapangan terbang yang sibuk. An employer who fires the most recently hired person. Majikan yang memberhentikan pekerja yang paling baru diambil bekerja. Suppose you have a stack astack and an empty auxiliary stack auxstack. Show how you can do each of the following tasks by using only the ADT stack operations: Anggapkan anda mempunyai tindanan astack dan tindanan bantu kosong auxstack. Tunjukkan bagaimana anda boleh melakukan setiap tugas berikut dengan menggunakan hanya operasi ADT tindanan: Display the contents of astack in reverse order; that is, display the top last. Papar kandungan astack secara terbalik; iaitu, kandungan atas paling akhir. Delete every occurrence of a specified item from astack, leaving the order of the remaining items unchanged. Hapuskan setiap kewujudan item yang dinyatakan dari astack, tanpa mengubah susunan kandungan asal yang masih tinggal. (30/100) (b) Consider the language L below: L = w$w : w is a string of characters other than $, w = reverse(w) The string A$A, ABC$CBA, and $ are in L, but AB$AB is not. Assume L contains only one $. Write the program segment that recognize whether a particular strings is in the language L. Pertimbangkan bahasa L di bawah: L = w$w : w ialah rentetan aksara yang bukan $, w = terbalik(w) Rentetan A$A, ABC$CBA, dan $ adalah L, tetapi bukan AB$AB. Anggapkan L mengandungi hanya satu $. Tulis segmen program yang mengiktiraf sama ada rentetan tertentu adalah dalam bahasa L....13/-

- 13 - (i) Use both the ADT stack and queue operations. Guna kedua-dua operasi ADT tindanan dan baris gilir Use only ADT stack operations. Guna hanya operasi ADT tindanan. (30/100) (c) (i) What is the output of the following program and what argument values, if any could you pass to the function f to cause the program to run forever? Apakah output program berikut dan apakah nilai-nilai hujah jika ada, yang boleh di hantar kepada fungsi f yang menyebabkan larian program selamalamanya? #include <iostream.h> int f(int n) int main() cout << The value of f(8) is << f(8) <<endl; return 0; //end main int f(int n) //Precondition: n >= 0 cout << Function entered with n = << n <<endl; switch (n) case 0:case 1:case 2: return n + 1; default: return f(n-2) * f(n-4); //end switch end f Write a recursive function displayoctal() that receives a positive decimal number then converts the number to base 8 and display the result. Tulis fungsi rekursi displayoctal() yang menerima nombor perpuluhan positif, kemudian menukarkan kepada nombor asas 8 dan paparkan hasilnya. (20/100)...14/-

- 14 - (d) (i) Given the nodes of a binary tree in the preorder sequence and the postorder sequence, show that it may not be possible to reconstruct a unique binary tree. Diberi nod pepohon perduaan dalam jujukan tertib awalan dan jujukan tertib akhiran, tunjukkan bahawa tidak mungkin untuk membina semula pepohon perduaan yang unik. Suppose you are given two sequences of elements of corresponding to the inorder sequence and the preorder sequence. Prove that it is possible to reconstruct a unique binary tree. Anggapkan anda diberi dua jujukan unsur-unsur yang sepadan dengan jujukan tertib sisipan dan jujukan tertib awalan. Buktikan bahawa ada kemungkinan boleh membina semula pepohon perduaan yang unik. (20/100) - ooooooo -