You are on page 1of 7

Student ID: U16____________

Object Oriented Programming I


Final Exam, fall 2016
Maximum Time: 90 min Total Points: 60

STUDENT INFORMATION:
Note: Provide the following information (Use capital letters).

Name SOLUTIONS Student’s Signature

Student ID 0000
Group # in OOP1 000
___________________________________________________________________
SPECIAL INSTRUCTIONS:
1. Negative Points: 2 points will be deducted from the total points in the following cases
 Incomplete, Incorrect, unclear Student Information.
 Final Answers written with Pencil.
2. All answers should be written in the space provided for each question.
3. Calculators are not allowed.
4. Exchange of any object including eraser, pen, ruler etc. is strictly forbidden during exam.

3
Student ID: U16____________

Q. 1 Write the correct choice (the most appropriate answer) in the table given below. [1x15 Point]

Q# 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15

Answer

1. When we pass two-dimensional array parameters to function, Size of first dimension of array is not required but Size
of second dimension is required.
a. True b.False

2. Which of following Reduce function-call overhead


a. Inline function b. Function overloading
c. Recursive function d. Template function

3. Which one of following convenient for situations in which the “same” function is needed for different numbers or
types of arguments
a. Inline function b. Function overloading
c. Recursive function d. Default argument

4. Template is generic way to make overloaded functions


a. True b. False

5. Name of an array is
a. A constant pointer b. Address of the first element of array
c. A non-constant pointer d. Both a and b

6. Life time of an automatic storage class is the execution time of local function in which it is declared.
a. True b. False

7. Register variable is good for often-used items (loop counters)


a. True b. False

8. Scope of a Global variable is


a. Function Scope b. Main Scope
c. Function prototype scope d. File Scope

9. Both Static variable and Static arrays are initialized to 0 by default


a. True b. False

4
Student ID: U16____________

10. In call by value parameter passing


a. Pointers to data (argument’s value) is passed to the called function
b. Copy of data (argument’s value) is passed to the called function
c. Reference to data (argument’s value) is passed to the called function
d. None of these

11. In call by reference parameter passing


a. Function cannot directly access original parameter data
b. Original parameter data cannot be modified by the called function
c. Function can directly access original parameter data
d. None of these

12. char str[ ]=”TASHKENT”;


cout<<strlen(str);
a. 7 b. 8
c. 9 d. Infinite

13. Which of the following operator use to access members (fields) of structure.
a. ; (Semicolon) b. . (Dot)
c. : (colon) d. , (coma)

14. Structure is heterogeneous (It can be composed of data of different types).


a. True b. False

15. Which of the following is the correct way of declaring a three dimensional array (2x3x4 dimensions)
a. int array[[3][4]] b. int array[2, 3, 4]
c. int array[2][3][4] d. int array[2,3][4]

5
Student ID: U16____________

Q. 2. Write the OUTPUT of the following Code, if there is any Syntax Error, mention the error.
[15 Points]

III. [1 points]

I. [2 Points]

Output: 7 9 11

Output:

A IV.
of the following pointer/array operations are invalid [2 P
U

II. [2 points]

Output:

Invalid Operations:

//p2=&a;

//*p1=*p2;

//*p1=10;

//p2++;

6
Student ID: U16____________

//array++;

V. [1 Points]

Output:
Output: Line # 9:__________________
Line # 10:_______1

Line # 11:_______2 Line # 10:__________________


Line # 12:_______2

Line # 13:_______3 Line # 11:__________________


VI. [4 points]

Line # 12:__________________

VII. [3 points]

7
Student ID: U16____________

Output:

Line # 29:__________________23

Line # 31:__________________32

Line # 33:__________________23

8
Q. 3. Write function definitions for the following function. [15 Points]

Note: Choose appropriate data types for the arguments and return type, and use constant (const), wherever
required.

1. Write a function that takes a string as parameter, and replace Lowercase characters in the string by Uppercase
and Uppercase by lowercase. [5 Points]
Example: String “INHA Tashkent123” replace to “inha tASHKENT123”

2. Write a recursive function POWER( base, exponent) that takes base and exponent as parameters and return
baseexponent
Assume that exponent is an integer greater than or equal to 1. [5 Points]
Hint: base case: base1 = base

3. Write a function that takes two dimension array of size 3x3 (rows x column), and return the sum of its
diagonal elements. [5 points]
Hint: Sum of the diagonal elements for the matrix given below is: 1+2+0=3

Q. 4. Write a C++ program that multiply two 3x3 matrices. The program should include the following functions. [15
Points]

 InputMatrix(): Takes the elements of a two dimensional matrix from the user. [3points]
 DisplayMatrix(): Display the elements of a two dimensional matrix. [3 points]
 MultiplyMatrices(): Multiply two matrices, store the result in a 3rd matrix. [6 points]

Call these functions in the appropriate order to take input matrices, multiply it and display the result. [3 Points]

You might also like