1. Which header file is used to declare the complex number?
a) complexnum
b) complex
c) complexnumber
d) None of the mentioned
2. How to declare the complex number?
a) (3,4)
b) complex(3,4)
c) (3,4i)
d) None of the mentioned
3. How many real types are there in complex numbers?
a) 1
b) 2
c) 3
d) 4
4. What is the output of this program?
1.#include <iostream>
2.#include <complex>
3.using namespace std;
4.int main()
5.{
6. complex<double> c1(4.0, 16.0), c2;
7. c2 = pow(c1, 2.0);
8. cout << c2;
9. return 0;
10.}
a) (-240, 128)
b) (240, 128)
c) (240, 120)
d) None of the mentioned
5. What is the output of this program?
1.#include <iostream>
2.#include <complex>
3.using namespace std;
4.int main()
5.{
6. complex<double> c_double(2, 3);
7. complex<int> c_int(4, 5);
8. c_double *= 2;
9. c_double = c_int;
10. cout << c_double;
11. return 0;
12.}
a) (2, 3)
b) (4, 5)
c) (8, 15)
d) None of the mentioned
6. What is the output of this program?
1.#include <iostream>
2.#include <complex>
3.using namespace std;
4.int main()
5.{
6. complex<int> i(2, 3);
7. i = i * 6 / 3;
8. cout << i;
9. return 0;
10.}
a) (4, 6)
b) (2, 3)
c) (6, 12)
d) None of the mentioned
7. What is the output of this program?
1.#include <iostream>
2.#include <complex>
3.using namespace std;
4.int main()
5.{
6. complex<double> c1(4.0,3.0);
7. cout << “c1: ” << c1;
8. complex<float> c2(polar(5.0,0.75));
9. cout << c1 + complex<double>(c2.real(),c2.imag());
10. return 0;
11.}
a) c1: (4,3)(7.65844,6.40819)
b) c1: (4,3)(7,6)
c) both a & b
d) None of the mentioned
8. What is the output of this program?
1.#include <iostream>
2.#include <complex>
3.using namespace std;
4.int main()
5.{
6. complex<double> c1(4.0, 3.0);
7. complex<float> c2(polar(5.0, 0.75));
8. cout << (c1 += sqrt(c1)) << endl;
9. return 0;
10.}
a) (4.0, 3.0)
b) (6.12132, 3.70711)
c) (5.0, 0.75)
d) None of the mentioned
9. Which of the following is not a function of complex values?
a) real
b) imag
c) norm
d) cartesian
.
10. What is the output of this program?
1.#include <iostream>
2.#include <complex>
3.using namespace std;
4.int main ()
5.{
6. complex<double> mycomplex (20.0, 2.0);
7. cout << imag(mycomplex) << endl;
8. return 0;
9.}
a) 2
b) 20
c) 40
d) None of the mentioned
11. Which keyword is used to define the user defined data types?
a) def
b) union
c) typedef
d) type
12. Identify the correct statement.
a) typedef does not create different types.It only creates synonyms of existing types.
b) typedef create different types.
c) both a & b
d) none of the mentioned
13. What does the data type defined by union will do?
a) It allow one different portion of memory to be accessed as same data types
b) It allow one same portion of memory to be accessed as same data types
c) It allow one different portion of memory to be accessed as different data types
d) It allow one same portion of memory to be accessed as different data types
.
14. What is the output of this program?
1.#include <iostream>
2.using namespace std;
3.int main()
4.{
5. typedef int num;
6. num a = 10, b = 15;
7. num c = a + b + a – b;
8. cout << c;
9. return 0;
10.}
a) 20
b) 15
c) 30
d) 25
15. What is the output of this program?
1.#include <iostream>
2.using namespace std;
3.int main()
4.{
5. int i;
6. enum month {
7. JAN,FEB,MAR,APR,MAY,JUN,JUL,AUG,SEP,OCT,DEC
8. };
9. for (i = JAN; i <= DEC; i++)
10. cout << i;
11. return 0;
12.}
a) 012345678910
b) 0123456789
c) 01234567891011
d) none of the mentioned
16. What is the output of this program?
1.#include <iostream>
2.using namespace std;
3.int main()
4.{
5. typedef int num;
6. typedef char let;
7. let w = “steve”;
8. num a = 10, b = 15;
9. num c = a + w;
10. cout << c;
11. return 0;
12.}
a) 10steve
b) steve10
c) compile time error
d) compile but not run
17. What is the syntax of user-defined data types?
a) typedef_existing data type_new name
b) typedef_new name_existing data type
c) def_existing data type_new name
d) none of the mentioned
18. How many types of user-defined data type are in c++?
a) 1
b) 2
c) 3
d) 4
.
19. What is the scope of typedef defined data types?
a) inside that block only
b) whole program
c) outside the program
d) none of the mentioned
20. How many types of models are available to create the user-defined data type?
a) 1
b) 2
c) 3
d) 4
21. subscript operator is used to access which elements?
a) string
b) char
c) array
d) all of the mentioned
22. How many arguments will the subscript operator will take for overloading?
a) 1
b) 2
c) 0
d) as many as possible
23. Pick out the correct statement.
a) subscript operator has a higher precedence than the assignment operator.
b) subscript operator has a lower precedence than the assignment operator.
c) subscript operator is used with string elements.
d) None of the mentioned
24. What is the output of this program?
1.#include <iostream>
2.using namespace std;
3.const int SIZE = 10;
4.class safe
5.{
6. private:
7. int arr[SIZE];
8. public:
9. safe()
10. {
11. register int i;
12. for (i = 0; i < SIZE; i++)
13. {
14. arr[i] = i;
15. }
16. }
17. int &operator[](int i)
18. {
19. if (i > SIZE)
20. {
21. cout << “Index out of bounds” <<endl;
22. return arr[0];
23. }
24. return arr[i];
25. }
26.};
27.int main()
28.{
29. safe A;
30. cout << A[5];
31. cout << A[12];
32. return 0;
33.}
a) 5Index out of bounds
b) 40
c) 50
d) 51
25. What is the output of this program?
1.#include <iostream>
2.using namespace std;
3.class numbers
4.{
5. private:
6. int m_nValues[10];
7. public:
8. int& operator[] (const int nValue);
9.};
10.int& numbers::operator[](const int nValue)
11.{
12. return m_nValues[nValue];
13.}
14.int main()
15.{
16. numbers N;
17. N[5] = 4;
18. cout << N[5];
19. return 0;
20.}
a) 5
b) 4
c) 3
d) 6
26. What is the output of this program?
1.#include <iostream>
2.using namespace std;
3.const int limit = 4;
4.class safearray
5.{
6. private:
7. int arr[limit];
8. public:
9. int& operator [](int n)
10. {
11. if (n == limit – 1)
12. {
13. int temp;
14. for (int i = 0; i < limit; i++)
15. {
16. if (arr[n + 1] > arr[n])
17. {
18. temp = arr[n];
19. arr[n] = arr[n + 1];
20. arr[n + 1] = temp;
21. }
22. }
23. }
24. return arr[n];
25. }
26.};
27.int main()
28.{
29. safearray sa1;
30. for(int j = 0; j < limit; j++)
31. sa1[j] = j*10;
32. for(int j = 0; j < limit; j++)
33. {
34. int temp = sa1[j];
35. cout << “Element ” << j << ” is ” << temp;
36. }
37. return 0;
38.}
a) 0102030
b) 1020300
c) 3020100
d) error
27. What is the output of this program?
1.#include <iostream>
2.using namespace std;
3.class A
4.{
5. public:
6. int x;
7. A(int n = 0) : x(n) {};
8. int& operator[](int n)
9. {
10. cout << “0” ;
11. return x;
12. }
13. int operator[](int n) const
14. {
15. cout << “1” ;
16. return x;
17. }
18. };
19.void foo(const A& a)
20.{
21. int z = a[2];
22.}
23.int main()
24.{
25. A a(7);
26. a[3] = 8;
27. int z = a[2];
28. foo(a);
29. return 0;
30.}
a) 110
b) 111
c) 011
d) 001
28. What is the output of this program?
1.#include <iostream>
2.using namespace std;
3.class sample
4.{
5. private:
6. int* i;
7. int j;
8. public:
9. sample (int j);
10. ~sample ();
11. int& operator [] (int n);
12.};
13.int& sample::operator [] (int n)
14.{
15. return i[n];
16.}
17.sample::sample (int j)
18.{
19. i = new int [j];
20. j = j;
21.}
22.sample::~sample ()
23.{
24. delete [] i;
25.}
26.int main ()
27.{
28. sample m (5);
29. m [0] = 25;
30. m [1] = 20;
31. m [2] = 15;
32. m [3] = 10;
33. m [4] = 5;
34. for (int n = 0; n < 5; ++ n)
35. cout << m [n];
36. return 0;
37.}
a) 252015105
b) 510152025
c) 51015
d) None of the mentioned
29. What do we need to do to pointer for overloading the subscript operator?
a) reference pointer
b) dereference pointer
c) store it in heap
d) None of the mentioned
30. What do we need to use when we have multiple subscripts?
a) operator()
b) operator[]
c) operator
d) None of the mentioned
Answers
1-b | 2-b | 3-c | 4-a | 5-b |
6-a | 7-b | 8-b | 9-d | 10-a |
11-c | 12-a | 13-d | 14-a | 15-a |
16-c | 17-a | 18-c | 19-b | 20-b |
21-c | 22-a | 23-a | 24-a | 25-b |
26-a | 27-d | 28-a | 29-b | 30-a |