# C++ Programming Questions and Answers – Complex Library – 1

«
»

This set of C++ Programming Multiple Choice Questions & Answers (MCQs) focuses on “Complex Library – 1”.

1. Which header file is required to use complex class in your program?
a) <complex>
b) [itex]
c) <complex_math>
d) <algorithm>

Explanation: <complex> header file is required to use the functionalitites of complex numbers.

2. Which of the following is the correct syntax of declaring a complex number?
a) complex variable_name<type>;
b) complex<type> variable_name;
c) Complex<type> variable_name;
d) Complex variable_name<type>;

Explanation: The correct syntax of declaring a complex number object is complex<type> variable_name.

3. Which function is used to get the real part of the complex number?
a) img_p()
b) imag_p()
c) real()
d) real_p()

Explanation: The real() function is provided by the complex <header> to access the real part of a complex number object.

4. Which function is used to get the imaginary part of the complex number?
a) real()
b) imag()
c) imag_p()
d) real_p()

Explanation: The imag() function is provided by the complex <header> to access the imaginary part of a complex number object.

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

```#include <iostream>
#include <complex>
using namespace std;
int main()
{
complex <double> cn(3.0, 5.0);
cout<<"Complex number is: "<<real(cn)<<" + "<<imag(cn)<<"i"<<endl;
return 0;
}```

a) Complex number is: 3 + 5i
b) Complex number is: 5 + 3i
c) Complex number is: 9 + 25i
d) Complex number is: 3 – 5i

Explanation: The first part in the constructor of complex object denotes real part and second part denotes the imaginary part hence the complex number is 3 + 5i.

6. Which function is used to get the absolute of a complex number?
a) ret()
b) norm()
c) mod()
d) abs()

Explanation: abs() function is provided by the header to calculate the absolute value of a complex number.

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

```#include <iostream>
#include <complex>
using namespace std;
int main()
{
complex <double> cn(3.0, 5.0);
cout<<"Absolute value is: "<<abs(cn)<<endl;
return 0;
}```

a) Absolute value is: 4
b) Absolute value is: 5
c) Absolute value is: 3
d) Absolute value is: 5.83095

Explanation: In this program we are trying to print the absolute value of a complex number using abs() function of <complex> header.

8. Which function is used to get the argument of a complex number?
a) abs()
b) norm()
c) arg()
d) argu()

Explanation: The argument of a complex is calculated using the arg() function of the <complex> header.

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

```#include <iostream>
#include <complex>
using namespace std;
int main()
{
complex <double> cn(3.0, 5.0);
cout<<arg(cn)<<endl;
return 0;
}```

a) 1.03038
b) 0
c) Not defined
d) Error

Explanation: In this program we are trying to print the argument value of a complex number using arg() function of <complex> header.

10. What is the use of polar function?
a) Used to construct a complex number from the real and imaginary part
b) Used to construct a complex number from magnitude and phase angle
c) Used to construct a complex number from the magnitude and real part
d) Used to construct a complex number from argument and phase angle 