Sail E0 Webinar

MCQs

Total Questions : 5
Question 1.


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
  1.    119
  2.    102.5
  3.    123.4
  4.    none of the mentioned
 Discuss Question
Answer: Option B. -> 102.5

:In this program, We are overloading the function and getting the output as 10 and 2.5 by division 

and multiplication.
Output:
$ g++ call3.cpp
$ a.out
102.5


Question 2.

 In which form does the function call operator can be overloaded?


  1.    static member function
  2.    non-static member function
  3.    dynamis_cast
  4.    static_cast
 Discuss Question
Answer: Option B. -> non-static member function

None.


Question 3.


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
  1.    static member function
  2.    non-static member function
  3.    dynamis_cast
  4.    static_cast
 Discuss Question
Answer: Option B. -> non-static member function

Answer: (a)
Explanation: 
In this program, We are returning the real and imaginary part of the complex number by using function call operator.
Output:
$ g++ call3.cpp
$ a.out
c2=(9.7,8)
c2=(5.1,5.3)


Question 4.


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
  1.    55, 106, 156
  2.    55, 106
  3.    55, 106, 159
  4.    none of the mentioned
 Discuss Question
Answer: Option A. -> 55, 106, 156

In this program, We are using the function call operator to calculate the value of objc.
Output:
$ g++ call2.cpp
$ a.out
55, 106, 156


Question 5.


What is the output of this program?


1.
#include
2.
using namespace std;
3.
void duplicate (int& a, int& b, int& c)
4.
{
5.
a *= 2;
6.
b *= 2;
7.
c *= 2;
8.
}
9.
int main ()
10.
{
11.
int x = 1, y = 3, z = 7;
12.
duplicate (x, y, z);
13.
cout
  1.    1468
  2.    2812
  3.    2614
  4.    none of the mentioned
 Discuss Question
Answer: Option C. -> 2614

:We are passing the values by reference and modified the data on the function block.
Output:
$ g++ call1.cpp
$ a.out
2614


Latest Videos

Latest Test Papers