Você está na página 1de 6

U IVERSITY COLLEGE OF THE CARIBBEA

Member of the OAS & Commonwealth Consortia of Universities

ASSOCIATE OF SCIE CE DEGREE I MA AGEME T I FORMATIO SYSTEMS GROUPS: K12 [eve] E D OF MODULE EXAMI ATIO
CE TRE MODULE DATE TIME DURATIO : OXFORD TERRACE CAMPUS : OBJECT ORIE TED PROGRAMMI G C++ [ITT 200] : DECEMBER 18, 2008 : 10:00 AM : 3 HOURS

I STRUCTIO S: 1. 2. 3. Please read all instructions carefully before attempting any question. This paper consists of seven (7) printed pages and four (4) sections [A, B, C & D]. Sections [A, B C & D] are compulsory.

4. No electronic devices capable of storing and retrieving text,

including electronic dictionaries, calculators may be used


ALL QUESTIONS MUST BE ANSWERED IN THE ANSWER BOOKLET PLEASE ENSURE THAT YOU NUMBER YOUR QUESTIONS CORRECTLY. CLEARLY WRITE THE NUMBER OF THE QUESTION ON EACH OF THE RELEVANT PAGES. WHERE QUESTIO S HAVE MULTIPLE PARTS, ALL PARTS MUST BE A SWERED. START THE RESPO SE TO EACH QUESTIO O A EW PAGE.

Write your REGISTRATIO UMBER clearly on each page of your answer booklet. DO OT WRITE YOUR AME. B. Your script will not be marked if it has your name.

DO NOT TURN OVER UNTIL YOU ARE TOLD TO DO SO


Page 1 of 6

SECTION A
Answer ALL questions in this section. Each question worth 3 marks. 1. What is the purpose of the line below: using namespace std; 2. Which of the following declaration are illegal: int 44; int last?; int NextNumber; int round-up; int the_cats_paws; int main; 3. What will be output by the following code fragment: char * s1 = pear; char * s2 = pear; int cmp = strcmp(s1,s2); cout<<cmp; 4. How many numbers will be printed in the following if the value of n is 22. a. if( n <20) cout<<n<< ; cout<< 2 * n<<endl; b. if( n >20) cout<<n<< ; else cout<< 2 * n<<endl; cout<< 3 * n<<endl;

5. Find the error in the following loop: a. for( int i =1, i<=7, i++) { cout<<1.0/i<<endl; } b. while(n < 20); { cout<<n++<<endl; }

Page 2 of 6

SECTION B
Answer ALL questions in this section. Each question worth 4 marks. 6. Locate the error in the program and classify it as either a syntax error, compile error, a run-time error or a logical error. #include<iostream> using namespace std; int main() { int a +=22; cout<<a<<endl; } 7. What is wrong with the following code fragment? int x = 10; cout>>Enter x : ; cin<<x; 8. Consider the following code fragment: int data [5]; for (int i=1; i<=6; i++) { data[i]=i; } This compiles without error but what is the problem with this code? 9. Consider the following code fragment: string s; int* i; s = Fred Jones; i = &s; cout << *i; This will not compile briefly explain why, and suggest a single change that will fix this problem.

10. When you attempt to compile a program containing the following line of code it gives a warning: double point = 12.65; int coordinate; coordinate = point; Suggest ONE way in which this problem could be fixed.

Page 3 of 6

SECTION C
Answer ALL questions in this section. Each question worth 5 marks. 11. Draw picture to show the effect of the following code: double * p = new double; *p = 3.141592653589793; short * q = new short [5]; *q = 44; *(q + 4) = 88;

12. Consider the following code. What will be printed to the screen? class Vehicle { public: void display() { cout<<This is the Vehicle display class<<endl; } }

class Car: public Vehicle { public: void display() { cout<<This is the Car display class<<endl; } } int main() { Vehicle v1; Car car1; Vehicle *p = &v1; pdisplay(); p = &car1; pdisplay(); }

Page 4 of 6

13. Consider the following code. What does the code fragment do and what is the output? void print_binary(int n) { if (n>2) print_binary(n/2); cout<<n%2; } int main() { print_binary(14); }

14. If x has the address 0x3fffd1c, then what will be the value of the variables after each of the following code is executed. int x = 32; int * p = &x; int & r = x; int * q = p; int n = (*p)++; r = *(--p) + 1; a. x b. n c. r d. *p e. *q

15. Describe or give the output of what each line of code does: string s = ABCDEFGHIJKLMNOP; cout<<s.length(); s[8] = !; s.replace(8,5, xyz); cout<<s.find(!);

Page 5 of 6

SECTION D
Answer ALL questions in this section. Each question worth 8 marks. 16. Write a for statement that outputs the even numbers in the range 2 to 20, each on a separate line.

17. Write a Person class interface. Each object of this class will represent a human being. Data members should include the persons name, year of birth and year of death. Include a default constructor, a destructor, accessor functions are name, born and died and print function for its data members. 18. Write statements for each of the following: a. Initialize a pointer p to point to a Person object x. b. Assign the Person object y to the object to which p points. c. Initial a reference r to the Person object x. d. Declare a static array myarray of 8 string objects. e. Declare a dynamic array larray of 8 string objects.

19. Write a function called CalAvg to calculate the average of two integer values. 20. Write a recursive function that returns the power xn, using the following code algorithm below as a guide. float power( float x, int n) { //return 1 if n is equal to 0 // calculate and call the recursive function }

END OF QUESTION PAPER

Page 6 of 6

Você também pode gostar