Document

Download as pdf or txt
Download as pdf or txt
You are on page 1of 7

C++ Exam - Mobile Native (Alexandria 42) - Time Allowed: 1:45 Hours

Read Carefully the Question It is NOT Allowed to use any digital media It is NOT Allowed to use the internet
Required
1.Name in English:

2.How structures and classes in C++ differ?


(2 Points)
a) In Structures, members are public by default whereas, in Classes, they are private by default
b) In Structures, members are private by default whereas, in Classes, they are public by default
c) Structures by default hide every member whereas classes do not
d) Structures cannot have private members whereas classes can have
3.What will be the output of the following C++ code? #include<iostream.h> class X { int m; public: X() : m(10) { } X(int m
X { int n; public: Y(int nn) : n(nn) {} int getn() { return n; } }; int main() { Y yobj( 100 ); cout << yobj.getm() << " " << yobj.g
(2 Points)
a) 10 100
b) 100 10
c) 10 10
d) 100 100
4.What will be the output of the following C++ code? #include <iostream.h> class BaseClass { protected: int i; public:
lass: public BaseClass { int j; public: DerivedClass(int x, int y): BaseClass(y) { j = x; } ~DerivedClass() { } void show() { cou
dClass ob(3, 4); ob.show(); return 0; }
(2 Points)
a) 3 4
b) 4 3
c) 4
d) 3
5.What will be the output of the following C++ code? #include <iostream.h> class MyInterface { public: virtual void Di
d Display() { int a = 5; cout << a; } }; class Class2 : public MyInterface { public: void Display() { cout <<" 5" << endl; } }; in
; obj2.Display(); return 0; }
(2 Points)
a) 5
b) 10
c) 5 5
d) 15
6.What will be the output of the following C++ code?
#include
class p
{
protected:
int width, height;
public:
void set_values (int a, int b)
{
width = a; height = b;
}
virtual int area (void) = 0;
};
class r: public p
{
public:
int area (void)
{
return (width * height);
}
};
class t: public p
{
public:
int area (void)
{
return (width * height / 2);
}
};
int main ()
{
r rect;
t trgl;
p * ppoly1 = &rect;
p * ppoly2 = &trgl;
ppoly1->set_values (4, 5);
ppoly2->set_values (4, 5);
cout << ppoly1 -> area() ;
cout << ppoly2 -> area();
return 0;
}
(2 Points)
a) 1020
b) 20
c) 10
d) 2010
7.What will be the output of the following C++ code? #include <iostream.h> #include <string.h> class A { float d; publ
class B: public A { int a = 15; public: void func(){ cout<<"Hello this is class B\n"; } }; int main() { A *a; a->func(); return 0
(2 Points)
a) Hello this is class A
b) Hello this is class B
c) Error
d) Unexpected Execution
8.Virtual functions in C++ tells the compiler to perform ______________________ on such functions.
(2 Points)
a) static binding
b) late binding
c) compile time binding
d) no binding
9.Which of the following is correct?
(2 Points)
a) Base class pointer object cannot point to a derived class object
b) Derived class pointer object cannot point to a base class object
c) A derived class cannot have pointer objects
d) A base class cannot have pointer objects
10.Why references are different from pointers?
(2 Points)
a) A reference cannot be made null
b) A reference cannot be changed once initialized
c) No extra operator is needed for dereferencing of a reference
d) All of the mentioned
11.How many types of polymorphism are there in C++?
(2 Points)
a) 1
b) 2
c) 3
d) 4
12.What is the difference between delete and delete[] in C++?
(2 Points)
a) delete is used to delete normal objects whereas delete[] is used to pointer objects
b) delete is a keyword whereas delete[] is an identifier
c) delete is used to delete single object whereas delete[] is used to multiple(array/pointer of) objects
d) delete is syntactically correct but delete[] is wrong and hence will give an error if used in any case
13.What will be the output of the following C++ code? #include <iostream.h> class A { int a; A() { a = 5;} }; int main() { A
(2 Points)
a) 5
b) Garbage value
c) Compile-time error
d) Run-time error
14.What is dynamic binding?
(2 Points)
a) The process of linking the actual code with a procedural call during run-time
b) The process of linking the actual code with a procedural call during compile-time
c) The process of linking the actual code with a procedural call at any-time
d) All of the mentioned
15.Which of the following is correct about this pointer in C++?
(2 Points)
a) this pointer is passed as a hidden argument in all the functions of a class
b) this pointer is passed as a hidden argument in all non-static functions of a class
c) this pointer is passed as a hidden argument in all static functions of a class
d) this pointer is passed as a hidden argument in all static variables of a class
16.What will be the output of the following C++ code? #include <iostream.h> int main() { int a = 5, b = 10, c = 15; int *
(2 Points)
a) 5
b) 10
c) 15
d) it will return some random number
17.What will be the output of the following C++ code? #include <iostream.h> int main() { char *ptr; char Str[] = "abcde
(2 Points)
a) fg
b) cdef
c) defg
d) abcd
18.int result(int n)
{
if (n == 1)
return 2;
else
return 2 * result(n - 1); }
What value does result(5) return?
(2 Points)
a) 64
b) 32
c) 16
d) 8
e) 2
19.Consider the following class:
class Test
{
public:
int x;
Test(){x=0;}
Test(int y)
{
x=y++;
}
Test(Test &r)
{
x=++r.x;
}
void print ()
{
cout<<x;
}
};
void main()
{
Test t(1);
t.print();
Test x(t);
x.print();
t.print();
}
What is the output of the previous program?
(2 Points)
121
122
222
233
20.What will be the output of the following C++ code? #include <iostream.h> int main() { int a[2][4] = {3, 6, 9, 12, 15, 1
]]; return 0; }
(2 Points)
a) 15 18 21
b) 21 21 21
c) 24 24 24
d) Compile time error
21.What will be the output of the following C++ code? #include <iostream.h> int main () { int numbers[5]; int * p; p =
numbers + 3; *p = 40; p = numbers; *(p + 4) = 50; for (int n = 0; n < 5; n++) cout << numbers[n] << ","; return 0; }
(2 Points)
a) 10,20,30,40,50,
b) 1020304050
c) compile error
d) runtime error
22.What will be the Output of the following Code:
int * GetMin(int ar[5]);
int main ()
{
int *ptr;
int X[5] = {12, 18, -11, -20, 3};
ptr = GetMin(X);
printf(%d, *ptr);
return 0;
}
int * GetMin(int ar[5])
{
int min, I;
min = ar[0];
for(I = 1 ; I < 10 ; I++)
{
if(ar[I] < min)
{
min = ar[I];
}
}
return &min;
}
(2 Points)
a) -20
b) Function cant return address
c) No value will be printed
d) There is a value that we dont know appear on the screen
23.What will be the output of the following C++ code? #include <iostream.h> void swap(int &a, int &b); int main() { int
rn 0; } void swap(int &a, int &b) { int temp; temp = a; a = b; b = temp; cout << "In swap " << a << b; }
(2 Points)
a) In swap 105 In main 105
b) In swap 105 In main 510
c) In swap 510 In main 105
d) In swap 510 In main 510
24.What is the difference between references and pointers?
(2 Points)
a) References are an alias for a variable whereas pointer stores the address of a variable
b) References and pointers are similar
c) References stores address of variables whereas pointer points to variables
d) Pointers are an alias for a variable whereas references stores the address of a variable
25.#include
int f(int &x, int c)
{
c = c - 1;
if (c == 0)
return 1;
x = x + 1;
return f(x, c) * x;
}
int main()
{
int a = 4;
cout<<f(a,a);
(2 Points)
a) 343
b) 336
c) 120
d) 840
26.What will be the output of the following C++ code? #include <iostream.h> struct Time { int hours; int minutes; int
rs = 5; t.minutes = 30; t.seconds = 45; cout << "Total seconds: " << toSeconds(t) << endl; return 0; } int toSeconds(Tim
onds; }
(2 Points)
a) 19845
b) 20000
c) 15000
d) 19844
27.#include <iostream>
class Person
{
protected:
int id;
public:
Person(int i)
{
id = i;
}
Person(Person &p)
{
id = p.id;
}
int GetId()
{
return id;
}
void SetId(int m)
{
id = m;
}
};

