Documents

C++ Notes

Description
C++ NotesC++ NotesC++ NotesC++ Notes
Categories
Published
of 16
All materials on our website are shared by users. If you have any questions about copyright issues, please report us to resolve them. We are always happy to assist you.
Related Documents
Share
Transcript
  THE ORIGIN OF C++ In 1979, a young engineer at Bell (now AT&T) Labs, Bjarne Stroustrup, started toeperi!ent wit etensions to # to !a$e it a better tool %or i!ple!enting larges'ale proje'ts In t ose days, an aerage proje't 'onsisted o% tens o% t ousands o% lines o% 'ode(L*#) In 19+, seeral !odi%i'ations and etensions ad already been !ade to # wit 'lassesIn t at year, t e na!e -#..- was 'oined /er sin'e t en, t e .. su%%i as be'o!e asynony! %or obje'torientation (Bjarne Stroustrup 'ould ae !ade a %ortune only byregistering .. as a trade!ar$) It was also in t at year t at #.. was %irst used outsideAT&T Labs T e nu!ber o% users was doubling eery %ew !ont s  and so was t enu!ber o% 'o!pilers and etensions to t e languageBetween 19+0 and 19+9, #.. underwent a !ajor re%or! rote'ted !e!bers, prote'tedin eritan'e, te!plates, and a so!ew at 'ontroersial %eature 'alled !ultiple in eritan'ewere added to t e language It was 'lear t at #.. needed to be'o!e standardi2ed OBJECT-ORIENTED PROGRAMMINGBASIC INPUT/OUTPUT FUNCTIONS CIN>>:  It is used %or input li$e s'an%( ) in #3443 T is is 'alled insertors COUT>>:  It is used %or output li$e print%( ) in #3443 T is is 'alled eertors KEYWORDSCLASS A #lass is way to bind t e data and its asso'iated %un'tions toget er It allows t e dataand %un'tions to be idden, i% ne'essary, %ro! eternal use 5 en de%ining a 'lass, we are'reating a new abstra't data type t at 'an be treated li$e any ot er builtin data type T e  'lass de'laration des'ribes t e type and s'ope o% its !e!bers T e general %or! o% de'laration is as %ollows6 Synt!:C ## $ ##%n&'(P)*t':)*, ' '$ )t*.n#01n$t*.n '$ )t*.n#21, *$:)*, ' '$ )t*.n01n$t*.n '$ )t*.n3 T e 'lass de'laration is si!ilar to stru't de'laration T e body o% a 'lassis en'losedwit in bra'es and ter!inated by a se!i'olon T e 'lass body 'ontains t e de'laration o% ariables and %un'tions T ese %un'tions and ariables are 'olle'tiely $nown as 'lass!e!bers ASSESSORS PRI4ATE:  T e #lass !e!bers t at ae been de'lared as priate 'an be a''essed only wit in t e 'lass PUBLIC:  T e #lass !e!bers t at ae been de'lared as publi' 'an be a''essed outside t e 'lass also PROTECTED : li$e priate e'ept t at deried 'lasses ae a''ess to t e! too Try not to use t is  it 'an elp per%or!an'e but it brea$s en'apsulation E!&2 ':5*n$ 1'6*.#t)'&78>C ## *t'&( *nt n1&,') // 2)*t' ,y '01 t0 .t $.#t21, *$:.* 9'tt *nt ; 0 .t ,<.* 21tt.*<($.1t66=n1&,'):=66n1&,')66=n=$.1t66=$.#t:=66$.#t66=n=33  .* *t'&::9'tt*nt ; 0 .t ,<(n1&,') ?$.#t?,3*nt &*n <(*t'& !$.1t 66=n O,@'$t !=66=n=!79'tt; 7<!721tt <*t'& y$.1t66=n O,@'$t y=66=n=y79'tt;7<y721tt <)'t1)n 3 OBJECT *bje'ts are t e basi' run ti!e entity in an obje'toriented syste! T ey !ay represent a person, a pla'e, a ban$ a''ount or any t at t e progra! as to andle T ey !ay alsorepresent user de%ined data su' as e'tors, ti!e, and lists 5 en a progra! is ee'uted, t e obje't intera'ted by sending !essages to one anot er E!&2 ':C ## '&2(C8) n&'0 .t 9'21, *$:.* 9'tt.*<($.1t66=ENTER NAME:=$*n>>n&'$.1t66=ENTER AGE:=$*n>>9'3.* 21tt .*<($.1t66=NAME:=66n&'$.1t66=AGE:=669'33*nt &*n <('&2 ''79'tt <  '721tt <)'t1)n 3 CONSTRUCTORS A 'onstru'tor is used to initiali2e an obje't A de%ault 'onstru'tor is one t at 'an beino$ed wit out any argu!ents I% t ere is no userde'lared 'onstru'tor %or a 'lass, and i% t e 'lass does not 'ontain const  or re%eren'e data !e!bers, t e i!ple!entationi!pli'itly de'lares a de%ault 'onstru'tor %or it 5*n$ 1'6*.#t)'&78>C ## *nt'9')(*nt &;nP1, *$:*nt'9')*nt; *nt< //$.n#t)1$t.) '$ )'4.* *#2 y <($.1t66=&?=66&66=n=$.1t66=n?=66n66=n=33*nt'9')::*nt'9')*nt !; *nt y< //$.n#t)1$t.) '0*n'(&?!n?y3Int &*n <(*nt'9') *nt;<*nt'9') *nt?*nt'9');<$.1t66=n OBJECT=66=n=*nt7*#2 y <$.1t66=n OBJECT=66=n=*nt7*#2 y <)'t1)n 3 T e progra!!er did not de'lare a 'onstru'tor in 'lass C   an i!pli'it de%ault 'onstru'tor was de'lared and de%ined by t e i!ple!entation in order to 'reate an instan'e o% 'lass C.  
We Need Your Support
Thank you for visiting our website and your interest in our free products and services. We are nonprofit website to share and download documents. To the running of this website, we need your help to support us.

Thanks to everyone for your continued support.

No, Thanks