SlideShare a Scribd company logo
Introduction ooff PPrrooggrraammmmiinngg 
LLeeccttuurree 2277
TTooddaayy’’ss LLeeccttuurree 
– CCllaasssseess aanndd 
oobbjjeeccttss 
– CCoonnssttrruuccttoorrss 
– DDeessttrruuccttoorrss 
– MMeemmbbeerr ffuunnccttiioonnss 
– MMeemmbbeerr ddaattaa
FFuunnccttiioonn 
OOrriieenntteedd
OObbjjeecctt OOrriieenntteedd
MMuullttiippllee 
MMeeddiiaa
CCllaasssseess 
OObbjjeeccttss 
CCoonnssttrruuccttoorrss
DDaattaa HHiiddiinngg 
Encapsulation
CCoonnssttrruuccttoorr
BBuuggss
The majority ooff pprrooggrraammmmiinngg 
pprroobblleemmss ooccccuurr bbeeccaauussee ooff tthhee 
uussee ooff uunn--iinniittiiaalliizzeedd ddaattaa..
CCoonnssttrruuccttoorr 
 NNaammee ooff tthhee ccoonnssttrruuccttoorr iiss 
ssaammee 
aass tthhee nnaammee ooff tthhee ccllaassss 
 IItt ddooeess nnoott rreettuurrnn aannyy tthhiinngg,, nnoott 
