We present you new model of LG commercial washing machine Giant C PRO. What is new? Auto tub cleaning and auto dosing interfaceDescripción completa
Alladin, Walt Disney. This was transposed by me. A Simplified music sheet for Beginner in keyboard, electric organ, or pianoFull description
Descripción completa
Full description
new
Full description
hop
new
C, C++, C# Programming ConceptsFull description
Descripción: New york new york big band not sinatra key
Version 2.2: July 2012 ISBN: 978-9080179301 New Aesthetic New Anxieties is the result of a five day Book Sprint organized by Michelle Kasprzak and led by Adam Hyde at V2_ from June 17–21, 2012. A...
k.608 for wind quintetFull description
Descripción: frank sinatra
New york new york big band not sinatra key
Descripción: Sheet Music (PDF)
Frank Sinatras New York New YorkDescripción completa
C++
)igh Le*el Language
Object Oriented
Procedural C
Fully
Partial
C++
JAVA
Procedural
Object Oriented
Focus on procedure
Focus on data
Coding is Lengthy
Coding Minimized
Cost is high
Cost is lo
Main Mainta tain inan ance ce com comple! ple! Main Mainta tain inan ance ce "im "imple ple #o reusability reusability %op %op to bottom procedure o& coding'
$es reusability reusability present by inheritance (ottom to top procedure o& coding'
,-./0 C 1ennis 2itchie ,345s/0 C++ 6c ith class7 1e*eloped by (jarne "trostrup C+simula 8-
Object Oriented Programming/0 En object oriented programming A program is conceptually organized around its data and associated methods'
Features o& object oriented programming 1ata Abstraction data hiding Gncapsulation Enheritance Polymorphism/ =compile time polymorphism a=&unction o*erloading b=operator o*erloading o*erloading .=run time polymorphism a=*irtual classes b=*irtual &unctions &unctions
He can understand all &eatures by using real li&e e!ample or programming e!ample
(ut &irst e ill understand all &eatures by real li&e e!ample Abstraction/ 0 %o sho the essential &eature ithout shoing the bacIground details or comple!ity' %his is called Abstraction Gncapsulation/ 0 %o rapping up data and &unction in a single entity
CLA"" A#1 O(JGC% /0 Class/0 A class is a user de&ine data type that combine both member *ariable o& primary and deri*ed data type and member &unction in it' A class is a &undamental blocI o& an object oriented programming' Class is the most poer&ul data type in C++ a class de&ines the data and beha*ior<&unctions= o& the data type' Programmers can then create objects that are instances or *ariable o& this class' classes support inheritance a &undamental part o& object0oriented programming'
"ynta! %o declare a class/0 class classname > Access speci&iers/ *ariable declration
KKdata members' access speci&ier/ &unction declraration KKmember &unctions class/0 it is a Ieyord that tell to the compiler ne data type is declared' classname/0 it is a identi&ier' access modi&ier/0 they control the accessibility accessibility o& class member &rom outside boundary o& class' Object/0 Objects are instances o& a gi*en data type 'the data type pro*ides a blueprint &or the object that is created or instantiated hen the application is e!ecuted' A sample program by using class /0 9include:iostream'h; 9include:conio'h; class A > public/
"um o& to no' by using Class' 9include:iostream'h; 9include:conio'h; class A > Ent abc public/ *oid read<= > cout::@enter to no'@ cin;;a;;b *oid sum<=
Void display display<= <= > cout::@sum@::c Void A// sum<= > Ca+b *oid main<= > A obj Obj'read<= Obj'sum<= Obj'display<= Cout::@the sum o&@::a::@and@::b::@is/@::c getch<= return <4= Access Modi&ier/ %hey are used &or control the accessibility o& class member &rom outside boundary o& class' %here are access modi&ier present in C++'
'= Public .'= Pri*ate '= Protected Public/0 %he all members that are declared under public section can be access inside the boundary o& class and can be access outside outside boundary o& class' Pri*ate/0 %he all members that are declared under pri*ate section can be access inside the boundary o& class but can not be access access outside boundary o& class' Protected/ 0 "ame as pri*ate in a class but its mean change in inheritance'
Access speci&ier/ Nsed in class Publi Publicc $es Pri*ate Pri*ate $es Protecte Protected d $es
Nsed in outside o& class $es #o #o
#ote/ (y de&ault de&ault Access modi&ier is is pri*ate'
For Gg'/ 9include:iostream'h; 9include:conio'h; class A > int !yz public/ *oid disp<= > z!+y cout::@sum is @::z *oid main<= > A obj obj'!,4 obj'y4 obj'disp<=
getch<= Gg/ 9include:iostream'h; 9include:conio'h; class A > int !yz public/ *oid disp<= > z!+y cout::@sum is @::z *oid main<= > Ent ab A obj Cout::@Gnter to no'@ Cin;;obj'a Cin;;obj'b Obj'disp<=
getch<=
9include:iostream'h; 9include:conio'h; class A > int !yz public/ *oid input<= > cout::@Gnter to numbers@ cin;;!;;y *oid disp<= > z!+y cout::@sum is @::z *oid main<= > A obj obj'input<=
obj'disp<= getch<= 9include:iostream'h; 9include:conio'h; class A > int !yz *oid input<= > cout::@Gnter to numbers@ cin;;!;;y public/ *oid disp<= > z!+y cout::@sum is @::z *oid main<= > A obj obj'input<=
obj'disp<= getch<= OKP/ Grror in input Function Access' Access' 9include:iostream'h; 9include:conio'h; class A > int !yz *oid input<= > cout::@Gnter to numbers@ cin;;!;;y public/ *oid disp<= > input<= z!+y cout::@sum is @::z *oid main<=
> A obj obj'disp<= getch<= OKP/ Program ill be e!ecute'
Class member &unction de&inition/ 0 e can de&ine class member &unction in to places' inside the boundary o& class outside boundary o& class #ote/ 0 e ill ill declared class class &unction inside inside the boundary o& class but e can de&ine them in inside the boundary o& class or outside boundary o& class Enside the boundary o& class/0
9include:iostream'h; 9include:conio'h; class A
> char n6.47 char mn6.47 char &n6.47 int mr public/ *oid input<= > cout::@Gnter your name@ gets cout::@n1etails cout::@n1etails aren@ cout::@#ame is ?::n cout::@nFather5s name name is ?::&n
cout::@Mother5s name name is ?::mn cout::@2oll #umber is ?::r cout::@MarIs is ?::m *oid main<= > A obj obj'input<= obj'disp<= getch<= Outside boundary o& class/0 "ynta! &or de&ine &unction outside boundary o& class 2eturntype class#ame//&unction#ame<= class#ame//&unction#ame<= > KKstat // scope resolution operater' 9include:iostream'h; 9include:conio'h; class A
> char n6.47 char mn6.47 char &n6.47 int marIs roll public/ *oid input<= *oid disp<= *oid A//input<= > cout::@Gnter your name@ gets
cout::@n1etails cout::@n1etails aren@ cout::@#ame is ?::n cout::@nFather5s name name is ?::&n cout::@Mother5s name name is ?::mn cout::@2oll #umber is ?::r cout::@MarIs is ?::m *oid main<= > A obj obj'input<= obj'disp<= getch<= Creating More than one object /0 He can also maIe more than one object o& class type' G*ery object taIe separate memory location HAP that accept and display . student in&ormation 9include:iostream'h; 9include:conio'h;
class A > char n6.47 char mn6.47 char &n6.47 int mr public/ *oid input<= *oid disp<= *oid A//input<= > cout::@Gnter your name@ gets
> cout::@n1etails cout::@n1etails aren@ cout::@#ame is ?::n cout::@nFather5s name name is ?::&n cout::@Mother5s name name is ?::mn cout::@2oll #umber is ?::r cout::@MarIs is ?::m *oid main<= > A objI obj'input<= I'input<= obj'disp<= I'disp<= getch<=
Array Objects/0 e can also create array object o& class type G*ery array object taIe separate memory location'
HAP &or array o& class' 9include:iostream'h; 9include:conio'h; class A > char n6.47 char mn6.47 char &n6.47 int mr public/ *oid input<= *ois disp<= *oid A//input<= > cout::@Gnter your name@ gets
cin;;r *oid A//disp<= > cout::@n1etails cout::@n1etails aren@ cout::@#ame is ?::n cout::@nFather5s name name is ?::&n cout::@Mother5s name name is ?::mn cout::@2oll #umber is ?::r cout::@MarIs is ?::m *oid main<= > A obj647 Ent E For Obj6i7'input<= &or obj6i7'disp<=
getch<=
Parameterized Method/0 A class can ha*e parameterized method' method' A &unction can taIe taIe parameter' parameter' A method ho taIe parameter parameter is called parameterized method' A method can taIe any type o& parameter liIe int char &loat long double array class object as a argument' G!ample /0 9include:iostream'h; 9include:conio'h; class A > int !yz public/ *oid input !a yb
*oid disp<= > z!+y cout::@sum is ?::z *oid main<= > A obj obj'input<.3,= obj'disp<= getch<= G!ample ./0 < Value taIen by user in main &unction= 9include:stdio'h; 9include:conio'h; class A > int !yz public/ *oid input
!a yb *oid disp<= > z!+y cout::@sum is ?::z *oid main<= > int mn cout::@Gnter to number@ cin;;m;;n A obj obj'input
Value 2eturning Function/ Functio n/ Hhen Function G!ecution is complete a &unction can return a *alue to the caller 'A &unction can return any type o& *alue'
LiIe int char &loat &loat long double etc' 2eturn eyord is used &or return any *alue' Class A > Ent !y Public/ Void input Qa $b Ent disp<= > 2eturn < ! + y = Void main<= > Ent r m n Cout::@enter the no' m and n@ Cin;;m;;n A obj
OKP/ G22O2 .' Class A > Ent !yz Public/ Void input Qa $b Void disp<= > R!+y Cout::@sum@::z ' this can be used a program &or ?this@ operator' Class A > Ent !yz Public/
Void input !! yy Void disp<= > R!+y Cout::@sum@::z Void main<= > A obj Obj'input<4'S4= Obj'disp<= OKP/ "um0.6Barbage *alue7 S' Class A >
Constructor and 1estructor class A > int !, KK error int y4 KK error public / *oid disp<= > cout::!::y #ote/ 0 e cannot cannot initialize initialize class data members at the time o& declaration' E& e ant to initial class member e ha*e to maIe a &unction and e can gi*e *alue inside the &unction liIe this inside the class in a member &unction using a constructor' class A > int ! int y public /
Constructor /0 A constructor is a special member &unction o& the class it is automatically automatically called hene*er object o& that class is created' Constructor has same name as class name in hich constructor has declared' Constructor is used &or initial class member' E& any class has no constructor the compiler automatically automatically create de&ault constructor in class'
"ome points about constructor/0 '= Et has same name as class name in hich it is declared' .'= constructor cannot be called' Et is automatically called hene*er object o& that class is created' '= Et is used &or initial class member' S'= Constructor has no return type not e*en *oid' T'= Constructor cannot return any *alue' 8'= Constructor cannot be inherited' -'= A class can ha*e more than one constructor but signature or parameters parameters are di&&erent di&&erent Constructor alays declared under public section' Class A > Ent !y Public/ A<= > Q4 $.4
A obj KKconstructor KKconstruc tor ill be callled
Constructor are to types '=de&ault constructor .'=Parameterized Constructor 1e&ault constructor/0 A constructor ith no parameter is called called de&ault constructor constructor'' E& your class has no constructor then compiler co mpiler ill create de&ault constructor in the class'
class A > int ! int y pri*ate / A<= > !, y,4 cout::!::y *oid main<= >
A obj getch<=
KKerror
OKP compilation error e cannot create object o& abo*e class because constructor declared under pri*ate section
Parameterized Constructor/0 A Constructor ith parameter is called parameterized constructor constructor'' He must pass *alue *alue &or parameterized constructor at the time o& object creation' class A > int ! int yz public / A
!a yb *oid disp<= > z!+y cout::@"um is ?::z *oid main<= > A obj KKerror A obj<,434= obj<,43 4= KKcorrect getch<=
G!ample ./ class A > int ! int yz public / A
> !a yb *oid disp<= > z!+y cout::@"um is ?::z *oid main<= > int mn cout::@enter to number@ cin;;m;;n A obj
Hhat5s the output/0 class A
> int ! int yz public / A !a yb *oid disp<= > z!+y cout::@"um is ?::z *oid main<= > A obj KKerror A obj.<,434= KK correct A I
A obj/0 this line produce error because class has parameterized constructor it is mandatory &or us pass *alue at the time o& object creation' 1e&ault Argument Constructor class A > public/ A *oid main<= > A obj A Ip<,4= getch<=
G!ample .<hat5s the output= class A
> int ! int yz public / A<= > A !a yb *oid disp<= > z!+y cout::@"um is ?::z *oid main<= > A obj A obj.<,434= A I
getch<= Program ill be e!ecuted'
Constructor call/0 A constructor can be call in to ays implict call A ob<.434= ob<.43 4= e!plicit call A ob A<.434= Constrcutor o*erloading/ A class can ha*e more than one constructor but signature are di&&erent' di&&erent' "ignature means means type o& parameter or number o& parameter are di&&erent' 9include:iostream'h; 9include:conio'h; class A > int !yz
Public/ A<= > !,4 y44 A !a y. A !a yb *oid disp<= > z!+y cout::@"um is@::z Void main<= > A
A .<484= .<484 = A <= 'disp<= .'disp<= 'disp<= getch<=
Function o*erloading/ 9include:stdio'h; 9include:conio'h; class A > int !yz public/ *oid input< = > !,4 y44 z!+y cout::@"um is@::z
Copy Constructor/0 Et is used &or initial one object member &rom another object member ith same *alue' Copy constructor present in int !y public/ "ample !a yb "ample<"ample ob= > !ob'! yob'y *oid sho<= > cout::!::@t@::y
*oid main<= > "ample s<4.4= "ample s.
1estructor/ 0 it is used &or deallocate memory that is pro*ided by constructor' 1estructor has same name as class name but precede by tilde
S= 1estructor alays declared under public section' class A > int ! int yz public / A !a yb UA<= KKdestructor > *oid disp<= > z!+y cout::@"um is ?::z *oid main<= > int mn
cout::@enter to number@ cin;;m;;n A obj int !y public/ A<= *oid sho<= A//A<= > !, y3 *oid A//sho<= > int z z!+y
cout::@"um is ?::z
Function o*erloading/ A class can ha*e more than one &unction o& same name but signature are di&&erent' di&&erent' "ignature means type o& parameter or number o& parameter are di&&erent' 9include:iostream'h; 9include:conio'h; class A > int !yz public/ *oid input< = > !,4 y44 z!+y cout::@"um is@::z
int !yz public/ *oid input<= > !,4 y44 z!+y cout::@"um is@::z int input<= > !, y. z!+y return z Void main<= > int r A 'input<= r'input<=
getch<= "tatic Member/0 Hhat5s %he OKp class A > int ! public/ A<= > !4 *oid sho<= > cout::! !++ *oid main<= > A aa.aaS aa.a aS a'sho<=
a.'sho<= a'sho<= aS'sho<= a'sho<= a'sho<= a.'sho<= oKp 4 4 4 4 . .= class A > static int ! public/ A<= > !4
*oid sho<= > cout::! !++ *oid main<= > A aa.aaS aa.a aS a'sho<= a.'sho<= a'sho<= aS'sho<= a'sho<= a'sho<= a.'sho<= oKp 4 . S T
8 "tatic Member /0 A class can contain static member means static *ariable and static &unction' static member *ariable /0 %here is only one copy o& static member present in the memory' All objects share that copy' #ote/0 = "tatic *ariable must declared inside the class' .= "tatic *ariable must de&ine outside the boundary o& class' = "tatic *ariable automatically initial ith zero' "tatic Function /0 He can also create static &unction by using static Ieyord' #ote = "tatic &unction can access only static member o& the class .= "tatic &unction call by using class#ame//&unctionname<=
class A > public / static *oid input<= > cout::@)ello@ *oid main<= > A//input<=
E#)G2E%A#CG/ He can e!tend &unctionality o& an e!isting class by creating a ne class that deri*es &rom the e!isting class' %he deri*ed class inherits the properties o& the base class and you can add or o*erride methods and properties are reuired' %here are to main classes in inheritance'
' "uper class or base class or parent class' .' 1eri*ed class or sub class or child class' (ase class/ An e!isting class hich property used by deri*ed or sub class 'it is also Inon as parent or super class' 1eri*ed Class/ A nely de&ined class that use the property o& an e!isting class ' Enheritance present in many &orms' ' "ingle inheritance' .' Multiple inheritance' ' )ierarchal in inheritance' S' Multile*el in inheritance' T' )ybrid inheritance' "ingle inheritance/ Hhen a class inherits &rom only one base class it is called single inheritance' base class and deri*ed class
Multiple inheritance/ Hhen a class inherits &rom more than one base class it is called multiple inheritance'more than base class and deri*ed class' )ierarchal inheritance/ Hhen more than one class inherits &rom same base it is called called hierarchal inheritance' inheritance' Multile*el inheritance/ Hhen a class inherits &rom a class ho also inherits &rom another class it is called multile*el inheritance' )ybrid inheritance/ Et is a collection o& to or more than inheritance' "ingle Enheritance/ 9include:iostream'h; 9include:conio'h; 9include:stdio'h; class person >
char n6.47 char &n6.47 char city647 public/ *oid readdata<= > cout::@Gnter your name@ gets cout::@n1etails cout::@n1etails aren@ cout::@#ame is ?::n cout::@nFather5s name name is ?::&n cout::@city is ?::city Class employee/ public person > Ent id Float sal
9include:iostream'h; 9include:conio'h; 9include:stdio'h; class person > char n6.47 char &n6.47 char city647 public/ *oid readdata<= > cout::@Gnter your name@ gets cout::@n1etails cout::@n1etails aren@
cout::@#ame is ?::n cout::@nFather5s name name is ?::&n cout::@city is ?::city Class employee/ public person > Ent id Float sal Public/ Void input<= > 2eaddata<= Cout::@enter id@ Cin;;id Cout::@enter salary@ Cin;;sal Void disp<= > 1ispdata<= Cout::@id@::id Cout::@n salary@::sal salary@::sal
9include:iostream'h; 9include:conio'h; 9include:stdio'h; class person > char n6.47 char &n6.47 char city647 public/ *oid readdata<= > cout::@Gnter your name@ gets
cout::@Gnter your city@ gets cout::@n1etails cout::@n1etails aren@ cout::@#ame is ?::n cout::@nFather5s name name is ?::&n cout::@city is ?::city Class employee/ public person > Ent id Float sal Public/ Void input<= > Cout::@enter id@ Cin;;id Cout::@enter salary@ Cin;;sal Void disp<= >
Multiple Enheritance/ A class can inherits more than one class' "ynta!/ 1eri*ed class name/ *isibility mode base class name *isibility mode base class name' 9include:iostream'h; 9include:conio'h; 9include:stdio'h; class person
> char n6.47 char &n6.47 char city647 public/ *oid input<= > cout::@Gnter your name@ gets cout::@n1etails cout::@n1etails aren@ cout::@#ame is ?::n cout::@nFather5s name name is ?::&n cout::@city is ?::city Class student > Ent rm
Ent reg Public/ Void getdata< getdata<== > Cout::@enter roll no'@ Cin;;r Cout::@enter marIs@ Cin;;m Cout::@enter reg' no'@ Cin;;reg Void dispdata<= > Cout::@n your reg' no' is@::reg Cout::@n your id is ?::r Cout::@your marIs is@::m Class graduate/ public person public student > Char st6.47 Public/ Void taIe<= > Enput<=
class person > char n6.47 char &n6.47 char city647 public/ *oid input<= > cout::@Gnter your name@ gets cout::@n1etails cout::@n1etails aren@ cout::@#ame is ?::n cout::@nFather5s name name is ?::&n cout::@city is ?::city Class student / public person >
Ent rm Ent reg Public/ Void getdata< getdata<== > Cout::@enter roll no'@ Cin;;r Cout::@enter marIs@ Cin;;m Cout::@enter reg' no'@ Cin;;reg Void dispdata<= > Cout::@n your reg' no' is@::reg Cout::@n your id is ?::r Cout::@your marIs is@::m Class graduate/ public student > Char st6.47 Void taIe<= > Betdata<=
Cout::@enter your stream@ Bets 1ispdata<= Cou::@enter your stream@::st *oid main<= > graduate obj Obj'taIe<= Obj'sho<= Betch<= Access Modi&ier in inheritance/ Public 1eri*ation/
Access Access Modi& Modi&ier ier used used in deri*e deri*e Access ccess by object
o& 1eri*ed class
Public Pri*ate Protected
yes no yes
yes no no
Pri*ate deri*ation/ Access Access Modi& Modi&ier ier used used in deri*e deri*e Access ccess by object o& 1eri*ed class
Public Pri*ate Protected
Protected deri*ation/
yes no yes
no no no
Access Access Modi& Modi&ier ier used used in deri*e deri*e Access ccess by object o& 1eri*ed class
Public Pri*ate Protected
Class A > Ent !y Public/ Ent ab Protected/ Ent mn Class ( public A > Public/ Void disp<=
yes no yes
no no no
QT A4 MT
KKG22O2
Void main<= > ( obj Obj'b Obj'yT KKG22O2 Obj' bj'n.4 n.4 KK G22 G22O2 Constructor in inheritance/ '= %he base base class class cons constru tructo ctorr is constr construct ucted ed be&ore the deri*ed class constructor constructor means hen e create instance
constructor because deri*ed class constructor pass *alue &or base class constructor' Class A > Public/ A<= > Cout::@const o& A@ Void disp<= > Cout::@hello@ Class (/public A > Public/ (<= > Cout::@const o& (@ Void main<=
> ( Obj OKP/ Const o& A Const o& ( Class A > Public/ Void disp<= > Cout::@hello@ Class (/Public A > Public / (<= > Cout::@const o& (@ Void main<= >
( obj OKP/ const o& (
Class A > Public/ A<= > Cout::@const o& A@ Void disp<= > Cout::@hello@ Class (/Public A > Public / Void sho<=
> Cout::@hello &riends@ Void main<= > ( obj OKP/ const o& A Class A > Public/ A Cout::@the *alue o& !@::! Class (/Public A > Public / Void sho<= > Cout::@hello &riends@
Void main<= > ( obj OKP/ G22O2
Class A > Public/ A Class (/Public A > Public / (<=/A<.T= >
KK( obj<.T=
Void main<= > ( obj
Class A > Public/ A Class (/Public A > Public / ( Void main<= > ( obj<..T=
Ambiguity in multiple inheritance/ Class A > Public/ Ent ! Class (/public A > Public/ Ent y Class C/public A > Public/ Ent z Class 1/public (public C > Public/ Void disp<=
( class has ! and y as a member and C class has Q and R as a member hen e inherit ( and C class in 1 then 1 class has to copy o& ! in memory one o& ( and another by C "o Q,4 ill produce error e can correct them by using/ (y using scope resolution operator '= Class A
> Public/ Ent ! Class (/public A > Public / Ent y Class C /public A > Public/ Ent z Class 1/public C( > Public/ Void disp<= > (//!,4 Cout::@*alue@::(//! Void main<= >
1 obj Obj'disp<= .'= (y using *irtual (ase class/ Class A > Public/ Ent ! Class (/public *irtual A > Public/ Ent y Class C/public *irtual A > Public/ Ent z Class 1/public (public C > Public/
Pointer object o& class/ He can also create pointer object o& a class hen e create pointer object o& class e can access class member ith the help o&<0;= sign in place o& <'= operator' Class A > Ent !y Public/ Void input<=
> Cout::@enter to no'@ Cin;;!;;y Void disp<= > R!+y Void main<= > A Wobj Objne A Obj0;input<= Obj0;disp<= 1elete obj Betch<= #GH/ it is used &or dynamically dynamically allocated allocated memory' 1GLG%G/ it is used &or deallocate memory'
POL$MO2P)E"M/ %here are to types o& polymorphism/ = Compi Compile le time time or stat static ic polym polymor orph phis ism m or or early binding' GQ/ = &unction o*erloading .= Operator o* o*erloading = 2untime polymorphism or dynamic polymorphism or late late (inding' GQ/ Method o*erriding' (inding/ %o attach an object ith &unction Inon as binding ' %here are to types o& (inding/ '= Garly Garly bindi binding/ ng/ in in early early bindi binding ng an obje object ct attach ith method at compile time' .'= .'= Late Late (ind (indin ing/ g/ in late late bind bindin ing g an obje object ct attach ith &unction at run time' "ynta! &or ne command/ Class_name=*object; Object=new class name #o as theobject theobject is pointer type type e use 0;
Class A > Public/ Void disp<= > Cout::@)ello class A@ Class (/public A > Public/ Void display display<= <= > 1isp<= Cout::@hello class (@ Void main<= > A Wobj Objne A Obj0;disp<=
Objne ( Obj0;disp<= Betch<= OKP/ class A Class A Class A > Public/ Virtua Virtuall Vo Void disp<=4 disp<=4 Class (/public A > Public/ Void disp<= > Cout::@hello class (@ Class C/public A > Public/ Void disp<=
> Cout::@hello class C@ Void main<= > A Wobj Objne ( Obj0;disp<= Objne C Obj0;disp<= Betch<= OKP/ )ello class ( )ello Class C
Pure *irtual &unction/0 A &unction ith no body is called pure *irtual &unction' "ynta! to declare *irtual &unction/ Virtual returntype &unction name<=4
(ase class pointer object can access deri*ed class &unction but must de&ined ith *irtual Ieyord in base class'
Class A > Public/ Void disp<= > Cout::@)ello class A@ Class (/public A > Public/ Void disp<= > Cout::@hello class (@ Void main<= > ( obj
Obj'disp<= Obj'disp<= Betch<= OKP )ello Class A )ello class (
Class A > Public/ Void disp<= > Cout::@)ello class A@ Class (/public A > Public/ Void disp<= > 1isp<=
Cout::@hello class (@ Void main<= > ( obj Obj'disp<= Betch<= OKP/ 2un time error "tacI o*er&lo
Class A > Public/ Void disp<= > Cout::@)ello class A@ Class (/public A > Public/
An inter&ace describes the beha*ior or capabilities o& a C++ class ithout committing to a particular implementation o& that class'
%he %he C++ C++ inte inter& r&ac aces es are are impl implem emen ente ted d usin using g and thes thesee abst abstra ract ct clas classe sess abstra abstract ct classe classess and should not be con&used ith data abstraction hich is a concept o& Ieeping implementation details separate &rom associated data' A class is made abstract by declaring at least one o& its &unctions as pure virtual &unction' A pure *irtual &unction is speci&ied by placing X 4X in its declaration as &ollos/ class (o! > public/ *irtual double getVo getVolume<= 4 pri*ate/ double length double breadth double height %he purpose o& an abst abstra ract ct clas classs
object o& an abstract compilation error'
class
causes
a
%hus i& a subclass o& an A(C needs to be instantiated it has to implement each o& the *irtual &unctions hich means that it supports the inter&ace declared by the A(C' Failure to o*erride a pure *irtual &unction in a deri*ed class then attempting to instantiate objects o& that class is a compilation error' Classes that can be used to instantiate objects are called concrete classes' Abstract Class G!ample/ Consider the &olloing e!ample here parent class pro*ides an inter&ace to the base class to implement a &unction called getArea()/ 9include :iostream; class "hape > public/ *irtual int getArea<= 4 *oid setHidth
> idth *oid set)eight height h protected/ int idth int height KK 1eri*ed classes class 2ectangle/ public "hape > public/ int getArea<= > return <idth W height= class %riangle/ public "hape > public/ int getArea<=
> return <idth W height=K. int main<*oid= > 2ectangle 2ect %riangle %ri 2ect'setHidth
%otal 2ectangle area/ T %otal %otal %riangle area/ $ou can see ho an abstract class de&ined an inter&ace in terms o& getArea<= and to other classes implemented same &unction but ith di&&erent algorithm to calculate the area speci&ic to the shape'
Operators o*erloading in C++/ G*ery operator has prede&ined meaning they orI on primiti*e data type liIe + operator add to no' to change the &unctionality o& an operator so operator can orI on user de&ined data type is Inon as operator o*erloading' $ou can rede&ine or o*erload most o& the built0 in operators a*ailable in C++' %hus a programmer can use operators ith user0 de&ined types as ell'
O*erloadableK#on0o*erloadableOperators/
Folloing is the list o& operators hich can be o*erloaded/ +
0
W
K
Y
Z
[
U
\
:
;
:
;
++
00
::
;;
\
[[
+
0
K
Y
Z
[
W
::
;;
67
<=
ne
delete ne 67 delete 67
0;
0;W
Folloing is the list o& operators hich can not be o*erloaded/ //
'W
'
]/
O*erloaded operators are &unctions ith special names the Ieyord operator &olloed by the symbol &or the operator being de&ined'
LiIe any other &unction an o*erloaded operator has a return type and a parameter list' (o! operator+
class (o!
%emplates are the &oundation o& generic programming hich in*ol*es riting code in a ay that is independent o& any particular type' A template is a blueprint or &ormula &or crea creati ting ng a gene eneric ric clas classs or a &unct unctiion' on' %he library containers liIe iterators and algorithms are are e!am e!ampl ples es o& gen generi eric prog progrramm amming ing and ha*e been de*eloped using template concept' %here is a single de&inition o& each container such as vector but e can de&ine many di&&erent Iinds o& *ectors &or e!ample vector #int$ or vector #string$'
$ou can use templates to de&ine &unctions as ell as classes let us see ho do they orI/ Function Functio n %emplate/ %emplate/ %he general &orm o& a template &unction de&inition is shon here/ template :class type; ret0type &unc0 name KK body o& &unction )ere type is a placeholder name &or a data type used by the &unction' %his name can be used ithin the &unction de&inition' %he &olloing is the e!ample o& a &unction tem templat platee that hat retu return rnss the ma!im a!imum um o& to *alues/
Void add Ent c
Ca+b Cout::@sum@::c 9include :iostream'h; 9include :string'h; template :class %; *oid add<% a % b= > % c ca+b cout::@"um ?::c *oid main <= > add<4.4= add<4'84'-= E& e compile and run abo*e code this ould produce the &olloing &olloing result/ Class %emplate/ Just as e can de&ine &unction templates e can also de&ine class templates' %he general
&orm o& a generic class declaration is shon here/ template :class type; class class0name > ' ' ' )ere t%pe hich ill inst instan anti tiat ated ed'' generic data list'
is the placeholder type ype name ame be speci&ied hen a class is $ou can can de&i de&ine ne more more than than one one type by using a comma0separated
Constant member& e can declare constant *ariable constant &unction and constant object' A const object can call only constant member'
A class can also contain const member' e can not modi&y the *alue o& const ember ' 9include:iostream'h; 9include:conio'h; class A >
public/ *oid disp cout::X*alue o& a X::a *oid main<= > cout::Xhello X A obj obj'disp<4= getch<= Program il be e!ecuted .= 9include:iostream'h; 9include:conio'h; class A > public/ *oid disp aa+. cout::X*alue o& a X::a
Friend Function/0 A &riend &unction is a &riend o& a class' it can access pri*ate member o& a class ith the help o& object' 9include:iostream'h; 9include:conio'h; class A > int !y public/
= A &r &rie iend nd &un &unct ctio ion n is a &ri &rien end d o& the the clas classs it can declared in any blocI public pri*ate or protected' protected' .= it is not not a membe emberr o& o& a clas classs = it can can acc acces esss pri pri*a *ate te memb member er o& a cla class ss ith the help o& object' S= it call call only only by &unct unctio ion n nam name T= it body body de&i de&ine ned d out outsi side de the the cla class ss'' %ype con*ersion/0 %here are to types o& type con*ersion = Empl Emplic icit it %y %ype Con Con*e *ers rsio ion/ n/00 Et is don donee by compiler .= G!pli G!plici citt %y %ype Con Con*e *ers rsio ion/ n/00 Et is don donee by programmer' programmer' Et is also called called type casting' implicit type con*ersion int a, long ba G!plicit %ype Con*ersion long a,4 int b
Pro!y Class/0 A pro!y class is a stand0in &or another class' Let^s suppose you ha*e a class that has a method that taIes 84 seconds to complete' %hat means e*erytime you call that method your program aits' (ut let^s also assume you rarely call that method' Let^s &urther assume this method is named Load<= and the class is MyClass G!pand["elect[Hrap[Line G!pand["elect[Hrap[Line #umbers class MyClass > public/ *oid Load<= KKtaIes a long time *oid AMethod<= etc'''
KKthe other methods'
'
%he pro!y class ould looI liIe/ 6codecpp7 class MyClassPro!y > MyClassW theObject public/ MyClassPro!y<= / theObject<4= > MyClassW operator0;<= MyClass operatorW<= "o hen you create a MyClassPro!y object the MyClassW inside is set to zero' #o you use MyClassPro!y MyClassPro!y objects instead instead o& MyClass objects' E& someone needs the MyClass object they use the operator0; o*erload o& MyClassPro!y' %his &unction just returns the MyClassW i& the MyClass object e!ists otherise is creates it and calls Load<='
"o not until you use the pro!y object ith the 0; operator do you see the 84 seccond delay' delay'
MyClassPro!y p
KKno delay
p0;AMethod<= bject is created created
KK)ere the MyClass MyClass o
KKLoaded and the MyCl ass//AMethod called'
'ception aning in C++
An e!ception is a problem that arises during the e!ecution o& a program' A C++ e!ception is a response to an e!ceptional circumstance that arises hile a program is running such as an attempt to di*ide by zero' G!ceptions pro*ide a ay to trans&er control &rom one part o& a program to another' C++ e!ception handling is built upon three Ieyords/ tr% catc! and t!row' •
program am thro thros s an e!ce e!cept ptio ion n t!row& A progr hen a problem shos up' %his is done using a t!row Ieyord'
•
progra ram m catc catche hess an e!ce e!cept ptio ion n catc!& A prog ith an e!ception handler at the place in a program here you ant to handle the problem' %he catc! Ieyord indicates the catching o& an e!ception'
•
tr%& A tr% blocI identi&ies a blocI o& code &or hich hich part articul icular ar e!cep !cepttions ions ill ill be
acti acti*a *atted' ed' Et^s t^s &ollo ollo ed by one one or more ore catch blocIs' Assuming a blocI ill raise an e!ception a method catches an e!ception using a combination o& the tr% and catc! Ieyords' A tryKcatch blocI is placed around the code that might generate an e!ception' Code ithin a tryKcatch blocI is re&erred to as protected code and the synta! &or using tryKcatch looIs liIe the &olloing/ try > KK protected code catch< G!ception#ame e = > KK catch blocI catch< G!ception#ame e. = > KK catch blocI catch< G!ception#ame e# = > KK catch blocI
$ou can can list list don don mult multip iple le catc! statements to catch di&&erent type o& e!ceptions in case your tr% blocI raises more than one e!ception in di&&erent situations' %hroing G!ceptions/ G!ceptions can be thron anyhere ithin a code blocI using t!row stat statem emen ents ts'' %he %he operand o& the thro statements determines a type &or the e!ception and can be any e!pression and the type o& the result o& the e!pression determines the type o& e!ception thron' Folloing is an e!ample o& throing an e!ce e!cept ptio ion n hen hen di*i di*idi ding ng by zero zero cond condit itio ion n occurs/ double di*ision i&< b 4 = > thro X1i*ision by zero condition\X return
Catching G!ceptions/ %he catc! blocI &olloing the tr% blocI catches any e!ception' $ou can speci&y hat type o& e!ception you ant to catch and this is determined by the e!ception declaration that appears in parentheses &olloing the Ieyord catch' try > KK protected code catch< G!ception#ame e = > KK code to handle G!ception#ame e!ception Abo*e code ill catch an e!ception o& 'ceptioname type' E& you ant to speci&y that a catch blocI should handle any type o& e!ception that is thron in a try blocI you must put an ellipsis ''' beteen the parentheses enclosing the e!ception declaration as &ollos/ try >
KK protected code catch<'''= > KK code to handle any e!ception %he &olloing is an e!ample hich thros a di*ision by zero e!ception and e catch it in catch blocI' 9include :iostream; using namespace std double di*ision i&< b 4 = > thro X1i*ision by zero condition\X return int ! T4 int y 4
double z 4 try > z di*ision cerr :: msg :: endl return 4 (ecause e are raising an e!ception o& type const c!ar* so hile catching this e!ception e ha*e to use const charW in catch blocI' E& e compile and run abo*e code this ould produce the &olloing &olloing result/ 1i*ision by zero condition\
OPG2A%O2 OVG2LOA1E#B/ Operator o*erloading is a mechanism in C++ hich pro*ides a special meaning to an
operator ' it is one o& the e!citing &eatures o& C++ language' %he input and output operator <:: and ;;= used in C++' For input or display are good e!amples o& o*erloading' %hat is the le&t shi&t <::= and right shi&t <;;= operators hich are used to le&t and right shi&t the bits respecti*ely are o*erloaded to per&orm a di&&erent &unction o& input And output hen used ith cin and cout' #O%G/ thus operator operator o*erloading pro*ides the ability to use the same operator to per&orm di&&erent actions' Operator o*erloading/0 G*ery operator ha*e speial meaning but e can change the &unctionality o& an operator it is called operator o*erloading' He can o*erlaod unary operator as ell as binary operator' Nnary Operator O*erloading/0 class student > Ent roll_numb Ent age
Program o*erloading unary operator ++ using arguments' class student > Ent roll_numb Ent age Public/ "tudent
> 2oll_numbrn Ageag Void operator ++ Age age+ Void main<= main<= > "tudent ram<.44,= 2am++ Betch<= (inary Operator o*erload /0 %o o*erlaod binary operator is called binary operator o*erloading class student > Ent roll_numb Ent age Public/ "tudent
2oll_numbrn Ageag "tudent operator + "tudent temp<44= KKroll_numb and age initialized to 4 %emp'age age+obj'age 2etturn temp Void main<= main<= > "tudent ram<.44,=mohan<.4.4= "tudent ramesh<44= 2ameshram+mohan KK add the age o& ram ram and mohan and asssign the sum to the age o& ramesh Betch<=