Final_01_fall

Final_01_fall - 19 December 2001 COMP 102 Final Exam Page 1...

Info iconThis preview shows pages 1–4. Sign up to view the full content.

View Full Document Right Arrow Icon
19 December, 2001 COMP 102 -- Final Exam Page 1 of 16 THE HONG KONG UNIVERSITY OF SCIENCE AND TECHNOLOGY Department of Computer Science COMP 102: Computer and Programming Fundamentals I Fall 2001 Final Examination Version A Date: 19 December 2001 Time: 12:30-3:30 pm Venue: Hall This exam contains 10 questions in 16 pages. Please count the pages. You have 3 hours to complete this exam. Problem Your point s Max point s Problem Your point s Max point s 1 6 6 5 2 10 7 5 3 10 8 10 4 15 9 10 5 10 10 19 Subtotal 51 Subtotal 49 Your total points 100 Please identify yourself: Lecture/Lab section Name Student ID Signature
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
19 December, 2001 COMP 102 -- Final Exam Page 2 of 16 1. (6 points) For each of the follow C++ code segments, mark it with “CORRECT” if it is correct and “WRONG” if it is NOT correct. You should consider both syntax and logical correctness. ________a)int array[4] ={ 0, 1, 2, 3, 4 }; _________b)int x[5]; x[0] = 0; _________c)void fn (const int x[ ] ) { if ( x[0] < 0) x[0] = 0; } _________d)char message[ ] = "Hello"; _________e)char message[6]; message = "Hello"; _________f)int array[2,3];
Background image of page 2
19 December, 2001 COMP 102 -- Final Exam Page 3 of 16 2. (10 points) The following program shows the result of a battle between the Taliban and Pashtun tribesmen in Afghanistan. The function call count(taliban) uses enumeration to store the values in the taliban array. What will the report function print on the screen? #include <iostream.h> #include <string.h> enum {totalfighters, fighters, prisoners, dead, totaldead}; const int FIGHTERS = 500; void count(int army[]); // This function produces the values {221, 31, 19, 11, 160} when it is // called with the taliban array. // The values are {452, 146, 35, 39, 121} for the pashtun array. void report(int army[], char name[], char city[]){ cout << "Current " << name << " dead: " << army[dead] << endl; cout << "Current " << name << " prisoners: " << army[prisoners] << endl; cout << "Remaining " << name << " fighters in " << city << ": " << army[fighters] << endl; cout << "The " << name << " has lost " << army[totaldead] << " fighters." << endl; cout << "Total remaining " << name << " fighters: " << army[totalfighters] << endl << endl; } int main () { int taliban[5] = {FIGHTERS, 0, 0, 0, 0}; int pashtun[5] = {FIGHTERS, 0, 0, 0, 0}; count(taliban); report(taliban, "Taliban", "Kandahar"); count(pashtun); pashtun[totalfighters] += taliban[prisoners]; report(pashtun, "Pashtun", "Kandahar"); return 0; } Answer: Complete the following output produced by the report function: Current Taliban dead: __________ Current Taliban prisoners: __________ Remaining Taliban fighters in Kandahar: __________ The Taliban has lost __________ fighters. Total remaining Taliban fighters:
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
Image of page 4
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

Page1 / 16

Final_01_fall - 19 December 2001 COMP 102 Final Exam Page 1...

This preview shows document pages 1 - 4. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online