250+ TOP MCQs on Complex Library – 2 and Answers

C++ Programming Multiple Choice Questions & Answers (MCQs) on “Complex Library – 2”.

1. What will be the output of the following C++ code?

#include 
#include 
using namespace std;
int main()
{
	complex <double> cn(3.0, 5.0);
	cout<<"Complex number with magnitude "<<abs(cn)<<" 
        and phase angle "<<arg(cn)<<" is: 
        "<<polar(abs(cn), arg(cn))<<endl;
	return 0;
}

a) Complex number with magnitude 5.83095 and phase angle 1.03038 is: (3,5)
b) Complex number with magnitude 1.03038 and phase angle 5.83095 is: (3,5)
c) Complex number with magnitude 5.83095 and phase angle 5.83095 is: (3,5)
d) Complex number with magnitude 1.03038 and phase angle 1.03038 is: (3,5)
Answer: a
Clarification: In this program we are trying to costruct a complex number using polar() function of header.

2. Which function is used to calculate the norm of a complex number?
a) abs()
b) norm()
c) mod()
d) square_sum()
Answer: b
Clarification: header provides norm() function to calculate the norm of a complex number.

3. What will be the output of the following C++ code?

#include 
#include 
using namespace std;
int main()
{
	complex <double> cn(3.0, 4.0);
	cout<<"Norm is: "<<norm(cn)<<endl;
	return 0;
}

a) 9
b) 16
c) 25
d) 5
Answer: c
Clarification: In this program we are trying to calculate the norm of a complex number using norm() function of header.

4. Which function is used to calculate the conjugate of a complex number?
a) conj()
b) reverse()
c) opp()
d) find_conj()
Answer: a
Clarification: header provides conj() function to calculate the conjugate of a complex number.

5. What will be the output of the following C++ code?

#include 
#include 
using namespace std;
int main()
{
	complex <double> cn(3.0, 4.0);
	auto cnj = conj(cn);
	cout<<"Conjugate of "<<real(cn)<<"+("<<imag(cn)<<")i is: "<<real(cnj)<<"
        +("<<imag(cnj)<<")i"<<endl;
	return 0;
}

a) Conjugate of 3+(4)i is: 3+(4)i
b) Conjugate of 3+(4)i is: 3-(-4)i
c) Conjugate of 3+(4)i is: 3-(+4)i
d) Conjugate of 3+(4)i is: 3+(-4)i
Answer: d
Clarification: The complex conjugate of a+ib is a-ib so conj() of 3+4i = 3-4i or conj(complex(3,4)) = complex(3,-4).

6. What is the use of proj() function?
a) Used to calculate the argument of a complex number
b) Used to calculate the conjugate of a complex number
c) Used to calculate the negative of a complex number
d) Used to calculate the projection of a complex number
Answer: d
Clarification: header provides proj() function to calculate the projection of a complex number a + ib.

7. What will be the output of the following C++ code?

#include 
#include 
using namespace std;
int main()
{
	complex <double> cn(3.0, 4.0);
	cout<<"proj"<<cn<<" : "<<proj(cn)<<endl;
	return 0;
}

a) proj(3,4) : (3,4)
b) proj(3,4) : (4,3)
c) proj(3,4) : (-3,-4)
d) proj(3,4) : (-3,4)
Answer: a
Clarification: In this program we are trying to calculate the projection of a complex number complex(3,4) using proj() function of header the answer to which is (3,4).

8. What is the use of log() function in a complex?
a) To calculate the log of the imaginary part of a complex number
b) To calculate the log of rethe al part of a complex number
c) To calculate the log of a complex number
d) To calculate the log of the argument of a complex number
Answer: c
Clarification: header provides log() function to calculate the logarithm of a complex number a + ib.

9. What will be the output of the following C++ code?

#include 
#include 
using namespace std;
int main()
{
	complex <double> cn(3.0, 4.0);
	cout<<log(cn)<<endl;
	return 0;
}

a) 1.60944
b) (1.60944,0.927295)
c) 0.927295
d) 1.60944 + 0.927295
Answer: b
Clarification: In this program we are trying to calculate the logarithm of a complex number complex(3,4) using log() function of header the answer to which is (1.60944,0.927295).

10. What will be the output of the following C++ code?

#include 
#include 
using namespace std;
int main()
{
	complex <double> cn(3.0, 4.0);
	cout<<sin(cn)<<endl;
	return 0;
}

a) (3.85374,-27.0168)
b) 3.85374
c) -27.0168
d) 3.85374 – 27.0168
Answer: a
Clarification: In this program we are trying to calculate the sine of a complex number complex(3,4) using sin() function of header the answer to which is (3.85374,-27.0168).

  250+ TOP MCQs on STL – Heap and Answers

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top