ADVANCED FEATURES OF C++

Post on 21-Apr-2017

115 views 0 download

Transcript of ADVANCED FEATURES OF C++

A presentation on ADVANCED FEATURES OF C++

GLITTERING STAR by

BY

Introduction of c ++C WAS DEVELOPED IN THE 1970’S BY DENNIS RITCHIE OF AT AND T BELL LABSC++ WAS DEVELOPED IN THE EARLY 1980’S BY BJARNE STROUSTRUP OF AT AND BT BELL LABSC++ IS AN “EXTENSION” OF THE C LANGUAGE IN THAT MOST C PROGRAMS ARE ALSO C++ PROGRAMSC++ ,AS OPPOSED TO ,SUPPORTS ”OOPS”.

ADVANCED FEATURES IN C ++

ABSTRACT CLASSEXCEPTION HANDLING

STANDARD LIBRARIESGENERIC PROGRAMMING

TEMPLATES STANDARD TEMPLATE LIBRARY-STL

PARAMETERIZING THE CLASS FILE HANDLING

OBJECTCLASSSTATICCONSTRUCTORDESTRUCTORFRIEND CLASSFRIEND FUNCTIONINLINE FUNCTIONPOLYMORPHISMINHERITANCEABSTRACTIONENCAPSULATIONSCOPE RESOLUTION OPERATOR

Advanced features in c ++

ABSTRACT CLASS ABSTRACT CLASS IS A BASE

CLASS USED FOR DERIVING PURPOSES ONLY.

WHICH CONTAIN ATLEAST ONE PURE VIRTUAL FUNCTION IN IT.IT COULD NOT BE USED FOR

CREATING OBJECTS

IT IS ASSOCIATE AN INITIALIZED WITHTHE VIRTUAL FUNCTION DECLARATION

PURE VIRTUAL FUNCTION

EXAMPLE FOR ABSTRACT CLASS

FOOD IS AN EXAMPLE FOR ABSTRACT CLASS . MAKE AN INSTANCES OF AN APPLE OR A

STEAK OR A PEANUT BUTTER CUP.

steak applePeanut butter cup

EXCEPTION HANDLINGAN EXCEPTION IS A SITUATION IN WHICH A

PROGRAM HAS AN UNEXPECTED CIRCUMSTANCES DURING PROGRAM EXECUTION

CLASSIFICATION OF EXCEPTION HANDLING

oTRY BLOCKoCATCH BLOCKS

oTHROW EXPRESSIONoEXCEPTION SPECIFICATION

Standard librariesStandard library is classified into 2 types

Standard function libraryObject oriented class library

Standard function libraryThe library consists of general-purpose

And stand-alone functions that are not part of any class

l ibrary

Object oriented class library

This library consists of a collection of classesAnd associated functions

Generic programming1. STL USES GENERIC PROGRAMMING

THIS IS NOT OBJECT-ORIENTED PROGRAMMING.NO CLASS HIERARCHY , NO VIRTUAL DISPATCH. TEMPLATES ARE THE ENABLING FEATURES.2.BASED ON CONCEPT INSTEAD OF CLASSES

IF IT LOOKS LIKE A DUCK…IT IS A DUCK.TYPE MATTER LESS THAN THE OPERATIONS

IMPLEMENTED.FUNCTION ADAPT TO THEIR ARGUMENTS AT

COMPILE TIME.

TEMPLATESTHE SAME CODE HAS TO BE REPEATED TO

CARRY OUT THE SAME FUNCTIONON DIFFERENT DATA TYPES . THIS WILL LEAD

TO WASTE OF TIME AND EFFORT. TOSOLVE THIS YOU CAN USE THE TEMPLATE

FACILITY

Syntax:Template<class type>

TWITTER WHATSAPP

FACEBOOK

EXAMPLE

FOR

TEMPLATES

Example program#include<iostream.h>

int max (int a,int b){

Return(a>b)?a:b;}

Float max(float a, float b){

Return(a>b)?a:b;}

Char max(char a, char b){

Return(a>b)?a:b;}

