Azerbaijan State Oil and Industry University
Computer Science
Subject: Fundamentals of Programming
Student: Rasulzade Shams
Group: 606.20E
Introduction to C++
Standard Library.
Class Template vector.
C++ Programming Language
C++ is a general-purpose programming language created by Bjarne
Stroustrup in Bell Labs as an extension of the C programming
language, or "C with Classes". The language has expanded
significantly over time, and modern C++ now has object-oriented,
generic, and functional features in addition to facilities for low-level
memory manipulation. It is almost always implemented as a
compiled language, and many vendors provide C++ compilers,
including the Free Software Foundation, Microsoft, Intel, Oracle,
and IBM, so it is available on many platforms.
C++ has also been found useful in many other contexts,
with key strengths being software infrastructure and
resource-constrained applications, including desktop
applications, video games, servers (web search, or SQL
servers), and performance-critical applications (telephone
switches or space probes).
C++ Programming Language
The C++ language has two main components: a direct mapping
of hardware features provided primarily by the C subset, and
zero-overhead abstractions based on those mappings.
Stroustrup describes C++ as "a light-weight abstraction
programming language designed for building and using
efficient and elegant abstractions"; and "offering both
hardware access and abstraction is the basis of C++.
Doing it efficiently is what distinguishes it from other
languages."
C++ Programming Language
#include <iostream>
using namespace std;
int main()
{
cout<< "Hello, world!n";
return 0;
}
C++ inherits most of C's syntax.
Hello world program that uses the C++ Standard Library to write a message to standard output:
The C++ standard consists of two parts: the core language and the standard
library.
C++ programmers expect the latter on every major implementation of C++; it
includes aggregate types (vectors, lists, maps, sets, queues, stacks, arrays, ),
algorithms (find, for_each, binary_search, random_shuffle, etc.), input/output
facilities (iostream, for reading from and writing to the console and files),
filesystem library, localization support, smart pointers for automatic memory
management, regular expression support, time utilities (measurement, getting
current time, etc.), a random number generator and a slightly modified version
of the C standard library (to make it comply with the C++ type system).
C++ Standard Library
A large part of the C++ library is based on the Standard Template Library
(STL). Useful tools provided by the STL include containers as the collections
of objects (such as vectors and lists), iterators that provide array-like access to
containers, and algorithms that perform operations such as searching and
sorting.
As in C, the features of the library are accessed by using the #include directive
to include a standard header.
The C++ Standard Library provides 105 standard headers, of which 27 are
deprecated.
C++ Standard Library
Class Template vector
Templates are the mechanism by which C++ implements
the generic concept. Simply, they allow you to pass data type as
a parameter so that you don’t need to write the same code for different
data types.
Sometimes, you need a class implementation that is same for all classes,
only the data types used are different.
Normally, you would need to create a different class for each data type
OR create different member variables and functions within a single
class.This will unnecessarily bloat your code base and will be hard to
maintain, as a change is one class/function should be performed on all
classes/functions.
However, class templates make it easy to reuse the same code for all
data types.
The C++ Standard Library contains many class templates, in particular
the containers adapted from the Standard Template Library, such
as vector.
The elements of a vector are stored contiguously. Like all dynamic
array implementations, vectors have low memory usage. Unlike other
STL containers, such as lists, vectors allow the user to denote an initial
capacity for the container.
Vectors allow random access; that is, an element of a vector may be
referenced in the same manner as elements of arrays (by array indices).
A typical vector implementation consists, internally, of a pointer to a
dynamically allocated array, and possibly data members holding the
capacity and size of the vector. The size of the vector refers to the
actual number of elements, while the capacity refers to the size of the
internal array.
Class Template vector
The template class that has defined
above serves to store elements of any
valid type.
So as seen, if we wanted to declare an object of
this class to store integer values of type int we
would write:
This same class would also be used to create an
object to store any other type:
Uses of Class Templates
• Remove code duplication
• Generic callback
• Re-use source code as opposed to inheritance and composition, which provides a way to reuse object code
Resources
• https://en.wikipedia.org/wiki/C%2B%2B#Standard_library
• https://en.wikipedia.org/wiki/C%2B%2B_Standard_Library
• https://www.geeksforgeeks.org/templates-cpp/
• https://www.cplusplus.com/reference/vector/vector/
THANK YOU FOR ATTENTION

