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) <math>
c) <complex_math>
d) <algorithm>
View Answer
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>;
View Answer
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()
View Answer
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()
View Answer
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
View Answer
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()
View Answer
Explanation: abs() function is provided by the
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
View Answer
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()
View Answer
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
View Answer
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
View Answer
Explanation: The polar() function of a complex header is used to construct the complex number using the magnitude and phase angle.
Sanfoundry Global Education & Learning Series – C++ Programming Language.
To practice all areas of C++ language, here is complete set of 1000+ Multiple Choice Questions and Answers.
- Check C++ Books
- Apply for Information Technology Internship
- Practice Computer Science MCQs
- Check Computer Science Books
- Check Programming Books