Void main(){

Cout<<kmax(20.30)<<endl;Cout<<max(4.5,6.7)<<endl;

Cout<<max(‘ a ’, ’ b ’)<<endl;}

Standard templates libraryTHE STANDARD

TEMPLATE LIBRARY PROVIDE A

SET OF WELL STRUCTURESGENERIC C ++ COMPONENTSTHAT WORKS

TOGETHER IN A SEAMLESS WAY.

STL HAD THREE BASIC COMPONENTS:

CONTAINERS

GENERIC CLASS TEMPLATES FOR STORING COLLECTION OF DATA.

ALGORITHMS

GENERIC FUNCTION TEMPLATES FOR OPERATING ON CONTAINERS.

ITERATORS

GENERALIZED ‘SMART’ POINTERS THAT FACILITATE USE OF CONTAINERS.

THEY PROVIDE AN INTERFACE THAT IS NEEDED FOR STL ALGORITHMS TO OPERATE ON STL CONTAINERS.

STRING ABSTRACTION WAS ADDED DURING STANDARDIZATION

PARAMETERIZING THE CLASSParameterizing classes specify parameters that must be

Defined by any binding class.Parameterizing class is referred as class templates

FILE HANDLINGA file is a collection of

related data stored in

a particular area onthe disk

Programs can be designed to Perform the read and write

operationsOn these files

OBJECTIT IS A BASIS RUNTIME ENTITYAN OBJECT IS A COLLECTION OF DATA AND ASSOCIATEDMEMBER FUNCTION TO PERFORM VARIOUS TASK

classClass is a group of object

Class is a collection of similar object or object of same type

STATIC MEMBER OF A CLASS CAN CONTAIN STATIC MEMBER DATA AND STATIC MEMBER FUNCTION.IT MUST BE DECLARE WITH THE KEYWORD STATIC

STATIC MEMBER

STATIC DATA MEMBERWHEN OBJECT IS CREATED IT INTIALIZE

AS ZERO COPY OF ALL MEMBER IS CREATED WHEN

ENTIRE CLASS IS SHARED

STATIC MEMBER FUNCTIONA FUNCTION CAN BE INVOKED USING A CLASS NAME

IS CALLED STATIC MEMBER FUNCTION

Constructor and destructorsCONSTRUCTOR

DESTRUCTOR

Constructor and destructor are special member

function of classes that are used to

create and destroy class object

Types of constructorCopy constructorDynamic constructorDefault constructorParameterized constructor

COPY CONSTRUCTORIt is a special type of constructor which will create an object as a

copy of a previously created object

Dynamic constructorIt is used to allocate the memory to the object

To the runtime using new operator

RUNTIMEMEMORY ALLOCATE

OBJECT

Default constructorIt is a constructor which doesn’t

Take any argument

parameterized constructorWhen object is created it takes the

arguments with it

FRIEND FUNCTIONA function that is declare with a keyword friend

is known as friend function.FRIEND FUNCTION IS USED TO ACCESS

THE PRIVATE DATA

INLINE FUNCTIONIf the member function is

defined inside the class definitionIs called inline function

polymorphismIT IS ABILITY TO TAKE MORE

THAN ONE FORM

Types of polymorphism

COMPILE TIME POLYMORPHISMObject is bound to the function

call at the compile time

Eg: function and operator overloading

Compile time polymorphismRuntime polymorphism

FUNCTION OVERLOADINGA function having same name but

performDifferent task for different instances

Operator overloading

The process of making an operator to exhibit different

Behaviours in different instances

Eg: virtual function,pointers

INHERITANCESInheritances is the process of forming a new classs byacquiring or inherited the properties of object of base class or existing class

encapsulationWrapping upon data and function

into single entity

Eg :

Tele

visi

on r

emot

e

SCOPE RESOLUTION OPERATORS (::) ARE USED TO DEFINE A FUNCTION OUTSIDE A CLASS OR WHEN WE WANT TO

USE A GLOBAL VARIABLE BUT ALSO HAS A LOCAL VARIABLE WITH SAME NAME

Scope resolution operator

THANK U FRIENDS