1. What is the use of function call operator?
A. overloading the methods
B. overloading the objects
C. overloading the parameters
D. overloading the string
Answer: B
Explanation:
Overloading the objects is the use of function call operator.
2. Pick out the correct statement.
A. virtual functions does not give the ability to write a templated function
B. virtual functions does not give the ability to rewrite a templated function
C. virtual functions does give the ability to write a templated function
D. virtual functions does not give the ability to rewrite a simple function
Answer: A
Explanation:
Virtual functions does not give the ability to write a templated function.
3. What will happen when the function call operator is overloaded?
A. It will not modify the functions
B. It will modify the functions
C. It will modify the object
D. It will modify the operator to be interpreted
Answer: D
Explanation:
It will modifies how the operator is to be interpreted when applied to objects of a given type.
4. What will be the output of the following C++ code?
#include
using namespace std;
class Distance
{
private:
int feet;
int inches;
public:
Distance()
{
feet = 0;
inches = 0;
}
Distance(int f, int i)
{
feet = f;
inches = i;
}
Distance operator()(int a, int b, int C.
{
Distance D;
D.feet = a + c + 10;
D.inches = b + c + 100 ;
return D;
}
void displayDistance()
{
cout << feet << inches << endl;
}
};
int main()
{
Distance D1(11, 10), D2;
cout << "First Distance : ";
D1.displayDistance();
D2 = D1(10, 10, 10);
cout << "Second Distance :";
D2.displayDistance();
return 0;
}
A. First Distance : 1110
Second Distance :30120
B. First Distance : 110
Second Distance :3020
C. First Distance : 1115
Second Distance :30125
D. pre> First Distance : 100
Second Distance :30120
Answer: A
Explanation:
We are calculating the foot and inches by using the function call operator.
5. What will be the output of the following C++ code?
#include
using namespace std;
void duplicate (int& a, int& b, int& C.
{
a *= 2;
b *= 2;
c *= 2;
}
int main ()
{
int x = 1, y = 3, z = 7;
duplicate (x, y, z);
cout << x << y << z;
return 0;
}
A. 1468
B. 2812
C. 2614
D. 2713
Answer: C
Explanation:
We are passing the values by reference and modified the data on the function block.
6. What will be the output of the following C++ code?
#include
using namespace std;
class three_d
{
int x, y, z;
public:
three_d() { x = y = z = 0; }
three_d(int i, int j, int k) { x = i; y = j; z = k; }
three_d operator()(three_d obj);
three_d operator()(int a, int b, int C.;
friend ostream &operator<<(ostream &strm, three_d op);
};
three_d three_d::operator()(three_d obj)
{
three_d temp;
temp.x = (x + obj.x) / 2;
temp.y = (y + obj.y) / 2;
temp.z = (z + obj.z) / 2;
return temp;
}
three_d three_d::operator()(int a, int b, int C.
{
three_d temp;
temp.x = x + a;
temp.y = y + b;
temp.z = z + c;
return temp;
}
ostream &operator<<(ostream &strm, three_d op) {
strm << op.x << ", " << op.y << ", " << op.z << endl;
return strm;
}
int main()
{
three_d objA(1, 2, 3), objB(10, 10, 10), objC;
objC = objA(objB(100, 200, 300));
cout << objC;
return 0;
}
A. 55, 106, 156
B. 55, 106
C. 55, 106, 159
D. 55, 106, 158
Answer: A
Explanation:
In this program, We are using the function call operator to calculate the value of objc.
7. What will be the output of the following C++ code?
#include
using namespace std;
class Complex
{
private:
float real;
float imag;
public:
Complex():real(0), imag(0){}
Complex operator ()(float re, float im)
{
real += re;
imag += im;
return *this;
}
Complex operator() (float re)
{
real += re;
return *this;
}
void display()
{
cout << "(" << real << "," << imag << ")" << endl;
}
};
int main()
{
Complex c1, c2;
c2 = c1(3.2, 5.3);
c1(6.5, 2.7);
c2(1.9);
cout << "c2=";c1.display();
cout << "c2=";c2.display();
return 0;
}
A. c2=(9.7,8)
c2=(5.1,5.3)
B. c2=(9,8)
c2=(5,5)
C. c2=(4.7,8)
c2=(2.1,5.3)
D. c2=(5.7,8)
c2=(5.1,5.6)
Answer: A
Explanation:
In this program, We are returning the real and imaginary part of the complex number by using function call operator.
8. In which form does the function call operator can be overloaded?
A. static member function
B. non-static member function
C. dynamis_cast
D. static_cast
Answer: B
Explanation:
In non-static member function, the function call operator can be overloaded.
9. What will be the output of the following C++ code?
#include
using namespace std;
int operate (int a, int B.
{
return (a * B.;
}
float operate (float a, float B.
{
return (a / B.;
}
int main ()
{
int x = 5, y = 2;
float n = 5.0, m = 2.0;
cout << operate (x, y);
cout << operate (n, m);
return 0;
}
A. 119
B. 102.5
C. 123.4
D. 128.4
Answer: B
Explanation:
In this program, We are overloading the function and getting the output as 10 and 2.5 by division and multiplication.
10. What is the use of functor?
A. It makes the object “callable” like a function
B. It makes the class “callable” like a function
C. It makes the attribute “callable” like a function
D. It makes the argument “callable” like a function
Answer: A
Explanation:
functor makes the object “callable” like a function.