You are on page 1of 4

Page 1 of 4 PAPER REF.

NO
[QUESTION PAPER] TITLE: PROGRAMMING IN C++

Name:……………………………………………..
(COSC206) Matric. No:………………………………………
SEMESTER EXAM: 2nd
SESSION: 2019/2020 Time Allowed: 2
Hours
EXAMINERS:.
INSTRUCTION: Attempt Questions

(1) Function responsible for creating new objects (9)Which of the following is a valid class declaration?
when required is called: (a) class A { int x; }; (b) class B { }
(a) main() (b) inline (c) constructor (d) destructor (c) public class A { } (d) object A { int x; }
(2) What is the description of the following object- (10) Which constructor will initialize the base class
oriented language feature: double daisy(int d, double data member?
f) and double daisy(long l, int b) : (a)derived class (b) base class (c) class (d) None of
above
(a) inheritance (b) overloading (c) overriding
(d) encapsulation
3). Assuming variable num starts with value 10, what 11). What is the output of the flowing code chunk:
would the following code fragment print out? {
int num = 10; int a = 5;
cout << num + +; int b = 10;
cout << (a > b? a : b);
(a) 9 (b) 10 (c) 11 (d) nil }
(a) 5 (b) 10 (c) 15 (d) 50
4).If int sum = 21 and int val = 3. What is the final 12). ____ & ____ are the two ways by which
value of sum from the expression: arguments can be passed into a function when it is
sum+=val called.
(a) parameter passing & value passing (b) pass-
(a) 19 (b) 7 (c) 24 (d) 63 by value & pass-by-reference (c) pass-by-value &
pass-by-variable (d) data type & pass-by-reference
(5) What is the meaning of the following symbols in a (13) The fields in the class in C++ program are by
default:
UML class diagram: minus sign (-)
(a) protected (b) private (c) public (d) abstract (a) protected (b) private (c) public (d) abstract

(6) Which operator is used to define a function (14) What is the result of the following code listing :
outside the scope of its class: int item = 10;
int *Ptr = &item;
(a) . (b) & (c) :: (d) ~ cout<<” \nThe output: ”<<(*Ptr + 10)<<endl;

(a) 100 (b) 10 (c) 20 (d) *Ptr + 10

7). A function prototype specifies----------------- and 15) A helper function known to and seen by only
------------------------- members of its class should be defined as:
(a) function and parameter (b) function type and (a) protected (b) local (c) private (d) public
parameter (c) function name and parameter list
(d) function call and function definition
8) Keyword used in defining a symbolic 16) A function returning no value is declared as:
constant in C++ programing is: (a) void (b) static (c) return (d) default
(a) const (b).#define (c) a and b (d) <iostream>
Page 2 of 4 PAPER REF. NO
17). Two functions having the same signatures but (24) If a discount of 5% is given for buying
different implementation as a C++ feature is called: mayonnaise, what is the logic for amount paid:
int wages(double a){…} (a) amtPaid = totalCost – 5 * totalCost
int wages(double b){…} (b) amtPaid = totalCost – 0.5 * totalCost
(c) amtPaid = totalCost – 0.05 * totalCost
(a) inheritance (b) overloading (c) overriding (d) amtPaid = totalCost – 5 / totalCost
(d) encapsulation

(18) Wrapping data and its related functionality into a (25) Pick the odd one out.
single entity is known as: a) integer, character, boolean, floating
a) Abstraction b) Encapsulation b) enumeration, classes
c) Polymorphism d) Modularity c) integer, enum, void
d) arrays, pointer, classes
19) What happens to a line of code written after return (26) Which class strictly represents reading from files:
statement…………………………….
(a) unreachable (b) commented (c) deleted (a) ifstream (b) ofstream (c) fstream (d) ios
(d) returned
20) What is the output if integer values 2 is received by 27) . In the following code, what is the output from
variable choice in the following code: cout if cin is used to read in the following string data:
cin>>choice; “object think”
switch(choice){
Case 1: cout<<"Hey "; break; #include <iostream>
Case 2: cout<<" How "; using namespace std;
Case 3: cout<<" Coding”; break; int main()
default: cout<<"\n Out of Range"; {
} string name;
cin >> name;
(a) Hey (b) How (c) Coding (d) How Coding cout <<name;
}
(a) object (b) think (c) object think (d) o
21). Considering the following variable and pointer (28) Consider the following code chunk and find the
initialization, what statement would print the value of value of quotient:
count? int dividend, divisor, quotient;
int count = 25; dividend = 7;
int *countPtr = &count; divisor = 2;
(a) cout<< countPtr; (b) cout<< &countPtr; quotient = dividend / divisor;
(c) cout<<*countPtr; (d) cout<<countptr; (a) 3.5 (b) 3.0 (c) 3 (d) 3.50
22) Consider the following array definition: 29) What are the actual parameters in C++?
char school[ ] = "Babcock"; a) Parameters with which functions are called
What is the element in school[2]……… b) Parameters which are used in the definition of a
(a) a (b) b (c) B (d) A function
c) Variables other than passed parameters in a
function
d) Variables that are never used in the function

23). What is wrong with the following function call: 30) How do you describe the following operation in
the code block:
int costOfall(int x, string y, double z) //declaration { temp = x;
costOfall(20, 34.8, “Gowon Estate”); // function call x= y;
y = temp; }
(a) parameter type (b) function type (a) assignment (b) insertion
(c) function name (d) return type (c) swap (d) override
(31) Which of the following is not a type of 37) What is the final value of sum in the following
Page 3 of 4 PAPER REF. NO
Constructor? code chunk
a) Friend constructor b) Copy constructor { int n, sum = 0;
c) Default constructor d) Parameterized constructor for (n = 1; n <= 3 ; n++,n++)
sum = sum + n;
}
(a) 4 (b) 9 (c) 120 (d) 3
32) Which of the following statements are true? (38) What is the output of the following
int f(float) #include <iostream>
a) f is a function taking an argument of type int and using namespace std;
returning a floating-point number class Box
b) f is a function taking an argument of type float and {
returning an integer public :
c) f is a function of type float int length;
d) f is a function of type int int breadth;
};
int main( )
{
Box box;
cout<<box.length;
}
(a) null (b) 0 (c) 1 (d) length

33) Identify the user-defined types from the (39) What does the following declaration/initialization
following? also imply: double blend(32.5);
a) enumeration
b) classes (a) double blend = 32.5; (b) double 32.5 = blend;
c) both enumeration and classes (c)double blend; (d) blend = 32.5;
d) int
(34) Which of these following members are not (40) What will be the new value of x in the following
accessed by using direct member access operator? C++ code?
a) public #include <iostream>
b) private using namespace std;
c) protected void fun(int &x)
d) both private & protected {
x = 20;
}
int main()
{
int x = 10;
fun(x);
cout << "x = " << x;
return 0;
} (a) 10 (b) 20 (c) 2 (d) 0
(35) By default how the value are passed in C++?
a) call by value
b) call by reference
c) call by pointer
d) call by object
(36) State a benefit of inheritance in Object Oriented
programming paradigm:
(a) information hiding (b) encapsulation
(c) reusability (d) objects
;
Page 4 of 4 PAPER REF. NO

You might also like