OOP Unit VI MCQ
1. What is the Standard Template Library?
a) Set of C++ template classes to provide common programming data structures and
functions
b) Set of C++ classes
c) Set of Template functions used for easy data structures implementation
d) Set of Template data structures only
Ans: a
2. Pick the correct statement.
a) STL is a generalized library
b) Components of STL are parameterized
c) STL uses the concept of templates classes and functions to achieve generalized
implementation
d) All of the mentioned
Ans:d
3. How many components STL has?
a) 1
b) 2
c) 3
d) 4
Ans:d
4. What are the containers?
a) Containers store objects and data
b) Containers stores all the algorithms
c) Containers contain overloaded functions
d) Containers contain set of Iterators
Ans:a
5. In how many categories, containers are divided?
a) 1
b) 2
c) 3
d) 4
Ans:d
6. What are the Sequence Containers?
a) Containers that implements data structures which can be accessed sequentially
b) Containers that implements sorted data structures for fast search in O(logn)
c) Containers that implements unsorted(hashed) data structures for quick search in O(1)
d) Containers that implements data structures which can be accessed non-sequentially
Ans:a
7. How many Sequence Containers are provided by C++?
a) 2
b) 3
c) 4
d) 5
Ans:d
8. What are the Associative Containers?
a) Containers that implements data structures which can be accessed sequentially
b) Containers that implements sorted data structures for fast search in O(logn)
c) Containers that implements unsorted(hashed) data structures for quick search in O(1)
d) Containers that implements data structures which can be accessed non-sequentially
Ans:b
13. What are Iterators?
a) Iterators are used to iterate over C-like arrays
b) Iterators are used to iterate over pointers
c) Iterators are used to point memory addresses of STL containers
d) Iterators are used to iterate over functions
Ans:c
15. Which header file is used for Iterators?
a) <iterator>
b) <algorithm>
c) <iter>
d) <loopIter>
Ans:a
16. What will be the output of the following C++ code?
#include <vector>
#include <algorithm>
#include <iostream>
using namespace std;
int main()
{
vector<int> v;
for(int i=0;i<10;i++)
v.push_back(i+1);
for(int i=0;i<10;i++)
cout<<v[i]<<" ";
cout<<endl;random_shuffle(v.begin(), v.end());
for(int i=0;i<10;i++)
cout<<v[i]<<" ";
return 0;
}
a)
1 2 3 4 5 6 7 8 9 10
5 4 8 9 1 6 3 2 7 10
b)
5 4 8 9 1 6 3 2 7 10
1 2 3 4 5 6 7 8 9 10
c)
1 2 3 4 5 6 7 8 9 10
1 2 3 4 5 6 7 8 9 10
d)
5 4 8 9 1 6 3 2 7 10
5 4 8 9 1 6 3 2 7 10
Ans: a
17. What is the property of stable sort function provided by the STL algorithm?
a) sorts the elements of a sequence in ascending order preserving the relative order of equivalent
elements
b) sorts the elements of a sequence in descending order preserving the relative order of equivalent
elements
c) arranges the sequence randomly preserving the relative order of equivalent elements
d) same as sort function of STL algorithm
Ans: a
18. What is the property of partial sort function provided by the STL algorithm?
a) sorts the elements before the middle element in ascending order and remaining elements are left
without any specific order
b) sorts the elements before the middle element in descending order and remaining elements are left
without any specific order
c) sorts the elements after the middle element in ascending order and remaining elements are left
without any specific order
d) sorts the elements after the middle element in descending order and remaining elements are left
without any specific orderAns:a
19. What will be the output of the following C++ code?
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
int main ()
{
vector<int> v = {4,2,10,5,1,8};
sort(v.begin(), v.end());
if (binary_search(v.begin(), v.end(), 4))
cout << "found.\n";
else
cout << "not found.\n";
return 0;
}
a) found.
b) not found.
c) Error
d) Segmentation fault
Ans: a
20. What will be the output of the following C++ code?
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
int main ()
{
vector<int> v = {4,2,10,5,1,8};
if (binary_search(v.begin(), v.end(), 4))
cout << "found.\n";
else
cout << "not found.\n";
return 0;
}
a) found.b) not found.
c) Error
d) Segmentation fault
Ans: b
21. Which function can be used to find the sum of a vector container?
a) findsum()
b) accumulate()
c) calcsum()
d) checksum()
Ans:b
22. Which header file is required to use accumulate() function?
a) <algorithm>
b) <numeric>
c) <vector>
d) <iostream>
Ans:b
0 Comments
Please feel free to comment. Being diploma students We are always ready to help diploma Students