OOP

अब Quizwiz के साथ अपने होमवर्क और परीक्षाओं को एस करें!

Expection example

#include <iostream> // std::cerr #include <stdexcept> // std::out_of_range #include <vector> // std::vector int main (void) { std::vector<int> myvector(10); try { myvector.at(20)=100; } catch (const std::out_of_range& oor) { std::cerr << "Out of Range error: " << oor.what() << '\n'; } return 0; }

Virtual Constructors?

A virtual call is a mechanism to get work done given partial information. In particular, "virtual" allows us to call a function knowing only any interfaces and not the exact type of the object. To create an object you need complete information. In particular, you need to know the exact type of what you want to create. Consequently, a "call to a constructor" cannot be virtual. The object exists only after the constructor ends.In order for the constructor to be dispatched using the virtual table , there has to be an existing object with a pointer to the virtual table , but how can a pointer to the virtual table exist if the object still doesn't exist?

ADT

Abstract Data type (ADT) is a type (or class) for objects whose behavior is defined by a set of value and a set of operations. The definition of ADT only mentions what operations are to be performed but not how these operations will be implemented. It does not specify how data will be organized in memory and what algorithms will be used for implementing the operations.

Constructors

Constructors are special class functions which performs initialization of every object. The Compiler calls the constructor whenever an object is created. Constructors initialize values to object members after storage is allocated to the object.

Creator of C++

Bjarne Stroustrup

Data abstraction

Data abstraction refers to, providing only needed information to the outside world and hiding implementation details.

Virtual Desctructor

Deleting a derived class object using a pointer to a base class that has a non-virtual destructor results in undefined behavior. To correct this situation, the base class should be defined with a virtual destructor. As a guideline, any time you have a virtual function in a class, you should immediately add a virtual destructor (even if it does nothing). This way, you ensure against any surprises later.

Creator of C

Dennis Ritchie

Creators of SQL

Donald Chamberlin and Raymond Boyce

Garbage collection

Garbage collection is a form of automatic memory management. The garbage collector or collector attempts to reclaim garbage, or memory used by objects that will never be accessed or mutated again by the application. Tracing garbage collectors require some implicit runtime overhead that may be beyond the control of the programmer, and can sometimes lead to performance problems.

Manipulators

Manipulators are used to change formatting parameters on streams and to insert or extract certain special characters. Basic format flags. These manipulators are usable on both input and output streams, although many only have an effect when applied to either output or input streams.

Namespaces

Namespace is a feature added in C++ and not present in C. A namespace is a declarative region that provides a scope to the identifiers (names of the types, function, variables etc) inside it. Multiple namespace blocks with the same name are allowed. All declarations within those blocks are declared in the named scope.

OOP

Object oriented programming aims to implement real world entities like inheritance, hiding, polymorphism etc in programming. The main aim of OOP is to bind together the data and the functions that operates on them so that no other part of code can access this data except that function.

Objects

Objects are basic run-time entities in an object oriented system, objects are instances of a class these are defined user defined data types.

Message passing

Objects communicate with one another by sending and receiving information to each other. A message for an object is a request for execution of a procedure and therefore will invoke a function in the receiving object that generates the desired results. Message passing involves specifying the name of the object, the name of the function and the information to be sent.

cout

On most program environments, the standard output by default is the screen, and the C++ stream object defined to access it is cout. For formatted output operations, cout is used together with the insertion operator, which is written as << (i.e., two "less than" signs).

Polymorphism

Polymorphism means ability to take more than one form. An operation may exhibit different behaviors in different instances. The behavior depends upon the types of data used in the operation. C++ supports operator overloading and function overloading.

Template

Templates are the foundation of generic programming, which involves writing code in a way that is independent of any particular type. A template is a blueprint or formula for creating a generic class or a function. The library containers like iterators and algorithms are examples of generic programming and have been developed using template concept.

Run time polymorphism

Run time polymorphism is supported by virtual functions. The idea is, virtual functions are called according to the type of object pointed or referred, not according to the type of pointer or reference. In other words, virtual functions are resolved late, at runtime.

delete operator

Since it is programmer's responsibility to deallocate dynamically allocated memory, programmers are provided delete operator by C++ language. delete p; //for single variable delete[] p; //for array

STL

The Standard Template Library (STL) is a set of C++ template classes to provide common programming data structures and functions such as lists, stacks, arrays, etc. It is a library of container classes, algorithms and iterators. It is a generalized library and so, its components are parameterized.

STL Algorithms

The header <algorithm> defines a collection of functions especially designed to be used on ranges of elements. A range is any sequence of objects that can be accessed through iterators or pointers, such as an array or an instance of some of the STL containers.

new operator