eevveenn vvooiidd
EExxaammppllee 
ccllaassss DDaattee 
{{ 
iinntt mmoonntthh ;; 
iinntt ddaayy ;; 
iinntt yyeeaarr ;; 
ppuubblliicc:: 
DDaattee (( iinntt ddaayy == 11 ,, iinntt mmoonntthh == 11 ,, iinntt yyeeaarr == 11 )) 
}} ;;
FFuunnccttiioonn 
OOvveerrllooaaddiinngg
RRuulleess ooff ffuunnccttiioonn 
oovveerrllooaaddiinngg 
WWhheenn eevveerr wwee oovveerrllooaadd aa ffuunnccttiioonn,, 
tthhee nnaammee ooff tthhee ffuunnccttiioonn rreemmaaiinn tthhee 
ssaammee bbuutt aarrgguummeenntt lliisstt cchhaannggeess.. 
TThhee aarrgguummeenntt lliisstt ccaann:: 
– EEiitthheerr vvaarryy iinn tthhee nnuummbbeerr ooff 
aarrgguummeennttss 
– OOrr vvaarryy iinn tthhee ttyyppee
ccllaassss DDaattee 
{{ 
ppuubblliicc :: 
DDaattee (( iinntt mmoonntthh == 11 ,, iinntt ddaayy == 11 ,, iinntt yyeeaarr == 11 )) ;; 
pprriivvaattee :: 
iinntt mmoonntthh ,, ddaayy ,, yyeeaarr ;; 
}} ;; 
EExxaammppllee
EExxaammppllee 
mmaaiinn (( )) 
{{ 
DDaattee mmyyddaattee (( )) ;; 
}}
EExxaammppllee 
mmaaiinn (( )) 
{{ 
DDaattee mmyyddaattee (( ““0011--JJaann--22000022”” )) ;; 
}}
Memory AAllllooccaattiioonn IInnssiiddee 
aa CCoonnssttrruuccttoorr
UUttiilliittyy 
FFuunnccttiioonnss
FFrriieenndd 
FFuunnccttiioonnss
DDeessttrruuccttoorr
~~
RRuulleess ooff 
DDeessttrruuccttoorr 
11.. DDeessttrruuccttoorrss ccaannnnoott bbee 
oovveerrllooaaddeedd 
22.. DDeessttrruuccttoorrss ttaakkee nnoo aarrgguummeennttss 
33.. TThheeyy ddoonn’’tt rreettuurrnn aa vvaalluuee
ccllaassss DDaattee 
{{ 
ppuubblliicc :: 
DDaattee (( )) ;; 
DDaattee (( iinntt mmoonntthh ,, iinntt ddaayy ,, iinntt yyeeaarr )) ;; 
~~DDaattee (( )) ;; 
sseettMMoonntthh (( iinntt mmoonntthh )) ;; 
sseettDDaayy (( iinntt ddaayy )) ;; 
sseettYYeeaarr (( iinntt yyeeaarr )) ;; 
iinntt ggeettDDaayy (( )) ;; 
iinntt ggeettMMoonntthh (( )) ;; 
iinntt ggeettYYeeaarr (( )) ;; 
sseettDDaattee ((iinntt ddaayy,, iinntt mmoonntthh,, iinntt yyeeaarr )) ;; 
pprriivvaattee:: 
iinntt mmoonntthh ,, ddaayy ,, yyeeaarr ;; 
}} ;; 
EExxaammppllee 11
EExxaammppllee 11 
mmaaiinn (( )) 
{{ 
DDaattee mmyyddaattee (( 3355 ,, 1133 ,, 22000000 )) }}
EExxaammppllee 11 
mmaaiinn (( )) 
{{ 
DDaattee mmyyddaattee ;; 
mmyyddaattee..sseettDDaattee (( 2211 ,, 0011 ,, 11997799 )) }}
EExxaammppllee 11 
mmaaiinn (( )) 
{{ 
DDaattee mmyyddaattee (( 2211 ,, 0011 ,, 11997799 )) }}
WWhhaatt HHaappppeennss iinn 
MMeemmoorryy 
setMonth ( int month ) ; 
setDay ( int day ) ; 
setYear ( int year ) ; 
int getMonth ( ) ; 
int getDay ( ) ; 
int getYear ( ) ; 
Functions 
int month ; 
int day ; 
int year ; 
int month ; 
int day ; 
int year ; 
int month ; 
int day ; 
int year ;
EExxaammppllee 22 
mmaaiinn (( )) 
{{ 
DDaattee ddaattee11 ,, ddaattee22 ,, ddaattee33 ;; 
ddaattee11..sseettMMoonntthh (( 33 )) ;; 
ddaattee22..sseettDDaayy (( 2233 )) ;; 
}}
DDeessttrruuccttoorr 
ss ~className ( ) ;
DDeessttrruuccttoorrss 
~~DDaattee :::: DDaattee (( )) 
{{ 
ccoouutt<<<< ““OObbjjeecctt DDeessttrrooyyeedd”” ;; 
}}
CCoonnssttrruuccttoorrss 
DDaattee :::: DDaattee (( )) 
{{ 
ccoouutt <<<< ““DDaattee OObbjjeecctt CCrreeaatteedd”” ;; 
}}
CCoonnssttrruuccttoorrss 
wwiitthhoouutt AArrgguummeennttss 
DDaattee :::: DDaattee (( )) 
{{ 
ccoouutt<<<< ““DDeeffaauulltt ccoonnssttrruuccttoorr 
wwiitthhoouutt aarrgguummeennttss ccaalllleedd ”” ;; 
}}
CCoonnssttrruuccttoorrss wwiitthh 
AArrgguummeennttss 
DDaattee :::: DDaattee (( iinntt mmoonntthh ,, iinntt ddaayy ,, iinntt yyeeaarr )) 
{{ 
ccoouutt<<<< ““AA ccoonnssttrruuccttoorr wwiitthh ppaarraammeerrtteerrss ”” ;; 
}}

More Related Content

PPT
CS201- Introduction to Programming- Lecture 30
PPT
Potential and kinetic energy
PPT
CS201- Introduction to Programming- Lecture 03
PPT
Agenesia cuerpo calloso
DOCX
ADEWOYE OMONIYI ADEYEMI PR
PPT
pengenalan perangkat keras komputer
PPT
Perangkat keras komputer
PPT
Perangkat Keras Hardware
CS201- Introduction to Programming- Lecture 30
Potential and kinetic energy
CS201- Introduction to Programming- Lecture 03
Agenesia cuerpo calloso
ADEWOYE OMONIYI ADEYEMI PR
pengenalan perangkat keras komputer
Perangkat keras komputer
Perangkat Keras Hardware