class Employee: public Person


{
int salary;
public:
Employee(int i, int s) :Person(i)
{
salary = s;
}
Employee(Employee &e)
{
salary = e.salary;
}
int GetSalary()
{
return salary;
}
void SetSalary(int m)
{
salary = m;
}
};

Employee FillEmp()
{
Employee em(3, 4);
return em;
}

int main()
{
Employee emp(7, 8);
emp = FillEmp();
cout << emp.GetId() ;
cout << emp.GetSalary() << endl;
return 0;
}
What is the output of the previous program?
(2 Points)
34
78
Compile error
Non of the above
28.What will be the output of the following C++ code? #include <iostream.h> int main () { int n; for (n = 5; n > 0; n--) {
(2 Points)
a) 543
b) 54
c) 5432
d) 53
29.What will be the output of the following C++ code? #include <iostream.h> void Sum(int a, int b, int & c) { a = b + c;
y, y); cout << x << " " << y; return 0; }
(2 Points)
a) 2 3
b) 6 9
c) 2 15
d) compile time error
30.What will be the output of the following C++ code? #include <iostream.h> int func(int m = 10, int n) { int c; c = m +
(2 Points)
a) 15
b) 10
c) compile time error
d) 30
31.What will be the output of the following C++ code? #include <iostream.h> int func(int m , int n = 10) { int c; c = m +
{ cout << func(5); return 0; }
(2 Points)
a) 15
b) 11
c) compile time error
d) 30
32.What will be the output of the following C++ code? #include <iostream.h> class rect { int x, y; public: void val (int, i
t a, int b) { x = a; y = b; } int main () { rect Rect; Rect.val (3, 4); cout << "rect area: " << Rect.area(); return 0; }
(2 Points)
a) rect area: 24
b) rect area: 12
c) compile error
d) rect area: 56
33.What will be the output of the following C++ code? #include <iostream.h> class CDummy { public: int isitme (CDum
this) return 1; else return 0; } int main () { CDummy a; CDummy *b = &a; if (b->isitme(a)) { cout << "execute"; } else { c
(2 Points)
a) execute
b) not execute
c) error
d) both execute & not execute
34.Which of the following, when used as the /* body */ of method sum, will enable
that method to compute 1 + 2 + + n correctly for any n > 0?
//return 1 + 2 + ... + n

int sum(int n)
{
/* body */
}
I) return n + sum(n - 1);
II) if (n == 1)
return 1;
else
return n + sum(n - 1);
III) if (n == 1)
return 1;
else
return sum(n) + sum(n - 1);
(2 Points)
a) I only
b) II only
c) III only
d) I and II only
e) I, II, and III
Never give out your password.Report abuse
This content is created by the owner of the form. The data you submit will be sent to the form owner. Microsoft is no
mers, including those of this form owner. Never give out your password.
Powered by Microsoft Forms
|
The owner of this form has not provided a privacy statement as to how they will use your response data. Do not pro
| Terms of use

You might also like