MCQs
Total Questions : 5
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
Answer: Option B. -> non-static member function
None.
Question 3.
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
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
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.
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
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
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
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