Introduction to C++.pptx learn c++ and basic concepts of OOP

UbaidKhan930128 14 views 67 slides May 11, 2024
Slide 1
Slide 1 of 67
Slide 1
1
Slide 2
2
Slide 3
3
Slide 4
4
Slide 5
5
Slide 6
6
Slide 7
7
Slide 8
8
Slide 9
9
Slide 10
10
Slide 11
11
Slide 12
12
Slide 13
13
Slide 14
14
Slide 15
15
Slide 16
16
Slide 17
17
Slide 18
18
Slide 19
19
Slide 20
20
Slide 21
21
Slide 22
22
Slide 23
23
Slide 24
24
Slide 25
25
Slide 26
26
Slide 27
27
Slide 28
28
Slide 29
29
Slide 30
30
Slide 31
31
Slide 32
32
Slide 33
33
Slide 34
34
Slide 35
35
Slide 36
36
Slide 37
37
Slide 38
38
Slide 39
39
Slide 40
40
Slide 41
41
Slide 42
42
Slide 43
43
Slide 44
44
Slide 45
45
Slide 46
46
Slide 47
47
Slide 48
48
Slide 49
49
Slide 50
50
Slide 51
51
Slide 52
52
Slide 53
53
Slide 54
54
Slide 55
55
Slide 56
56
Slide 57
57
Slide 58
58
Slide 59
59
Slide 60
60
Slide 61
61
Slide 62
62
Slide 63
63
Slide 64
64
Slide 65
65
Slide 66
66
Slide 67
67

About This Presentation

Learn c++


Slide Content

C++ Ch a r a cter Set:  T h e v a li d s et o f c h arac t ers th at a C ++ l a ngu a g e can rec ogn i zes in c lu d es th e f ollo w i ng . 13 C + + Introducti o n

T o k ens:   S m a ll e s t indiv id u a l tok e n . uni t i n a pr og ram i s kno w n as 1 . 2 . 3 . 4 . I dent i f i ers Ke y w o r ds Operat o rs P unctu a t o rs / D e li m i ters 14 C + + Introducti o n

Identi f iers is a na m e given to progra mm ing ele m ents such as variables, f unctions, arra y s, objects, classes, etc.,  The f ollowing a r e some v a l i d id e ntifi er s: S tu d e n t R e g101 a1 e 2 r 3 c r e a t i ng identifi e rs: _ d os  R ules to be follow e d while ◼ I den tifi e r s a r e a s e quence of cha r ac t e r s w h i ch shou l d be g i n w it h t he a l phab e t e it her fr om A - Z ( U ppe r c a s e ) or a - z ( l o w e r c a s e ) or ( unde r s c o r e ) . ◼ C ++ t r e a t s uppe r c a se and l o w e r c a se ch ar a c t e r s d i ff e r en tl y ◼ N o S pec i al cha r ac t er i s a l l o w ed except unde r s c o r e “_”. ◼ I den ti f i er shou l d be s i n g l e w o r ds i .e. b l ank sp a c e s c a nnot be i nc l uded i n i den tifi e r . ◼ R e s e r v ed K e y w o r ds shou l d not be used as i den tifi e r s . ◼ I den ti f i e r s shou l d be of r e a son a b l e l en g t h. _ 15 Identifiers

K ey w o rds: are p re d ef in ed w o rd th at giv es sp ec i al m ea nin g t o th e c o m pli er. 16 K e yw o rds