What's hot (18)

PPT
Hardware
PPT
Microwave Spectroscopy
PDF
Contrats speciaux du commerce maritime
PPT
Le Black's Law Dictionary, monument de la lexicographie juridique - ATA 2010
PPT
Hong kong oct. 2014
PPT
PPT
A igreja, corpo de cristo
PPT
Microsoft excel tutorial06
PPT
Admission in india 2015
PPT
Gelombang
PPT
Kondisi kecamatan 2
PPT
The solar system
PPT
CS201- Introduction to Programming- Lecture 25
PDF
Cv9 4-2016
PPT
Achisitii recente 2014
PPT
Ciivic education 1
PPT
Replace your lawn sprinkler controller
PPT
Resumen de el dinero es deuda
Hardware
Microwave Spectroscopy
Contrats speciaux du commerce maritime
Le Black's Law Dictionary, monument de la lexicographie juridique - ATA 2010
Hong kong oct. 2014
A igreja, corpo de cristo
Microsoft excel tutorial06
Admission in india 2015
Gelombang
Kondisi kecamatan 2
The solar system
CS201- Introduction to Programming- Lecture 25
Cv9 4-2016
Achisitii recente 2014
Ciivic education 1
Replace your lawn sprinkler controller
Resumen de el dinero es deuda
Ad

Viewers also liked (20)

PPS
CS101- Introduction to Computing- Lecture 38
PPS
CS101- Introduction to Computing- Lecture 29
PPS
CS101- Introduction to Computing- Lecture 32
PPT
CS201- Introduction to Programming- Lecture 32
PPT
CS201- Introduction to Programming- Lecture 10
PPS
ENG101- English Comprehension- Lecture 40
PPS
ENG101- English Comprehension- Lecture 28
PPS
CS101- Introduction to Computing- Lecture 39
PPS
CS101- Introduction to Computing- Lecture 31
PPS
CS101- Introduction to Computing- Lecture 35
PPS
ENG101- English Comprehension- Lecture 45
PPS
ENG101- English Comprehension- Lecture 35
PPT
CS201- Introduction to Programming- Lecture 06
PPT
CS201- Introduction to Programming- Lecture 22
PPT
CS201- Introduction to Programming- Lecture 35
DOC
MTH101 - Calculus and Analytical Geometry- Lecture 44
PPT
MGT101 - Financial Accounting- Lecture 27
DOC
MTH101 - Calculus and Analytical Geometry- Lecture 41
PPT
CS201- Introduction to Programming- Lecture 31
PPS
CS101- Introduction to Computing- Lecture 43
CS101- Introduction to Computing- Lecture 38
CS101- Introduction to Computing- Lecture 29
CS101- Introduction to Computing- Lecture 32
CS201- Introduction to Programming- Lecture 32
CS201- Introduction to Programming- Lecture 10
ENG101- English Comprehension- Lecture 40
ENG101- English Comprehension- Lecture 28
CS101- Introduction to Computing- Lecture 39
CS101- Introduction to Computing- Lecture 31
CS101- Introduction to Computing- Lecture 35
ENG101- English Comprehension- Lecture 45
ENG101- English Comprehension- Lecture 35
CS201- Introduction to Programming- Lecture 06
CS201- Introduction to Programming- Lecture 22
CS201- Introduction to Programming- Lecture 35
MTH101 - Calculus and Analytical Geometry- Lecture 44
MGT101 - Financial Accounting- Lecture 27
MTH101 - Calculus and Analytical Geometry- Lecture 41
CS201- Introduction to Programming- Lecture 31
CS101- Introduction to Computing- Lecture 43
Ad

Similar to CS201- Introduction to Programming- Lecture 27 (20)

