You are on page 1of 12

OOPS ASSIGNMENT

The Standard Template Library:

The Standard Template Library (STL) is a


generic library that provides solutions to
managing collections of data with an efficient
algorithm.
The STL provides a collection of classes that
meet different kind of tasks, with algorithms
that operate on the classes.
Furthermore, STL also provides a framework
for other collection of user defined classes or
algorithms. The traditional programming
such as dynamic arrays, linked lists, binary
trees, search algorithms and other data
structures routines can be implemented
using STL more efficiently and easily.
Components of STL:
The STL consist of the containers, iterators,
and algorithms.
Further we can make use of flowchart to
understand parts/types of STL.

1. Containers :
Container classes’ purpose is to contain
other objects. Each of these classes is a
template, and can be instantiated to contain
any type of object.
The STL container classes include vector,
list, deque, set, multiset, map, multimap,
hash_set, hash_multiset, hash_map and
hash_multimap to suit different kind of tasks.
In associative containers even unordered set,
unordered multiset, unordered map ,
unordered multimap arre included.

2. Iterators:
It is a pointer(kind of) used to manipulate the
elements of the objects’ collections. These
collections may be containers or subsets of
containers.
Iterators provide common interface for any
arbitrary container type. Every container
class provides its own iterator type but when
you try the program examples later, most of
the containers have a common iterator types.
It is a smart pointer.

3. Algorithms:
Algorithms are used to process the elements
of collections. For example, algorithms can
search, sort and modify. Algorithms use
iterators Or simply iterators are link between
containers and algos.

Now,about containers and programs using


containers:

1. Sequence containers
These are ordered collections in which
every element has a certain position i.e.
they store value in contiguous memory
locations.
This position depends on the time and place
of the insertion, but it is independent of the
value of the element.
The STL contains three predefined
sequence container classes: vector, deque,
and list.
Now its types:

a. Vectors:

A vector manages its elements in a dynamic


array(resizeable array). It enables random
access. Appending and removing elements
at the end of the array is very fast.
However, inserting an element in the middle
or at the beginning of the array takes time
because all the following elements have to
be moved to make room for it while
maintaining the order.
Operations on vectors can only be
performed by using v.begin() and
v.end(),where v.begin() and v.end() are
pointers referring to front and end pointers.

b. Deque:
The term deque (pronounced “deck”) is an
abbreviation for ‘double-ended queue’.
It is a dynamic array that is implemented so
that it can grow in both directions.
So, inserting elements at the end and at the
beginning is fast. However, inserting
elements in the middle takes time because
elements must be moved.

c. List:
List is simply a doubly linked list.
Elements are not stored in contiguous
memory locations.
List does not support random access(i.e.
elements cannot be accessed like arrays as
arr[5]).

2. Associative Containers:
These are sorted collections in which the
actual position of an element depends on
its value due to a certain sorting criterion.
We have no idea of a sequence.
Data is accessed using the key instead of
indexes.

Maps are associative containers that store


elements in a mapped fashion. Each
element has a key value and a mapped
value. No two mapped values can have
same key values.
While in a multimap,two values mapped can
have same key, the difference being we
can’t update a value using key in
multimap(.i.e multimp[7]=700; is invalid in
multimap).

And Sets are a type of associative


containers in which each element has to be
unique, because the value of the element
identifies it. The value of the element
cannot be modified once it is added to the
set, though it is possible to remove and add
the modified value of that element.
And in multiset,as the name suggests,we
can have same multiple values.

Stream Classes:
Stream classes in C++ are used to input and
output operations on files and io devices.
These classes have specific features and to
handle input and output of the program.
There are three classes of iostream library:

ios class − This class is the base class for


all stream classes. The streams can be input
or output streams. This class defines
members that are independent of how the
templates of the class are defined.

istream Class − The istream class handles


the input stream in c++ programming
language. These input stream objects are
used to read and interpret the input as a
sequence of characters. The cin handles the
input.

ostream class − The ostream class


handles the output stream in c++
programming language. These output stream
objects are used to write data as a sequence
of characters on the screen. cout and puts
handle the out streams in c++ programming
language.

Formatting Output with stream


Function:
 The layout of a program's output is called
the format of the output.
 It is mainly done using stream
manipulators,which are shown with the
help of a table below:
Manipulator Description
flush causes the output buffer
to be flushed to the output
device before processing
proceed
endl prints a newline and
flushes the output buffer
dec causes integers to be
printed in decimal (base
10)
oct causes integers from this
point to be printed in octal
(base 8)
hex causes integers from this
point to be printed in
hexadecimal (base 16)
setbase() a parameterized
manipulator that takes
either 10, 8, or 16 as a
parameter, and causes
integers to be printed in
that base.
internal if this is set, a number's
sign will be left-justified
and the number's
magnitude will be right-
justified in a field (and the
fill character pads the
space in between). Only
one of right, left, and
internal can be set at a
time.
boolalpha causes values of type bool
to be displayed as words
(true or false)
noboolalpha causes values of type bool
to be displayed as the
integer values 0 (for false)
or 1 (for true)
-----------------------------END---------------------------------

-By Harsh yadav


(11912021)

You might also like