.  C ++ O per a t o r s : ◼ O p e r a tors a r e us e d to p e rf o r m op e r a t i ons on v a r ia b les v a lues. ◼ E x a mple: int x = 100 + 50;  C ++ O per a t o rs T y pe s : a nd ◼ C + + div i d e s the op e r a tors in t o  Arith m etic operators  Assig n m ent operators  Co m parison operators  Logical operators  Bit w ise operators the f ol l owing g roups. 22 C++ Ope r a t o rs

 A r ith m e t ic ope r a t o r s a r e u s e d t o p er f o r m c o mm on m athe m ati c al o p er atio n s . 23 Arithmetic Operat o rs

 Assign m ent operators are u sed to assi g n values to variable s . 24 As s i g nment Ope r a t o rs

 Co m parison operators are u sed to co m pare two value s .  The re turn v a lue of a c omp a r ison is e i t h e r true ( 1) or f a lse ( ) . 25 Relati o n a l Operator

 Log i c al ope r a t o r s a r e u s e d t o d e t er m i n e t h e logic b e t w ee n va r ia b les or val u e s . 26 Lo g ical Op e rat o rs

 A Bit w ise operators progra m m ing. are used in bit level 27 Bitwise Op e rat o rs

28  O p er a t o r s m ay also b e c lass i f ied o p er a nd s they a c t on e it h er : ◼ Unary O p er ato r s ◼ E x a m p l e: a ++ ◼ B i n a r y O p er ato r s ◼ E x a m p l e: x = y – z ; on the n u m b e r of C++ Ope r a t o rs

Sp ec ial O p er a t or :  An expr e ss i on is a co m b i n ation of o p c o d e a n d o p er a nd .  S o m e s p ec ial o p er ato r s u s e d in C++ prog r a mm i n g a re : 29 C++ Ope r a t o rs

 P un c t u a t o r s in C + + have sy n t a c t ic a n d s e m antic m e an i n g to t h e c o m p i l er . 30 Punctu a tors

D a ta T y pe s :   D a ta T y p e s ca n be d e f in e d a s the s e t of v a lu e s, w h ich ca n be stor e d in a v a ri a ble a long with t he op e r a t i ons t h a t ca n be p e r f orm e d on tho s e v a lues.  C++ d e f in e s s e v e r a l t y p e s of d a ta a nd e ac h t y pe h a s c h a r a c te r is t ics.  C++ d a ta t y p e s ca n be c lassi f ied a s: unique 1. 2. 3. Th e f und a m e n tal d ata type ( bu i l t - in D e r ived Da t a type U s er- d e f i n e d d a t a t ype d ata) 31 Data Types

D a ta T y pe s :  C++ d e f in e s s e v e r a l t y p e s of d a ta a nd c h a r a c te r is t ics. e ac h t y pe h a s unique  C + + d a ta t y p e s ca n be c lassifi e d a s: 32 Data Types

I nput & Outp u t Oper a t o rs  The input output op e r a t i ons a r e done using l i b ra r y f un c t i ons c in a nd c o u t obje c ts of the c lass iost re a m .   Using the st a nd a rd input a n d output l i br a r y , we will a ble to inte rac t with t he us e r by p r int i ng m e ss a g e on the s c r ee n a nd g e t t ing the us e r ’ s input f r om the k e y bo a rd. ◼ A st rea m is a n obj ec t wh e r e a p r o g r a m ca n e i t h e r inse r t / e x tr ac t c h a r a c te r s to / f r om i t . ◼ The stand a rd C + + l i br a ry includ e s the h ea d e r file ios t r e a m, w h e r e the stan d a r d input a nd output str ea m obj ec ts a r e d ec la re d. 35 Input & Output Operators

I nput Oper a t o r s :  I nput O p e r a tor “>>” : The stan d a r d input d e vi c e is usually the k e y bo a rd.  I nput in C + + is done by using the the c in s t r ea m. “ str ea m e x tr ac t i on” ( > > ) on  “c in” st a nds for “c onso l e inpu t ” .  E x a mp l e : i n t ag e ; c i n >>ag e ; 36 Input & Output Operators

Output Oper a t o r:  O u tput Op e r a tor “<<” : The stan d a r d output d e vi c e is t he s c r e e n (Monitor ) .  Output t ing in C + + is done by using the obj ec t foll o w e d by “ str ea m inse r t i on” (<< ) .  “c out” st a nds for c onso l e output the  E x a mp l e : c o ut< < ” s u m ” ; // p rin t s s um c o ut< < s u m ; // p rin t s t he c o nt e nt o f t he va ri a ble s u m ; 37 Input & Output Operators

