Page 1 Q 1.How many values can be returned b y a C++ function? 1 Infinity 0 None of the Above Q 2.Virtual functions are defined in Derived class Base class Both A and B None of the Above Q 3.cin in C++ program uses the operator>> < << > Q 4.Which of the following denotes advantages of operator overloading? Operator not limited to operate only with primitive Data Type Extensibility Both A and B None of the Above Q 5.The friend function of a class i n C++ can access Private members of the class protected members of the class Both A and B None of the Above Q 6.When dynamically allocated memory is lost to the C++ program then warning occurs memory leak occurs The program does not executes successfully None of the above
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
7/27/2019 Inclass Test
http://slidepdf.com/reader/full/inclass-test 1/14
Page 1
Q 1. How many values can be returned by a C++ function?
1
Infinity
0
None of the Above
Q 2. Virtual functions are defined in
Derived class
Base class
Both A and B
None of the Above
Q 3. cin in C++ program uses the operator
>>
<
<<
>
Q 4. Which of the following denotes advantages of operator overloading?
Operator not limited to operate only with primitive Data Type
Extensibility
Both A and B
None of the Above
Q 5. The friend function of a class in C++ can access
Private members of the class
protected members of the class
Both A and B
None of the Above
Q 6. When dynamically allocated memory is lost to the C++ program then
warning occurs
memory leak occurs
The program does not executes successfully
None of the above
7/27/2019 Inclass Test
http://slidepdf.com/reader/full/inclass-test 2/14
Page 2
Q 7. The operator that denotes address of a variable in C++ program is
*
%
$
&
Q 8. The overriding method must have the which of the followingsame as that of the method in the super class definition
same identifier
same signature
Both A and B
None of the Above
Q 9. Which of the following is used in C++ to create a copy of an object?
Assignment operator
Copy constructor
Both A) and B)
None of the Above
Q 10. Which of the following is used to group a set of global classes,
objects and functions under a name?
Area named
Namearea
Namespaces
None of the above
Q 11. Inheritance in C++ have default access specifier as
Private
Public
Protected
None of the Above
Q 12. The members of a class are by default
Private
Public
Protected
None of the Above
Q 13.
7/27/2019 Inclass Test
http://slidepdf.com/reader/full/inclass-test 3/14
Page 3
// All the necessary libraries have been included
// Consider the following code:
void swap(int& a, int b)
{
long temp;
temp=a;
a=b;
b=temp;
}
// If we have int x = 5 and y = 3,
// what are values of x and y after swap(x,y) being called?
x=3, y=3
x=5, y=3
x=3, y=5
x=5, y=5
Q 14.
// All the necessary libraries have been included
// Consider the following code:
void g(int& a) {
a = 13 ;
}
int f() {
int a = 42 ;
g( a ) ;
return a ;
}
// What value is returned if f() is called?
13
42
0
There is a compile error in the code
Q 15.
void f() {
7/27/2019 Inclass Test
http://slidepdf.com/reader/full/inclass-test 4/14
Page 4
int *p = new(nothrow) int ;
if ( p!=0 ) {
*p = 99 ;
delete p ;
cout << *p << endl ;
}
}
// What value is printed if f() is called?
Unknown value
99
0
The code has a compile error
Q 16.
// All the necessary libraries have been included
// Consider the following code:
void f() {
int *p = new(nothrow) int ;
if ( p!=0 ) {
*p = 99 ;
delete p ;
p = NULL;
cout << *p << endl ;
}
}
// What value is printed if f() is called?
The program will crash
99
0
NULL
Q 17.
// All the necessary libraries have been included
// Consider the following code:
void f() {
7/27/2019 Inclass Test
http://slidepdf.com/reader/full/inclass-test 5/14
Page 5
int x = 10;
int* const p = &x;
*p = 5;
cout << *p << endl;
}
// What value is printed if f() is called?
5
10
0
The code has a compile error.
Q 18.
// All the necessary libraries have been included
// Consider the following code:
void f() {
int x = 10;
int y = 20;
int* const p = &x;
*p = 5;
p = &y;
cout << *p << endl;
}
// What value is printed if f() is called?
The code has a compile error.
5
20
0
Q 19.
// All the necessary libraries have been included
// Consider the following code:
void f() {
const int x = 10;
const int* p = &x;
*p = 5;
ko thay doi bien
7/27/2019 Inclass Test
http://slidepdf.com/reader/full/inclass-test 6/14
Page 6
cout << *p << endl;
}
// What value is printed if f() is called?
The code has a compile error.
5
10
0
Q 20.
// All the necessary libraries have been included
// Consider the following code:
class A {
int x, y;
public:
void fa(int a) {
cout << a + x + y;
}
};
class B : public A {
public:
void fb() {
A a;
a.x = 3;
a.y = 5;
a.fa(10);
}
};
// What value is printed if fb() method of class B is called?
The code has a compile error
18
10
0
Q 21.
private
7/27/2019 Inclass Test
http://slidepdf.com/reader/full/inclass-test 7/14
Page 7
// All the necessary libraries have been included
// Consider the following code:
class A {
int x, y;
public:
void fa(int a) {
cout << a + x + y;
}
friend class B;
};
class B : A {
public:
void fb() {
A a;
a.x = 3;
a.y = 5;
a.fa(10);
}
};
// What value is printed if fb() method of class B is called?
18
10
0
The code has a compile error.
Q 22.
// All the necessary libraries have been included
// Consider the following code:
class A {
protected:
int x, y;
public:
void fa(int a) {
cout << a + x + y;
7/27/2019 Inclass Test
http://slidepdf.com/reader/full/inclass-test 8/14
Page 8
}
};
class B : public A {
public:
void fb() {
A a;
a.x = 3;
a.y = 5;
a.fa(10);
}
};
// What value is printed if fb() method of class B is called?
The code has a compile error.
10
0
18
Q 23.
// All the necessary libraries have been included
// Consider the following code:
class A {
int x, y;
public:
void fa(int a, int b) {
cout << a + b;
}
void fa(double a, double b) {
cout << a + b;
}
void fa(int a, double b) {
cout << a + b;
}
};
// What value is printed if the following code is executed?
7/27/2019 Inclass Test
http://slidepdf.com/reader/full/inclass-test 9/14
Page 9
// A a; a.fa(2, 3.2);
5.2
5
0.2
The code has a compile error.
Q 24.
// All the necessary libraries have been included
// Consider the following code:
class A {
int x, y;
public:
void f() {
cout << "father";
}
};
class B : public A {
public:
void f() {
cout << "son";
}
};
// What value is printed if the following code is executed?
Q 30: If class A inherits from class B, which inherits from class C, what is the order of calling constructors and destructors?
Q 31: class Student has 2 private members: int age, string address. The Student class has a constructor that takes age and addrarguments.
Implement an overloaded assignment operator that allows comparing two objects of the Student class. The two student’s objeare equal if both their age and address are equal.