CPP

CPP

Function Call has 9 Questions

What is the use of function call operator?

overloading the methods
overloading the objects
overloading the parameters
none of the mentioned
Pick out the correct statement.

virtual functions does not give the ability to write a templated function.
virtual functions does not give the ability to rewrite a templated function.
virtual functions does give the ability to write a templated function.
none of the mentioned
What will happen when the function call operator is overloaded?

It will not modify the functions.
It will modify the functions.
It will modify the object.
It will modify the operator to be interpreted.
What is the output of this program?
  1.     #include 
  2.     using namespace std;
  3.     class Distance
  4.     {
  5.         private:
  6.         int feet;
  7.         int inches;
  8.         public:
  9.         Distance()
  10.         {
  11.             feet = 0;
  12.             inches = 0;
  13.         }
  14.         Distance(int f, int i) 
  15.         {
  16.             feet = f;
  17.             inches = i;
  18.         }
  19.         Distance operator()(int a, int b, int c)
  20.         {
  21.             Distance D;
  22.             D.feet = a + c + 10;
  23.             D.inches = b + c + 100 ;
  24.             return D
  25.         }
  26.         void displayDistance()
  27.         {
  28.             cout  << feet <<  inches << endl;
  29.         }
  30.     };
  31.     int main()
  32.     {
  33.         Distance D1(11, 10), D2;
  34.         cout << "First Distance : ";
  35.         D1.displayDistance();
  36.         D2 = D1(10, 10, 10);
  37.         cout << "Second Distance :";
  38.         D2.displayDistance();
  39.         return 0;
  40.     }

First Distance : 1110 Second Distance :30120
First Distance : 110 Second Distance :3020
First Distance : 1115 Second Distance :30125
none of the mentioned
What is the output of this program?
  1.     #include 
  2.     using namespace std;
  3.     class three_d 
  4.     {
  5.         int x, y, z;
  6.         public:
  7.         three_d() { x = y = z = 0; }
  8.         three_d(int i, int j, int k) { x = i; y = j; z = k; }
  9.         three_d operator()(three_d obj);
  10.         three_d operator()(int a, int b, int c);
  11.         friend ostream &operator<<(ostream &strm, three_d op);
  12.     };
  13.     three_d three_d::operator()(three_d obj)
  14.     {
  15.         three_d temp;
  16.         temp.x = (x + obj.x) / 2;
  17.         temp.y = (y + obj.y) / 2;
  18.         temp.z = (z + obj.z) / 2;
  19.         return temp;
  20.     }
  21.     three_d three_d::operator()(int a, int b, int c)
  22.     {
  23.         three_d temp;
  24.         temp.x = x + a;
  25.         temp.y = y + b;
  26.         temp.z = z + c;
  27.         return temp;
  28.     }
  29.         ostream &operator<<(ostream &strm, three_d op) {
  30.         strm << op.x << ", " << op.y << ", " << op.z << endl;
  31.         return strm;
  32.     }
  33.     int main()
  34.     {
  35.         three_d objA(1, 2, 3), objB(10, 10, 10), objC;
  36.         objC = objA(objB(100, 200, 300));
  37.         cout << objC;
  38.         return 0;
  39.     }

55, 106, 156
55, 106
55, 106, 159
none of the mentioned
What is the output of this program?
  1.     #include 
  2.     #include 
  3.     using namespace std;
  4.     class Complex
  5.     {
  6.         private:
  7.         float real;
  8.         float imag;
  9.         public:
  10.         Complex():real(0), imag(0){}
  11.         Complex operator ()(float re, float im)
  12.         {
  13.             real += re;
  14.             imag += im;
  15.             return *this;
  16.         }
  17.         Complex operator() (float re)
  18.         {
  19.             real += re;
  20.             return *this;
  21.         }
  22.         void display()
  23.         {
  24.             cout << "(" << real << "," << imag << ")" << endl;
  25.         }
  26.     };
  27.     int main()
  28.     {
  29.         Complex c1, c2;
  30.         c2 = c1(3.2, 5.3);
  31.         c1(6.5, 2.7);
  32.         c2(1.9);
  33.         cout << "c2=";c1.display();
  34.         cout << "c2=";c2.display();
  35.         return 0;
  36.     }

c2=(9.7,8) c2=(5.1,5.3)
c2=(9,8) c2=(5,5)
c2=(4.7,8) c2=(2.1,5.3)
none of the mentioned
In which form does the function call operator can be overloaded?

static member function
non-static member function
dynamis_cast
static_cast
What is the output of this program?
  1.     #include 
  2.     using namespace std;
  3.     int operate (int a, int b)
  4.     {
  5.         return (a * b);
  6.     }
  7.     float operate (float a, float b)
  8.     {
  9.         return (a / b);
  10.     }
  11.     int main ()
  12.     {
  13.         int x = 5, y = 2;
  14.         float n = 5.0, m = 2.0;
  15.         cout << operate (x, y);
  16.         cout << operate (n, m);
  17.         return 0;
  18.     }

119
102.5
123.4
none of the mentioned
What is the use of functor?

It makes the object "callable"? like a function.
It makes the class "callable"? like a function.
It makes the attribute "callable"? like a function.
none of the mentioned