C as c a d i ng o f I/ O Oper a t o r s :   I f a pro g r a m r e qu i r e s more t h a n poss i ble to input these v a ri a bles mu l t i ple str ea m e x tr ac t i on “ >> ” one i n put va r iable then it is in a sin g le c in stat e ment using op e r a tors.  E x a mple: cout < < ” E nter t he t w o n u m ber”; c i n >> a >> b;  I f a pro g r a m r e qu i r e s more t h a n one output r e sult th e n this ca n be done using a sin g le c o u t stat e ment with mu l t i ple str ea m inse r t i on “ << “ op e r a tors.  This is ca l l e d ca s ca ding of input & output op e r a tors.  E x a mp l e : cou t << ” E nt e r e d t he t w o nu m ber” << a << b < < endl; cout < < ” T he sum of t w o n u m ber i s” << sum< < en d l ; 38 Input & Output Operators

I ntr o ducti o n:   Control state m ents are state m ents that alter t h e se q ue n ce of f low of instructions.  The order in which state m ents are executed in a program is called f low of contro l .  T y pes of control state m ents: control state m ents. ◼ Selection state m ents ◼ Iteration state m ents C++ supports two basic 41 Contr o l St a te m ents

Sel e ct io n Sta t e m ent s : This state m ent allows us to select a state m ent or set of state m ents f or execution based on so m e conditi o n. It is also k n own as co n dition a l stat e m ent.   This structure helps the progra m m er decision. The di f f erent selection state m ents: ◼ if sta te m e n t ◼ if – e lse s t a te m e n t ◼ N e st e d – if st at e m e n t ◼ s w it c h sta te m e n t to take appropriate   42 Contr o l St a te m ents

.: 43 i f  st a te m ent: This This This is the si m plest f orm of Selection state m ent. state m ent is also called as on e -way br a nc h ing. state m ent is used to decide whether a s t ate m ent  or  set of state m ents should be executed The decision is based on a condition evaluated to TR U E or FAL S E S y ntax: if (T e st Con d itio n ) / / is tr u e S t a te m e n t 1; S ta t e m e n t 2; or not. which can be   Sele c ti o n S tatem e nts

i f  – e ls e s t a te m ent: This state m ent is also called as tw o -way br a nc h in g . This structure helps to select one executed f rom two sets. set of state m ents to be  S y ntax of if – else if (T e st Con d itio n ) state m ent is:  S t a te m e n t 1; e lse S ta t e m e n t 2; 44 Sele c ti o n S tatem e nts

N e s ted i f st a te m ent :  If the state m ent of an if state m ent is another if state m ent then such an if state m ent is called as Neste d -if State m ent.  The general f orm of if ( T est C o n d i t i o n 1 ) St a t e m ent 1 ; else if ( T est C o n d i t i o n 2 ) St a t e m ent 2 ; else …… … .. else i f ( t est C o n d i t i o n N) St a t e m ent N; else D e fa ult St a t e m en t ; if – else – if state m ent is:. 45 Sele c ti o n S tatem e nts

S w i tch Sta t e m ent :  C + + h a s bui l t in m ul t ip l e - br a n c h s e le c t i on s t a tem e nt  I f t h e re a re m o re t han two al t e rn a t i ves t o s e le c t i on c onstru c t i s us e d. be sele c ted, m u l t i p l e  The g e n e r a l fo r m of S witch stat e ment S w it c h ( E x p re s s i o n ) is: { C a se L ab e l - 1 : S t a te m e n t 1 ; B re a k ; C a se L ab e l - 2 : S t a te m e n t 1 ; B re a k ; ………… . . C a se L a b e l -N: S t a t e m e n t N; B re a k ; D e f a u lt : D e f a u l t - S t a t e m e n t; } 46 Sele c ti o n S tatem e nts