Introduction to C++, Standard Library, Class Template vector.pptx

  • 1.
    Azerbaijan State Oiland Industry University Computer Science Subject: Fundamentals of Programming Student: Rasulzade Shams Group: 606.20E
  • 2.
    Introduction to C++ StandardLibrary. Class Template vector.
  • 3.
    C++ Programming Language C++is a general-purpose programming language created by Bjarne Stroustrup in Bell Labs as an extension of the C programming language, or "C with Classes". The language has expanded significantly over time, and modern C++ now has object-oriented, generic, and functional features in addition to facilities for low-level memory manipulation. It is almost always implemented as a compiled language, and many vendors provide C++ compilers, including the Free Software Foundation, Microsoft, Intel, Oracle, and IBM, so it is available on many platforms.
  • 4.
    C++ has alsobeen found useful in many other contexts, with key strengths being software infrastructure and resource-constrained applications, including desktop applications, video games, servers (web search, or SQL servers), and performance-critical applications (telephone switches or space probes). C++ Programming Language
  • 5.
    The C++ languagehas two main components: a direct mapping of hardware features provided primarily by the C subset, and zero-overhead abstractions based on those mappings. Stroustrup describes C++ as "a light-weight abstraction programming language designed for building and using efficient and elegant abstractions"; and "offering both hardware access and abstraction is the basis of C++. Doing it efficiently is what distinguishes it from other languages." C++ Programming Language
  • 6.
    #include <iostream> using namespacestd; int main() { cout<< "Hello, world!n"; return 0; } C++ inherits most of C's syntax. Hello world program that uses the C++ Standard Library to write a message to standard output:
  • 7.
    The C++ standardconsists of two parts: the core language and the standard library. C++ programmers expect the latter on every major implementation of C++; it includes aggregate types (vectors, lists, maps, sets, queues, stacks, arrays, ), algorithms (find, for_each, binary_search, random_shuffle, etc.), input/output facilities (iostream, for reading from and writing to the console and files), filesystem library, localization support, smart pointers for automatic memory management, regular expression support, time utilities (measurement, getting current time, etc.), a random number generator and a slightly modified version of the C standard library (to make it comply with the C++ type system). C++ Standard Library
  • 8.
    A large partof the C++ library is based on the Standard Template Library (STL). Useful tools provided by the STL include containers as the collections of objects (such as vectors and lists), iterators that provide array-like access to containers, and algorithms that perform operations such as searching and sorting. As in C, the features of the library are accessed by using the #include directive to include a standard header. The C++ Standard Library provides 105 standard headers, of which 27 are deprecated. C++ Standard Library
  • 9.
    Class Template vector Templatesare the mechanism by which C++ implements the generic concept. Simply, they allow you to pass data type as a parameter so that you don’t need to write the same code for different data types. Sometimes, you need a class implementation that is same for all classes, only the data types used are different. Normally, you would need to create a different class for each data type OR create different member variables and functions within a single class.This will unnecessarily bloat your code base and will be hard to maintain, as a change is one class/function should be performed on all classes/functions. However, class templates make it easy to reuse the same code for all data types.
  • 10.
    The C++ StandardLibrary contains many class templates, in particular the containers adapted from the Standard Template Library, such as vector. The elements of a vector are stored contiguously. Like all dynamic array implementations, vectors have low memory usage. Unlike other STL containers, such as lists, vectors allow the user to denote an initial capacity for the container. Vectors allow random access; that is, an element of a vector may be referenced in the same manner as elements of arrays (by array indices). A typical vector implementation consists, internally, of a pointer to a dynamically allocated array, and possibly data members holding the capacity and size of the vector. The size of the vector refers to the actual number of elements, while the capacity refers to the size of the internal array. Class Template vector
  • 11.
    The template classthat has defined above serves to store elements of any valid type. So as seen, if we wanted to declare an object of this class to store integer values of type int we would write: This same class would also be used to create an object to store any other type: Uses of Class Templates • Remove code duplication • Generic callback • Re-use source code as opposed to inheritance and composition, which provides a way to reuse object code
  • 12.
    Resources • https://en.wikipedia.org/wiki/C%2B%2B#Standard_library • https://en.wikipedia.org/wiki/C%2B%2B_Standard_Library •https://www.geeksforgeeks.org/templates-cpp/ • https://www.cplusplus.com/reference/vector/vector/
  • 13.
    THANK YOU FORATTENTION