C++ Programming Multiple Choice Questions & Answers (MCQs) on “Complex Library – 1”.
1. Which header file is required to use complex class in your program?
a)
b)
2. Which of the following is the correct syntax of declaring a complex number?
a) complex variable_name
b) complex
c) Complex
d) Complex variable_name
Answer: b
Clarification: The correct syntax of declaring a complex number object is complex
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()
Answer: c
Clarification: The real() function is provided by the complex
4. Which function is used to get the imaginary part of the complex number?
a) real()
b) imag()
c) imag_p()
d) real_p()
Answer: b
Clarification: The imag() function is provided by the complex
5. 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 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
Answer: a
Clarification: 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()
Answer: d
Clarification: abs() function is provided by the
7. 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<<"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
Answer: d
Clarification: In this program we are trying to print the absolute value of a complex number using abs() function of
8. Which function is used to get the argument of a complex number?
a) abs()
b) norm()
c) arg()
d) argu()
Answer: c
Clarification: The argument of a complex is calculated using the arg() function of the
9. 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<<arg(cn)<<endl; return 0; }
a) 1.03038
b) 0
c) Not defined
d) Error
Answer: a
Clarification: In this program we are trying to print the argument value of a complex number using arg() function of
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
Answer: b
Clarification: The polar() function of a complex header is used to construct the complex number using the magnitude and phase angle.