I ter a t iv e C o nst r ucts o r Lo o pin g :   The process of repeated execut i on of a sequence of state m ents until so m e condition is satis f ied is called as iteration or loop.   Iterative sta t e m ents are also ca l led as r ep e titi v e sta t e m ent or looping state m ents.  There are three t y pes ◼ w hile loop ◼ do w hile loop ◼ for loop of looping structures i n C ++: 47 Ite r a ti o n st a te m ents

w hi l e loo p:  This is a pr e -tested loop structure.  This structure checks the condition at the beginning of the structure.  The set of state m ents are executed again the condition is true. and a g ain until  The general f orm of while w hi l e ( T e s t C on d i t i on) structure is { St a t e m ent St a t e m ent …… . . St a t e m ent 1 2 N } // E nd o f Whi l e 48 Ite r a ti o n st a te m ents

d o - w hi l e loo p:  This is a pos t - test e d loop s tru c tur e .  This stru c ture c h ec ks the c ondi t ion a t t he e nd of the stru c tur e .  The s e t of st a tem e nts a r e e x ec ut e d a g a in c ondi t ion is t ru e . a nd a g a in until the  The g e n e r a l fo r m do of while stru c ture is { Sta t e m ent Sta t e m ent …….. Sta t e m ent 1 2 N } // w h i l e ( T e s t C ondi t i on); 49 Ite r a ti o n st a te m ents

f o r loo p:  This structure is the f ixed execut i on structure.  Usually used wh e n we know in ad v an c e ex a ctly how m any ti m es a set of state m ents to be executed repeatedl y .  This structure can be used as incre m ent looping decre m ent looping structure. or  The general f orm of f or structure is as f ollows: f or ( E x pre s s i on 1; E x pre s s i on 2; E x pre s s i on 3) { Sta t e m ent Sta t e m ent Sta t e m ent 1; 2; N; } 50 Ite r a ti o n st a te m ents

I ntr o duct io n:  An a r r a y is c ol l ec t i on of e lem e nts wh e re a ll the e lem e nts a r e s a me d a ta t y pe und e r the s a me n a m e .  The e lem e nts a r e numbe re d a s 0, 1, 2…. n - 1.  Th e se numb e r s ca l l e d a s indic e s or subs c r ipt s .  Th e se numb e r s a r e us e d to loc a te the posit i ons of e lem e nts with i n the a r r a y .  I f a is the name of acce ssed a s a[0 ] , a[1 ] , the a r r a y , t h e e lements c a n be dir e c t l y a[2 ] ,……, a[ n - 1]. 56 Arra y s

.  Why need to use array type?  Consider the following issue: "We have a list of 1000 students' marks of an integer type. If using the basic data type ( int ), we will declare something like the following…" int studMark0, studMark1, ...studMark999

#include< iostream > using namespace std ; int main() { int i,sum =0,a[5]; cout <<"enter Numbers "; for( i =0;i<5;i++) { cin >>a[ i ]; } for( i =0;i<5;i++) { sum= sum+a [ i ]; } cout <<" Sum= "<<sum; return 0; }

#include< iostream > using namespace std ; int main() { int i,a [5],max, min; cout <<"enter value "; for( i =0;i<5;i++) { cin >>a[ i ]; } max=a[0]; min=a[0]; for( i =1;i<5;i++) { if(max<a[ i ]) max=a[ i ]; if(min>a[ i ]) min=a[ i ]; } cout <<" max="<<max<< endl ; cout << " min ="<<min<< endl ; return 0; }