PPT
In introduction to Key Performance Indicators
PPT
Dielectrics lect28
PPT
Government resources
PPT
Bioinformatics
PPT
CS201- Introduction to Programming- Lecture 38
PPT
Industrialisasi Media
PPT
CS201- Introduction to Programming- Lecture 29
PPT
CS201- Introduction to Programming- Lecture 07
PPT
Osteo osteomalacia ricket2
PPT
CS201- Introduction to Programming- Lecture 40
PPT
CS201- Introduction to Programming- Lecture 26
PPT
Building types lecture
PPT
World com scandal
PPT
Penetration testing: A proactive approach to secure computing - Eric Vanderbu...
PPT
CS201- Introduction to Programming- Lecture 09
PPT
CS201- Introduction to Programming- Lecture 21
PDF
Rpam - resum
PPT
The anatomy of a dollar bill
PPT
2011planningforcollege 111129150759-phpapp01
PPT
cardiac arrhythmias
In introduction to Key Performance Indicators
Dielectrics lect28
Government resources
Bioinformatics
CS201- Introduction to Programming- Lecture 38
Industrialisasi Media
CS201- Introduction to Programming- Lecture 29
CS201- Introduction to Programming- Lecture 07
Osteo osteomalacia ricket2
CS201- Introduction to Programming- Lecture 40
CS201- Introduction to Programming- Lecture 26
Building types lecture
World com scandal
Penetration testing: A proactive approach to secure computing - Eric Vanderbu...
CS201- Introduction to Programming- Lecture 09
CS201- Introduction to Programming- Lecture 21
Rpam - resum
The anatomy of a dollar bill
2011planningforcollege 111129150759-phpapp01
cardiac arrhythmias

More from Bilal Ahmed (19)

PPT
CS201- Introduction to Programming- Lecture 45
PPT
CS201- Introduction to Programming- Lecture 44
PPT
CS201- Introduction to Programming- Lecture 43
PPT
CS201- Introduction to Programming- Lecture 42
PPT
CS201- Introduction to Programming- Lecture 41
PPT
CS201- Introduction to Programming- Lecture 39
PPT
CS201- Introduction to Programming- Lecture 37
PPT
CS201- Introduction to Programming- Lecture 36
PPT
CS201- Introduction to Programming- Lecture 34
PPT
CS201- Introduction to Programming- Lecture 33
PPT
CS201- Introduction to Programming- Lecture 28
PPT
CS201- Introduction to Programming- Lecture 24
PPT
CS201- Introduction to Programming- Lecture 23
PPT
CS201- Introduction to Programming- Lecture 20
PPT
CS201- Introduction to Programming- Lecture 19
PPT
CS201- Introduction to Programming- Lecture 18
PPT
CS201- Introduction to Programming- Lecture 17
PPT
CS201- Introduction to Programming- Lecture 16
PPT
CS201- Introduction to Programming- Lecture 15
CS201- Introduction to Programming- Lecture 45
CS201- Introduction to Programming- Lecture 44
CS201- Introduction to Programming- Lecture 43
CS201- Introduction to Programming- Lecture 42
CS201- Introduction to Programming- Lecture 41
CS201- Introduction to Programming- Lecture 39
CS201- Introduction to Programming- Lecture 37
CS201- Introduction to Programming- Lecture 36
CS201- Introduction to Programming- Lecture 34
CS201- Introduction to Programming- Lecture 33
CS201- Introduction to Programming- Lecture 28
CS201- Introduction to Programming- Lecture 24
CS201- Introduction to Programming- Lecture 23
CS201- Introduction to Programming- Lecture 20
CS201- Introduction to Programming- Lecture 19
CS201- Introduction to Programming- Lecture 18
CS201- Introduction to Programming- Lecture 17
CS201- Introduction to Programming- Lecture 16
CS201- Introduction to Programming- Lecture 15

CS201- Introduction to Programming- Lecture 27