The new operator denotes a request for memory allocation on the Heap. If sufficient memory is available, new operator initializes the memory and returns the address of the newly allocated and initialized memory to the pointer variable. int *p = NULL; p = new int;

Operators that cannot be overloaded

The operators :: (scope resolution), . (member access), .* (member access through pointer to member), and ?: (ternary conditional) cannot be overloaded.

Hierarchy

There are two main types of hierarchies - classification or composition. Technically, taxonomy is a classification hierarchy - relating ideas or things into types or classes. Another way of relating things or ideas is in a composition hierarchy, by identifying their parts or aspects. Classification shows the relationship between a general class (of a thing or idea) and its members or types. Composition shows the relationship between a complete whole (of a thing or idea) and its parts or aspects.

valarray

std::valarray is the class for representing and manipulating arrays of values. It supports element-wise mathematical operations and various forms of generalized subscript operators, slicing and indirect access.

numeric algorithms

<numeric> header describes a set of algorithms to perform certain operations on sequences of numeric values. Due to their flexibility, they can also be adapted for other kinds of sequences.

Class

A class is a blueprint or template or set of instructions to build a specific type of object. Every object is built from a class. Each class should be designed and programmed to accomplish one, and only one, thing. It details the properties and behaviour of the objects it instantiates.

Default arguments

A default argument is a value provided in function declaration that is automatically assigned by the compiler if caller of the function doesn't provide a value for the argument with default value.

STL Allocators

Allocators handle all the requests for allocation and deallocation of memory for a given container. The C++ Standard Library provides general-purpose allocators that are used by default, however, custom allocators may also be supplied by the programmer.

Abstract class/metaclass

An abstract class is, conceptually, a class that cannot be instantiated and is usually implemented as a class that has one or more pure virtual (abstract) functions. A pure virtual function is one which must be overridden by any concrete (i.e., non-abstract) derived class. This is indicated in the declaration with the syntax " = 0" in the member function's declaration.

STL Iterator

An iterator is any object that, pointing to some element in a range of elements (such as an array or a container), has the ability to iterate through the elements of that range using a set of operators (with at least the increment (++) and dereference (*) operators).

Error handling

C++ provides following specialized keywords for this purpose. try: represents a block of code that can throw an exception. catch: represents a block of code that is executed when a particular exception is thrown. throw: Used to throw an exception. Also used to list the exceptions that a function throws, but doesn't handle itself.

Compile time polymorphism

Compile time polymorphism means compiler knows which function should be called when a polymorphic call is made. C++ supports compiler time polymorphism by supporting features like templates, function overloading and default arguments.

Dynamic binding

In dynamic binding, the code to be executed in response to function call is decided at runtime. C++ has virtual functions to support this.

cin

In most program environments, the standard input by default is the keyboard, and the C++ stream object defined to access it is cin. For formatted input operations, cin is used together with the extraction operator, which is written as >> (i.e., two "greater than" signs). This operator is then followed by the variable where the extracted data is stored.

Inheritance

Inheritance is the process by which objects of one class acquire the properties of objects of another class. It supports the concept of hierarchical classification. Inheritance provides reusability. This means that we can add additional features to an existing class without modifying it.

Differences b/w C and C++

Some C features is deprecated in C++. C does not have classes and objects (C does not support OOP) Structures in C cannot have functions C does not have namespaces (namespaces are used to avoid name collisions). The I/O functions are entirely different in C and C++(ex: printf( ), scanf() etc. are part of the C language). You cannot overload a function in C (i.e. you cannot have 2 functions with the same name in C). Better dynamic memory management operators are available in C++. C does not have reference variables (in C++ reference variables are used in functions). In C constants are defined as macros (in C++ we can make use of 'const' to declare a constant). Inline functions are not available in C.

Access specifier

There are 3 access specifiers for a class/struct/union in C++. These access specifiers define how the members of the class can be accessed. Of course, any member of a class is accessible within that class(Inside any member function of that same class). Moving ahead to type of access specifiers, they are: Public - The members declared as Public are accessible from outside the Class through an object of the class. Protected - The members declared as Protected are accessible from outside the class BUT only in a class derived from it. Private - These members are only accessible from within the class. No outside Access is allowed.

Visibility mode

Visibility mode is used in the inheritance of C++ to show or relate how base classes are viewed with respect to derived class. When one class gets inherited from another, visibility mode is used to inherit all the public and protected members of the base class.

Encapsulation/Data-hiding

Wrapping up(combing) of data and functions into a single unit is known as encapsulation. The data is not accessible to the outside world and only those functions which are wrapping in the class can access it. This insulation of the data from direct access by the program is called data hiding or information hiding.


संबंधित स्टडी सेट्स

Accounting Exam 2 Multiple Choice Practice

View Set

Adult Med Surg - Elsevier - HESI

View Set

Texas Real Estate Principals 1 FInal

View Set