I ntr o duct io n:  A f un c t i on is a n a med g roup of st a tem e nts d e v e loped to solve a sub - p r obl e m a nd r e turns a v a lue to oth e r f un c t i ons w h e n it is ca l l e d.  Ty p e s of f un c t io n s: ◼ Library functi o ns A s t a n d a rd li b r a ry is a c o llec t i o n o f pr e - de f ined f u n c t i o ns a nd o t her pr og r a mm ing ele m en t s , w hich a re a c c es s ed t hr o u g h he a der f iles ◼ User-defin e d functio n s  We c a n c r e a t e o ur o w n f u n c t i o ns o r s u b - pr og r a m s t o s o l v e o ur pr o b l e m . S u ch f u n c t i o ns a re no r m a lly re f er r ed t o a s u s e r - de f ined f u n c t i o ns  58 Functi o ns

U s e r- def i ned funct io n s : Us e r- d e fin e d fun c t i on is a fun c t i on d e fin e d by the us e r to solve his / h e r p r obl e m . The purp o se of using a fun c t i on is to make the p r o g r a m d e si g n p r o ce ss ea s y , und e r stan d a ble a nd th er e by a voiding a mbi g uit y . T y p e s of f un c tio n s:    ◼ F un c tion ◼ F un c t ion ◼ F un c tion ◼ F un c tion w ith w ith w ith w ith n o a r g u m e n ts a n d n o re tu r n val u e s. a r gu m e n t s and w ith n o re t u r n val u e s. n o a r g u m e n ts a n d w ith re tu r n val u e s. a r g u m e n ts a n d w ith re tu r n val u e s. ◼ R e c u r sive f un c t io n . 59 Functi o ns

Function with no argument and no return #include< iostream > using namespace std ; void sum(); int main() { sum(); return 0; } void sum() { int a,b ; cout <<" enter a and b :- "; cin >>a>>b; cout <<" Sum="<< a+b ; }

Function with argument and no return #include< iostream > using namespace std ; void sum( int , int ); int main() { int a,b ; cout <<" enter a and b :- "; cin >>a>>b; sum( a,b ); return 0; } void sum( int a, int b) { cout <<" Sum="<< a+b ; }

Function with no argument and return #include< iostream > using namespace std ; int sum(); int main() { int x; x=sum(); cout <<" Sum="<<x; return 0; } int sum() { int a,b ; cout <<" enter a and b :- "; cin >>a>>b; return( a+b ); }

