You are on page 1of 37
UN MATAPELAJARAN FAKULTI TEKNOLOGI MAKLUMAT DAN KOMUNIKASI KOD MATAPELAJARAN : BITG1113 SULIT IVERSITI TEKNIKAL MALAYSIA MELAKA PEPERIKSAAN AKHIR SEMESTER 1 SESI 2008/2009 COMPUTER PROGRAMMING 2. Sila jawab semua daripada mukasw mukasurat 20 hin; PENYELARAS PN. SYAHIDA BT MOHTAR KURSUS BEKE, BMCS, BEKC, BMFA, BMFU, BMCD, BENC, BMFB, BENE, BEKM, BEKP MASA 2. JAM 30 MIN! TARIKH 5 NOVEMBER 2008 TEMPAT BK 3-4, BK 9-10, BK 11-12, KOMPLEKS SUKAN DAN DEWAN UTeM ARAHAN KEPADA CALON : 1. Kertas soalan ini mengandungi EMPAT (4) bahagian: © Babagian A (Soalan T/F) 10 soalan * Bahagian B (Soalan Objektif) : 30 soalan Babagian C (Soalan Struktur) :4 soalan © Bahagian D (Soalan Ese) 2 soalan 3. Semua jawapan hendaklah ditulis pada kertas jawapan yang disediakan. Sila gunakan borang OMR untuk jawapan Bahagian B. 4. Kertas soalan ini mengandungi 2 versi bahasa. Versi Bahasa Inggeris bermula soalan di Bahagian A,B ,C dan jawab SATU(1) soalan di Bahagian D. rat 2 hingga 19, manakala versi Bahasa Melayu bermula daripada gga 37. Sil jawab dalam satu versi sahaja. KERTAS SOALAN INI TERDIRI DARIPADA (37) MUKASURAT SAHAJA. (TERMASUK MUKASURAT HADAPAN) SULIT (BITG 1113) SULIT PART A : (10 MARKS) Write T if the statement is true and write F if the statement is false. The sequence strueture can be found in every program. Selection is about choosing between alternative paths based on some predefined test. A numeric variable used for counting something is called an accumulator. ‘You call a program-defined function in exactly the same way as you call a built-in function, 1g by reference is referred to as passing a variable’s address. ‘The array senarai[3]/5] is equivalent to the array senarai[15]. Arrays are passed to functions by reference. The mode ios will write all output to the end of the file. All elements in the structure must be of the same data type. The * operator in pointer is used to get the address of a variable. SULIT (BITG 1113) SULIT PART B: (30 MARKS) Answer ALL Questions. 1. The short English statements that represent the steps the computer must follow to solve a problem are called A. flow diagram B. IPO chart C. pseudochart D. pseudocode Files with the extension store C++ source code written by programmers. A. java B. exe C. cpp D. .cplus Every C+ application must contain exactly one A. main funetion B. pre-processor directive C. whitespace character D. header le 4, The set of instructions for adding two numbers is an example of the structure A. control B. repetition C. selection D. sequence SULIT (BITG 1113) SULIT Question 5 and 6 are based on the following pseudocode: wave wne start Set SALARY=0 Set HOUR_RATE = 12.50 Read employee’s working hour : HOUR . Print SALARY . End 5. Choose the correct statement for Line 5. A B. SALARY ce D. SALARY SALARY = SALARY + HOUR SALARY * HOUR_RATE SALARY = SALARY + HOUR * HOUR_RATE SALARY * HOUR + HOUR_RATE 6. If the pseudocode is converted into a flowchart, the symbol for line 5 is A ic 0000 SULIT (BITG 1113) ULIT 7, Choose an instruction of a sequence structure. Valk until tire B, “If it’s raining outside, take an umbrella to work” ‘Starts the car and drive to work” D. “While Mom is shopping, read the story book” 8. Which of the following is the equality operator in C++? Als B= Cc D. => Figure 1 9. The above flowchart shows the A. single way selection B. two way selection C. multiple way selection D. repetition SULIT (BITG 1113) SULIT 10. Given the value for KPT = 3.7,servYR = 4andeduBG = 2. What will be the output for the following program segment? LE(KPI >= 3.5) if(servyR >= 5 cout<<"Qualify else if(servYR cout<<"Qualify else if(serv¥R cout<<"Qualify 65 eduBG >= 3) for Senior Manager position\n”; = 3&5 servYR < 5 && eduBG >= 3) for Manager position\n": = 5 && eduBG < 3) for Supervisor position\n"; A. Qualify for Senior Manager position B. Qualify for Manager position C. Qualify for Supervisor po: ion D. Error occur because the source code is not closed with e1se 11. Given the value for Grade is B. Trace the output for the following program segment, switch (Grade) ( case ‘Ar: case ‘BY case ‘Cl: case ‘D': case ‘ET: default cout<<”Good Grade\n";break; cout<<"Moderate Grade\n"; break; cout<<“Study harder\n";break: cout<<"Change attitude\n”;break; cout<<"Invalid grade\n"; A. Good Grade B. Moderate Grade Cc. Study harder D. No output SULIT. (BITG 1113) suLIT 12. The whi 2e loop is referred to at the begit loop, because the loop condition is tested ning of the loop. A. a beginning B. an initial C. apretest D. a priming 13. Counters and accumulators must be initialized and A. added B. updated ©. displayed D, none of the above 14, Values that are used to end loops are referred to as values. A. end B. finish C. stop D. sentinel 15, The loop body instructions in the ys are processed at least once. A. do while B. for Cc. while D. both aand b 16.___ allow large and complex programs to be broken into small and manageable tasks. A, Statement B. Function C. #include directives D. Selection structures 7 SULIT (BITG 1113) SULIT 17. Which of the following statement is NOT TRUE about function header? A. It must be ended with semicolon. B. Begin with return Datatype. C. The name of the function follows the return Datatype D. Has an optional parametexList enclosed in (). 18, Any object defined for a function that is visible from its definition until the end of the program is called? A. Local scope. B. Independent scope. C. Global scope. D. Dependence scope. 19. Consider the following statement: num = 10 + rand( } $ (100 - 10 + 1). is assigned to the num variable, the value returned by rand( ) is A4 B. 352 C. 323 D. 2500 20. By default, __are passed to function by reference. A. ints B. double C. arrays D, primitive data types 21. Which of the following statements does not contain syntax error? hours [5] ={8,8,7.5,8, 8.5 }3 B. int scores [ 4 ] C. int sales [71] D. char months [ ] = SULIT 22. 23. 25. (BITG 1113) SULIT The first variable in a one-dimensional array is assigned a subscript of A. NULL B. -1 co D1 Which prototype for a function reads in an integer array and returns the array to the calling function? A. int function( }; B. int [ ] function( ); C. void function(int arrayl 1); D. void function (int sarray{ ]}+ 24. Which of the following while clauses tells the computer to continue reading the inventory. txt file until the end of the file is reached? The file object is named ininv. A.wnile (inventory.txt.end( )) B.while (inInv-end( }) C.while (!inInv.eof( )1 D. while (!inventory.txt.eof( )) You define a structure using the keyword. A, structure B. struct ° . record D. data SULIT (BITG 1113) SULIT 26. Examine the following structure declaration and determine why it will cause a compile error: structure accounting { int iPeriod = 2; long 1fiscalYear = 2000; double dCurrTaxRate = 0.15; A. The name of the structure must be followed by parentheses, the same as a function definition B. You are only allowed to use a single data type within a structure definition, a The structure is declared using the structure keyword D. There is no cause for any compilation error 27. A pointer A. contains the data stored at a location in memory. contains the address of a memory location. op can be used in input statements, but not output statement, 9 can be changed to different value: both input and output statements. 28. Given the following declarations. Which of the following expressions is NOT ALLOWED? int x 7 double d ; int* p; int **k double* = as ade = 6d; yoe> rau = bp; -10- SULIT 30. (BITG 1113) SULIT Which of the following statements about pointer is NOT TRUE? A. Pointers are built on the standard type address B. Pointers are machine addresses C. Pointers are derived data types D. Pointers can be constants Assume that a and b are pointers to integers and that a points to the variable name, What is the effect of the statement b = a; ? A. The value of name is copied into b. B. The memory address stored in a is copied into C. The memory address stored in bis copied into a D, The pointer a is now pointing to different object. -- SULIT (BITG 1113) PART C:: (40 MARKS) Answer ALL questions. QUESTION I (10 MARKS) a) Given the code segment below, fill in the blank with a statement to assign the character ¥ to the clement in the first row, second column of the letters array. main() { char letters(3] [3]: (2 marks) b) Declare and initialize a two-row with three-column char array named alphabets. The elements are as listed below: TIE D/G)F (2 marks) ©) The following main () funetion stores three students’ marks from user into three variables, and then calculates and outputs the total. Modify the main {) function so that the marks are stored into an array. main() { float markl,mark2,mark3, total; cout<<"Enter three students’ marks: \n"; cin>>mark1>>mark2>>mark3; total=markl+mark2+mark3; cout<>___(5) cin. ignore (100, \n"1i outfile < #in using namespace std; (2) day {Mon=1,Tues,Wed, Fri, Sat, Sun}; void main() cout << endl; for (_(2) 3); (4); day++) cout <<"\t" using namespace std; int main() ( treat tq + tec; cout<<*pec” — Nectgse” Sectrecendl; coutcepec” — “ceqee” “cerecendl; return 0; b a) Based on the above program: a b © . a r Figure3 i. What is the value for a, b and c in Figure 3? SULIT G marks) ii, What will p, q, and r point to? Redraw Figure 3 and use arrow to show the answers. (3 marks) iii. Base to the following addresses of a, b, and c, what is the final values of p, q. and r re 3? a = 0x00135760 b = 0x01015879 © = 0x00234781 iv. Write the outputs of the above program, 166 B marks) (3 marks) SULIT (BITG 1113) JLIT PART D : (20 MARKS) Answer only ONE (1) question. QUESTION 1 (20 MARKS) Write a complete program for the following problem You have been asked by a used car sale company to create a program that will determine the retail price of a used car. Their pricing policy is that any car is expected to sell in one month or less is marked up 10% over the cost and any car that is expected to stay on the showroom for more than one month is marked up 20% the cost. Be sure to notice that the low markup of 10% is used for up to 30 days and that at 31 days and more the markup change to 20%. Your program will give the retail price of a used car. A sample output is shown in Figure 4, BH © Windowsaystern22\cmdiexe This program determines the retail price of a used car lenter the cost of the used car :25000 Enter the expected of days until sold :25 The used car cost = RM 25000 expected day until sold = 25 days the retail price = RM 27500 Press any key to continue . Figure 4 17. SULIT (BITG 1113) SULIT You must apply techniques pass dy value and pass by reference to the functions in your program code, Consider the following program segment: #include using namespace std; //declare global constants //declare function prototypes int main() { int expected _daysold; doubie car_cost, retail_price; cout<< "\n\tThis program determines the retail price of a used car.\n\n"; gotInput (car_cost, expected_daysold) ; retail_price=calcRetailPrice(car_cost, expected_daysold) ; displayRetailPrice(car_cost, expected_daysold, retail_price); return 0; ) //+**seeesgunction definition® tse /{ function to get input // function to calculate retail price //function to display the output The program must use THREE (3) functions with the following prototypes: 1. void getInput (doubles cost, ints daysold) this fun jon accepts two inputs: cost and expected number of days until sold. 2. do calcRetailPrice(double cost, int daysold) this function is called to calculate the retail price for a used car. 3. void displayRetailPrice (double cost, int daysold, double price) this funetion is called to display the retail price for a used car. -18- SULIT (BITG 1113) SULIT QUESTION 2 (20 MARKS) Write a program that allows the user to enter the names of 3 candidates in an election and the number of votes received by each candidate. The program should then display as output each candidate’s name, the number of votes received, and the percentage of the total votes received by the candidate. Your program should also display the winner of the election. A sample output is: the [Candidate | % oftotal votes ‘| 10.00 40.00 | nn) | ‘The winner of the election is Mahathir program must use TWO (2) funetions with the following prototypes: a) int sumvotes (int list[ ], int size); b) int winnerIndex (int list[ ], int size); the function sumvotes accepts two inputs : an array list and an integer size, and returns an int, where size indicates the size of array list © the function winnerIndex accepts two inputs : an array list and an integer size, and returns an int, where size indicates the size of array list * use output formatting as necessary the names and number of votes received are entered within the main function - END - -19- SULIT (BITG 1113) SULIT BAHAGIAN A : (10 MARKAH) 6 9. 10, ulis B untuk penyataan yang benar dan S untuk penyataan yang salah, Struktur jujukan boleh didapati dalam setiap aturcara, Pilihan adalah mengenai memilih antara laluan-lauan altematif berdasarkan beberapa ujian yang telah ditetapkan Suatu pembolehubah berangka yang digunakan untuk mengira sesuatu disebut penumpuk Sesuatu fungsi program yang diisytiharkan dipanggil sama seperti fungsi yang telah siap dibina dalam sesuatu program. Memulangkan by reference dirujuk sebagai memulangkan satu alamat pembolehubah asusunan senarai [3] (5] adalah setara dengan tatasusunan senarai[15]. ‘Tatasusunan dihantar ke fungsi secara rujukan. Mod ios:app akan menulis semua output hingga ke akhir fal Semua elemen di dalam struktur mestilah mempunyai jenis data yg sama, Operator * pada penuding digunapakai untuk mendapatkan alamat suatu pembolehubah, -20- SULIT (BITG 1113) SULIT BAHAGIAN B : (30 MARKAH) Jawab SEMUA soalan, Pernyataan di dalam ringkasan Bahasa Inggeris yang menunjukkan aturcara dimana komputer mesti ikuti bagi menyelesaikan masalah dikenali sebagai A. carta alir B. carta IPO C. carta pseudo D, kod pseudo Fail yang mempunyai extension ___menyimpan kod aturcara yang ditulis oleh cureara, Sctiap aplikasi C++ mesti mengandun; A. Fungsi utama (main function) B. pre-processor directive C. tempat kosong (whitespace character) D. Fail header Set arahan-arahan untuk penambahan dua nombor ialah satu contoh struktur A. kawalan B. pengulangan . pilihan D. jujukan -21- SULIT (BITG 1113) Soalan 5 dan 6 adalah berdasarkan pada kod pseudo berikut: 1. Start 2. Set SALARY=0 3, Set HOUR_RATE = 12.50 4, Read employee’s working hour : HOUR 5. 6. Print SALARY 7, End 5. Pilih pemyataan yang BETUL untuk baris 5 A B. cs D. 6. Jika kod pseudo ini ditukarkan kepada carta alir, simbol untuk baris 5 ialah SALARY = SALARY + HOUR SALARY = SALARY * HOUR_RATE SALARY = SALARY + HOUR * HOUR RATE. SALARY = SALARY * HOUR + HOUR_RATE -22- SULIT SULIT (BITG 1113) SULIT 7. Pilih arahan yang berbentuk struktur jujukan, A. “Berjalan sehingga letih” B. “Vika hujan di luar, ambil payung untuk pergi kerja” C. “Hidupkan kereta dan pandu ke tempat kerja” D. “Selagi Ibu membeli-belab, baca buku cerita” 8. Manakah antara berikut adalah operator persamaan di dalam C+#? A B. Gambarajah 1 9. Carta alir di atas menunjukkan Api an satu arah B. pilihan dua arah C. pilihaan pelbagai arah D. pengulangan -23- SULIT (BITG 1113) SULIT 10, Diberi nilai untuk KPT = 3.7,servYR = 4andeduBG = 2. Apakah yang akan dipaparkan oleh keratan program berikut? LE (KPI >= ( if(serv¥R >= 5 && eduBG >= 3) cout<<"Qualify for Senior Manager position\n"; else if(servYR >= 3 6& servYR < 5 && eduBG >= 3) cout<<"Qualify for Manager position\n”; else if(servYR >= 5 && eduBG < 3) cout<<“Qualify for Supervisor position\n”; 3.5) Qualify for Senior Manager position Qualify for Manager position Qualify for Supervisor position Berlaku kod ralat kerana aturcara tidak ditutup dengan ©1se 11, Diber nilai untuk Grade adalah B. Jejak paparan bagi keratan program berikut, switch (Grade) ( case case case YAl: cout<<”Good Grade\n”;break: ‘3 ‘ch: cout<<"Moderate Grade\n";break; ‘Det <<"Study harder \n";break; ‘Bs cout<<"Change attitude\n";break; default : cout<<"Invalid grade\n"; gap Good Grade Moderate Grade Study harder Tiada output -24- SULIT 2 15 (BITG 1113) Gelu permulean gelung A. permulaan B. pertama C. preuji D. utama Pembilang dan penumpuk mesti dimulakan dan A. ditambah B. dikemaskini C. dipaparkan D. tidak ada jawaban di atas |. Nilai yang digunakan untuk mengakhiri gelung dirujuk sebagai nilai A. akhir B. hujung C. henti D. sentinel Arahan badan gelung di dalam penyata kurangnya sekali A. do while B. for C. while D, jawapan a dan b -25- while adalah dirujuk sebagai gelung SULIT kerana syarat gelung diuji pada selalu. diproses sekurang- SULIT (BITG 1113) LIT 16, ___membenarkan sesebuah program yang kompleks dan panjang dibahagikan kepada bahagian yang lebih kecil dan senang diuruskan. Pernyataan Fungsi oF > #include directives 9 Struktur pilihan 17. Manakah antara pernyataan berikut TIDAK BENAR mengenai fungs A. la mestilah diakhiri dengan semicolon (; ) B. Dimulakan dengan jenis data rerurn C. Nama fungsi diikuti dengan jenis data return D. Mempunyai opsyen senarai parameter yang ditutupi dengan kurungan ( ). 18, Sebarang objek yang diisytiharkan untuk sesebuah fungsi yang boleh digunakan dari permulaan fungsi hingga akhir program dipanggil? A. Skop setempat B. Skop tidak bersandaran C. Skop global D. Skop bersandaran, 19, Pertimbangkan pernyataan berikut: num = 10 + rand) % (100 - 10 + 1) Jika 53 diumpukkan kepada pembolehubah nun, nilai yang dikembalikan oleh rand ( ) ialah A B. 352 Cc. 323 D. 2500 i -26- SULIT (BITG 1113) SULIT 20, Secara default, _dihantar kepada fungsi ehagai rujukan. A. ints B. double C. tatasusunan D. jenis data primitive 21, Manakah antara penyataan berikut tidak mempunyai kesalahan sintaks? A. int hours £51]= (8,868, 7.5,8, 8.5}; . int scores [ 4] {85 , 92, 91, 88, 76 }: { 400, 300, 125 ty B. C. int sales [7] Dz . char months [ ] = { “jan”, “feb” , “mac” J+ 22. Pembolehubah pertama dalam satu tatasusunan satu dimensi diumpukkan indeks A. NULL oT 0 1 pO 8 23, Prototaip yang manakah adalah untuk satu fungsi yang menerima tatasusunan jer integer dan memulangkan tatasusunan tersebut kepada fungsi yang memanggilnya? A. int function( ); B. int [ ] function( )7 C, void function(int array[ ]); D. void function (ints arrayl 1); 24, Manakah antara klaus while berikut memberi arahan kepada komputer untuk terus membaca fail inventory. txt sehingga akhir fail? intnv adalah nama kepada objek fail A. while (inventory.txt.end( )) B. while (inInv.end( )) C. while (!inInv.eof( }) D. while (!inventory.txt.eof( )) -27- SULIT 26. (BITG 1113) SULIT Anda akan mendefinasikan struktur menggunakan katakunci A. structure B. struct C. rekod D. data Teliti pengisytiharan untuk struktur berikut dan tentukan apa yang menyebabkan akan berlakunya kesalalahan kompilasi structure accounting t iperiod = 2; long 1fiscalYear = 2000; double dcurrTaxRate = 0.15; A. Nama untuk struktur mestilah diikuti dengan kurungan, sama seperti untuk fungsi Anda hanya dibenarkan untuk menggunakan satu jenis data sahaja di dalam definasi struktur C. Pen ytiharan untuk struktur menggunakan katakunei struct D. Tiada sebab yang boleh meyebabkan berlakunya ralat kompilasi . Suatu penuding ‘A. mengandungi data yang disimpan pada satu ruang di dalam ingatan komputer B. mengandungi alamat suatu ruang ingatan di komputer C. boleh digunapakai untuk kenyataan input, tetapi tidak untuk kenyataan output D. boleh diubah kepada nilai-nilai berbeza di kedua-kedua kenyataan input and output -28- SULIT (BITG 1113) SULIT 28. Diberi pengisytiharan di bawah. Manakah pernyataan yang TIDAK DIBENARKAN? D. P= 6x; p= ad; q = ade k = 6p; 29. Yang manakah antara berikut adalah TIDAK BENAR berkenaan penuding? A B. c. D. Penuding berdasarkan kepada jenis piawai alamat Penuding adalah alamat perkakasan Penuding adalah data berjenis terbitan Penuding boleh menjadi pemalar 30, Andaikan a dan b adalah penuding kepada integer dan a menuding kepada satu pembolehubah name. Apakah kesan dari kenyataan pos Rf i name _akan disalin ke b, Alamat ingatan yang disimpan di dalam a disalin ke b Alamat ingatan yang disimpan di dalam b disalin ke a Penuding 2 menuding kepada suatu objek lain, -29. SULIT (BITG 1113) SUL BAHAGIAN C : (40 MARKAH) Jawab SEMUA soalan . SOALAN 1 (10 MARKAH) a) Diberi segmen aturcara seperti di bawah, isikan tempat kosong dengan satu pernyataan untuk mengumpukkan huruf x kepada elemen di baris pertama, lajur kedua di dalam tatasusunan Letters. main() { char letters[3] [3]; 2 markah) b) Isytiharkan dan berikan nilai awal kepada satu tatasusunan berjenis char, bernama alphabets, bersaiz dua baris dan tiga lajur. Elemen-elemen dalam tatasusunan tersebut adalah seperti di bawah: [MTT]E] D str ie ©) Fungsi main( ) berikut menyimpan markah tiga pelajar ke dalam tiga pembolehubah, (2 markah) kemudian men} a dan memaparkan jumlahnya, Ubahsuai fungsi main() tersebut supaya markah-markah disimpan di dalam tatasusunan, main() _ (6 markah) float markl,mark2,mark3, total; cout<<"E ter three s| s' marks: \n"; cin>>mark1>>mark2>>mark3; total arkl+mark2+mark3; cout<>, 5): cin. ignore (100,"\n") i outfile < using namespace std; (1) day (Mon=1,Tues, Wed, F void main() | cout << endl; (2) @) (4); day++) cout <<"\t"< using namespace std; int main() ( int a int b int cf int *p int * qi int* x; 6 27 ab; a= PF r= 6c treat tq + tec couts<* psc” Nectgec” “echrecendl; coutccpec” — Sccqee” “ccrecendl; return 0; } a) Berdasarkan aturcara di atas: a b ce Pe q x Gambarajah 3 i, Apakah nilai terakhir a, b, dan c di Gambarajah 3, SULIT (B markah) ii, p,q, dan rakan menuding kepada apa? Lukis semula Gambarajah 3 dan gunakan anak panah untuk menerangkan jawapan anda. di dalam Gambarajah 3 a = 0x00135760 b = 0x01015879 c = 0x00234781 iv. Tuliskan output untuk aturcara di atas, “34. (3 markah) Berdasarkan alamat-alamat ruang ingatan di bawah, nyatakan nilai terakhir p, q, dan r G markah) (3 markah) SULIT (BITG 1113) SULIT BAHAGIAN D : (20 MARKAH) Jawab SATU (1) soalan sahaja. SOALAN 1 (20 MARKAH) Tulis aturcara yang lengkap bagi masalah berikut: Anda diminta oleh sebuah syarikat jualan kereta terpakai untuk membangunkan satu program yang dapat menentukan harga jualan bagi sebuah kenderaan terpakai. Mengikut polisi harga, sesebuah kereta terpakai yang dijangka dapat dijual dalam masa sebulan atau kurang akan dinaikan harga 10% dari harga kos manakala bagi sesebuah Kereta terpakai yang dijangka berada di bilik jualan Jebih dari sebulan akan dinaikan 20% dari harga kos. Sila pastikan bahawa kenaikan rendah sebanyak 10% adalah digunapakai untuk 30 hari dan pada hari ke- 31 dan berikutnya, keuntungan akan bertukar kepada 20%. Oleh itu program anda boleh menyatakan harga jualan bagi sebuah kereta terpakai Contoh output adalah seperti di dalam Gambarajah 4. TBH Windowsigytemiziemdece This program determines the retail price of a used car] Icnter the cost of the used car :25000 lEnter the expected of days until sold :25 ‘he used car cost = RM 25000 Expected day until sold = 25 days | the retail price = RM 27500 Press any key to continue : Gambarajah 4 -35- SULIT (BITG 1113) SULIT ‘Anda mesti mengaplikasikan teknik pass by value dan pass by reference kepada fungsi-fungsi yang berkaitan, Teliti bahagian aturcara di bawah: [ginclude using namespace std; //declare global constants //declare function prototypes int main() 4 int expected_daysold; double car_cost, retail price: cout<< "\n\tThis program determines the retail price of a used car.\n\n"; get Input (car_cost, expected_daysold): retail_price=calcRetailPrice(car_cost, expected_daysold); displayRetailPrice(car_cost, expected_daysold, retail price); return 0; } //+eeeeeeetonction definition*s*tt // function to get input // function to calculate retail price //function to display the output Program anda mestilah menggunakan TIGA (3) fungsi dengan prototaip seperti berikut: 1. void getInput (doubles cost, ints daysold) fungsi ini menerima dua input iaitu kos dan jangka bilangan hari sehingga dijual. 2. double calcRetailPrice (double cost, int daysold) fungsi ini dipangeil untuk mengira harga jualan bagi sebuah harga kereta terpakai 3. void displayRetailPrice (double cost, int daysold, double price) fungsi ini dipanggil untuk memaparkan harga jualan untuk Kereta terpak 36- SULIT (BITG 1113) SULIT SOALAN 2 (20 MARKAH) Tuliskan program yang membolchkan pengguna untuk memasukkan nama 3. calon pilihanraya dan jumlah undian yang diterima oleh setiap calon, Program tersebut akan memaparkan output berbentuk nama calon, jumlah undi yang diterima dan juga peratusan undi dari keseluruhan jumlah undi, Program anda harus juga memaparkan_pemenang pilibanraya tersebut. Contoh paparan output adalah Candidate ] % of total votes | ~ Razak ~ ~~ 1000 10.00 | : 4000 ae a000) 5000 i ) - ‘The winner of the election Program anda mestilah menggunakan DUA (2) fungsi dengan prototaip seperti berikut: a) int sumVotes (int list[ ] , int size); b) int winnerIndex (int list[ ] , int size); + fungsi sumvotes menerima 2 input: satu tatasusunan fist dan satu integer size, di mana size menunjukkan saiz tatasusunan list + fungsi winnertndex menerima 2 input: satu tatasusunan list dan satu integer size, di mana size menunjukkan saiz.tatasusunan list © gunakan penformatan output di mana sesuai nama dan jumlah undi yang diterima diletakkan di dalam fungsi main ( ) TAMA’ “3T- SULIT

You might also like