PI Questions Day-2

You might also like

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 4

PI Questions :

Q1:  How many kinds of entities are directly parameterized in c++?

Q2: How many components STL has?

Q3: Explain the purpose of STL

Q4: From which STL we can insert/remove data from anywhere?

Q5: What does this function do?

void func() {

std::vector<std::string> vecOfString(5, "Hi");

for (std::string str : vecOfStr)

std::cout << str << std::endl;

Q6: How many components does the STL has ?

Q7: What is the role of clear() function from STL ?

Q8: What is the role of count() function from STL ?

Q9: how can we store class objects in a map ?

Q10: what find() function of map class return ?

Q11: Which data structure is used by Map?

Q12: From which STL we can insert/remove data from anywhere?

Q13: What is the correct way to initialize vector in C++?

Q14: Is it possible to initialize any Vector with an Array in C++?

Q15: Is duplicate data allowed in set?

Q16: Why Should A C++ Programmer Be Interested In The Stl?

Q17: What Are The Major Components Of The Stl?

Q18: What Are Some Of The Things A Programmer Should Be Aware Of When Using The Stl?(many Of
These May Not Make Sense Until You Have Actually Tried To Use The Stl.)

Q19: What Is The Design Philosophy Of The Stl?


Q20: How vector can be filled by random numbers ?

Answers :

Q1: C++ allows us to parameterize directly three kinds of entities through templates: types, constants,
and templates.

Q2: Explanation: STL has four components namely Algorithms, Containers, Functors and Iterators.

Q3: STL is a generalized library and components of STL are parameterized. STL uses the concept of
templates classes and function to achieve generalized implementation.

Q4 :List

Q5:Initialize vect to 5 string with value "Hi" & prints them

Q6 three container algorithms and iterators

Q7: clear all elements of list

Q8: count the occurrences of a key in map

Q9: using key value pairs

Q10: iterator to a specified key

Q11: Balanced Binary tree

Q12: List

Q13:  std::vector<int> vecOfInts;

Q14: Yes, Vector can be initialized by Array

Q15: Set never allow


Q16: Because the STL embodies the concept of reusable software components, and provides off-the-
shelf solutions to a wide variety of programming problems. It is also extensible, in the sense that any
programmer can write new software (containers and algorithms, for example), that "fit in" to the STL
and work with the already-existing parts of the STL, provided the programmer follows the appropriate
design guidelines.

Q17: The containers and container adaptors (both are objects that can hold other objects), the iterators
(generalized pointers that point at items in containers), and the algorithms (that work on containers
through iterators) will be the most frequently used components of the STL.

Q18:Understand member functions size(), max_size() and resize().

Understand member functions begin(), end(), rbegin() and rend().

Understand the fact that a reference to a "range" of values in STL generally means those values from
(and including) the first value in the range up to (but not including) the last value in the range. Such a
range can extend forward or backward, depending on the kinds of iterators being used.

Even though it may (sometimes) work, it is better not use a loop like for (i = c.begin(); i < c.end(); i++) ...
for processing all the elements of a container c; it is preferable instead to use a loop like this: for (i =
c.begin(); i != c.end(); i++) ... This second form is often necessary, in fact, since not all container iterators
support operator<.

RIt is safest to assume that insert() applied to a deque or a vector will invalidate any iterators or
references to elements of the deque or vector.

Know that any insert() member function applied to a container may (or may not) invalidate iterators and
references already pointing at elements of that container.

Q19:The STL exemplifies generic programming rather than object-oriented programming, and derives its
power and flexibility from the use of templates, rather than inheritance and polymorphism. It also
avoids new and delete for memory management in favor of allocators for storage allocation and deal
location. The STL also provides performance guarantees, i.e., its specification requires that the
containers and algorithms be implemented in such a way that a user can be confident of optimal
runtime performance independent of the STL implementation being used.

Q20:

For this task we will use a STL algorithm std::generate as:

template<typename _FIter, typename _Generator>

void generate(_FIter start, _FIter end, _Generator gen);

You might also like