Function with argument and return #include< iostream > using namespace std ; int sum( int , int ); int main() { int x,a,b ; cout <<" enter a and b :- "; cin >>a>>b; x=sum( a,b ); cout <<" Sum="<<x; return 0; } int sum( int a, int b) { return( a+b ); }

 Objects are basic bu i lding blocks f or designi n g progra m s.  An object is a collection of data m e m bers and associa t ed m e m ber f unctions.  An object m ay represent a per s on, place or a tab l e of data.  Each object is iden t i f ied by a unique na m e. Each object m ust be a  m e m ber of a particular class. 62 Objects

 A class is a collec t ion of objects t hat have ident i cal properties, co m m on behavior and shared relations h ip.  A class binds the data and its related f unctions together.  A class is a use r -de f ined data t y pe that we progra m . can use in a  To create a class, use the  Exa m ple: cl a s s M y C lass { // T h e class b od y }; class ke y word. ◼ W h e r e cl a ss k e y w o r d is us ed to c r eate a class c alled M y C la s s 63 Class

D ef i nit i o n a nd D ec la r a t i o n o f C lass es  A c lass d e f ini t ion is a p r o ce ss of n a ming a c lass a nd d a ta v a ri a bles, a nd in t e r f ac e op e r a t i on of the c lass.  The v a r ia b les d ec la r e d ins i de a c lass a r e kno w n a s d a ta memb e rs.  The fun c t i ons d e c la re d ins i de a c lass a re known a s memb e r f un c t i ons.   A c lass d ec la ra t i on sp e c ifi e s the re pr e s e ntation of o b je c ts of the c lass a nd s e t of op e r a t i ons th a t ca n be a pplied to su c h obje c ts. 64 Class in C++

D ef i nit i o n a nd D ec la r a t i o n o f C lass es  C l a ss body is e n c losed in a p a ir of b rac k e ts. C l a ss body c ontains t he d ec la ra t i on of i t s memb e rs ( d a ta a nd f u n c t i ons).  The f un c t i ons d e c la r e d ins i de a c lass a r e kno w n fun c t i ons. a s m e mb e r  The g e n e r a l s y ntax of the c lass d ec la ra t i on c lass U s e r _ D e f in e d_ Na me { priv a te : D a ta M e mb e r ; M e mber fun c t i ons; }; is: 65 Cla s s in C++

A cce s s Specif i ers A c ce ss sp ec ifi e r s d e f ine how the m e mb e r s ( a t t r ibutes a nd fun c t i on) o f a c lass ca n be acce ssed.  Ev e r y d a ta m e mb e r of a c lass is sp ec ifi e d by thr e e le v e ls acce ss prot ec t i on f o r hid i ng d a ta a nd f u n c t i on memb e rs inte r n a l t o the c lass. of  Th e y h e lp in co n troll i ng the acce ss Dif f e r e nt acce ss sp e c ifi e rs a r e : ◼ p r ivate ◼ pub l i c ◼ p r ot e c t e d of the d a ta m e mb e r s.   66 Ac c ess S p e c ifiers

pri va te :  p r iv a te a cce ss m e a ns a m e mb e r d a ta c a n only be acce ss e d by the c lass memb e r f un c t i on or f r iend fun c t i on.  The d a ta m e mb e r s or m e mb e r f un c t i ons d e c la r e d p r iv a te ca nnot be a cce ssed f r om ou t side the c lass.  The obje c ts of the c lass ca n acce ss the p r ivate memb e rs thro u g h the public m e mb e r f un c t i ons of the c lass.  B y d e f a ult d a ta m e mbe r s in a c lass a re priv a te.  E x a mp l e : p r ivat e : i n t x; f loat y; only 67 Ac c ess S p e c ifiers

pr o tec t e d :   The m e mb e r s whi c h a r e d ec la r e d using p r ot e c ted ca n be acce ssed only by the m e mber fun c t i ons, f r iend of the c lass a lso t he m e mb e r f un c t i ons d e r iv e d f r om this c lass.  The memb e rs c a nnot be acce ssed f r om outs i de the c lass. a nd  The prot ec ted acce ss sp ec ifi e r s.  E x a mp l e : p r ot e c t e d : i n t x; f loat y; sp e c ifi e r is si m i l a r to private acce ss 68 Ac c ess S p e c ifiers

public :  public acce ss m e a ns th a t m e mb e r ca n be acce ss e d a ny f un c t i on ins i de or o u ts i de the c lass.  S ome of the public f un c t i ons of a c lass p r ovide inte r f ac e f or acce ss i ng the p r ivate a nd p r ote c ted m e mbe r s  E x a mp l e : c l a s s MyC l a s s { pub l i c: / / Pub l i c ac c e s s s pec i f i er of the c lass. i nt x; pr i va t e: i nt y; } ; / / P u b li c a tt r i bute / / Pr i va t e acc e ss spe c i f i er / / Pr i va t e a t t r i bu t e 69 Ac c ess S p e c ifiers

M e m ber Func t i o n :  Me m b er f u n c ti o n s are f un c tio n s th at are in c lud e d w ithi n a cla s s (Me m b er fu n c ti o n s are a ls o ca ll ed Me t hod s ).  Me m b er f u n c ti o n s can b e d ef in ed ◼ I n si de c las s def i n i t io n ◼ Outs i de c las s def i nit i o n i n t w o pl ace s . 70 Me m ber F u ncti o n

I ns i de c las s def i nit i o n:  T o de fi ne m e m ber f unc ti on i ns i de a c l a s s t he f unc ti on de c l a r a ti on w it h i n t he c l a s s i s r ep l ac e d by ac t ual f unc ti on de fi n iti on i ns i de c l a s s. t he  O n l y s m a l l f unc ti ons a r e  E x a m p l e: c l a ss r ec t a n g le { de fi ned i ns i de c l a s s de fi n iti o n . vo id c o m pu t e ( ) { a r e a = le n g th * b r e a d t h ; } vo id d is p l a y ( ) { i n t l e n g t h , b r e a d t h , pub l i c : vo id g e t _ d a t a ( ) { a r e a ; c ou t < < ” E n t e r t h e va l u e s f o r L e n g th an d B r e a d t h ” ; c i n >> le n g t h >> b r e ad t h ; } c ou t << ” T h e a r e a o f r ec t a n g le is ” << a r e a ; } }; 71 Me m ber F u ncti o n

Outs i de c las s def i nit i o n:  To d e f ine m e mb e r f un c t i on outs i de the c lass, the c lass n a me must be l i nk e d with t he n a me of memb e r f un c t i on.  S c ope re solu t ion op e r a tor ( : : ) is used to d e f ine the m e mb e r fun c t i on out s ide the c lass.  S y ntax of a memb e r f un c t i on d e fin e d outs i de the c lass i s : r et urn _t y pe cl a ss _ n a m e : : m e m be r_f unc t i o n _ n a m e ( a r g 1 , ... , a r g nN) { f u n c t i o n b o d y ; } 72 Me m ber F u ncti o n

P r og r a m to u s e m e m ber c las s def i n i t io n: # incl u de<i o s t r e a m .h > cl a s s i t em { pri va t e: i n t nu m ber s ; f l oa t c o s t ; p u b l ic: functi o ns i ns i de a nd o uts i de }; vo id i t em : : g e t d at a ( int a , f l oa t b) { n u m ber = a ; c o s t = b; } vo id g e t d at a ( int a , vo id p u t da t a ( ) { c o ut< < ” Nu m ber: f l oa t b); int m a in( ) { i t em x ; x . g e t da ta ( 250 , 10 . 5 ) ; x . p u t d at a ( ) ; r e t urn ; } “ << n u m ber< < endl; c o ut< < ” C o s t: ” << c o s t << endl; } 73 Me m ber F u ncti o n

Object o f a c las s :  An obj ec t i s a rea l w or ld e lem e nt whi c h is id e ntifi a ble e nti t y with s ome c h a r a c te r is t ics (a t t ribut e s) a nd b e h a vior ( fun c t i ons).  An obj ec t i s a n instan c e of a c lass.  An obj ec t i s norm a l l y d e fin e d in the m a in ( ) fun c t i on.  The s y ntax for d e fining obje c ts of a c lass a s follows: class Cl a ss _ N a m e { p r i v at e : //M e m b e r s pub l i c : //M e m b e r s }; cl a s s Cl a ss _ N a m e O bj e c t_ n a m e 1 , O bj e c t_ n a m e 2 , ……; ◼ w h e r e c lass k e y w or d is optional. 74 Defini n g o b ject of a class

D o t oper a t o r (. ) :  The public d a ta m e mb e r s of obj ec ts of a c lass c a n be acce ss e d using dir ec t m e mber acce ss op e r a tor (. ) .  P r iv a te a nd p r ot e c ted m e mb e r s of the c lass c a n be acce ss e d only throu g h the memb e r fun c t i ons of the c lass.  No f un c t i ons ou t side a c lass ca n include stat e ments to a c ce ss d a ta d ir e c t l y .  The s y ntax of a cce ss i ng memb e r ( d a ta a nd f u n c t i ons) of a c lass is: a) S y n tax f o r a c c e ss i n g a d ata m e m b er o f t h e clas s : O bje ct _ N a m e . da ta_ m e m ber; b ) S y n tax f o r a c c e ss i n g a m e m b er f un cti o n o f t h e clas s : O bj e c t_ N a m e . m e m ber _ f u n c t i o n( a r g u m e nts ) ; 75 Acc e ssing m e m b er o f t h e class
Tags