SlideShare a Scribd company logo
1 of 34
Introduction ttoo PPrrooggrraammmmiinngg 
LLeeccttuurree 3344
IInn TTooddaayy’’ss LLeeccttuurree 
 AArrrraayyss ooff oobbjjeeccttss 
 IInntteerraaccttiioonn ooff AArrrraayyss wwiitthh FFrreeee 
SSttoorree 
 nneeww aanndd ddeelleettee ooppeerraattoorrss 
OOvveerrllooaaddiinngg ooff AArrrraayyss 
OOppeerraattoorr
AArrrraayyss ooff OObbjjeecctt
Date mmyyddaattee [[ 1100 ]] ;;
int intArray [ 10 ] = { 1 ,, 22 ,, 33 ,, 44 ,, 55 66 ,, 77 ,, 88 ,, 99 ,, 1100 
}} ;;
DDaattee mmyyddaattee [[ 1100 ]] == {{ 
DDaattee (( 2211 ,, 0011 ,, 11997799 )) DDaattee (( 2211 ,, 0022 ,, 11997799 )) DDaattee (( 2211 ,, 0033 ,, 11997799 )) DDaattee (( 2211 ,, 0044 ,, 11997799 )) DDaattee (( 2211 ,, 0055 ,, 11997799 )) DDaattee (( 0022 ,, 0066 ,, 11997799 )) DDaattee (( 0022 ,, 0077 ,, 11997799 ,, 
DDaattee (( 0022 ,, 0088 ,, 11997799 )) DDaattee (( 0022 ,, 0099 ,, 11997799 )) DDaattee (( 0022 ,, 1100 ,, 11997799 )) 
}};;
EExxaammppllee 
FFiillll tthhee aarrrraayy 
ffoorr (( iinntt ii == 00 ;; ii << aarrrraayySSiizzee ;; ii ++++ )) 
{{ 
cciinn >>>> cc [[ ii ]] ;; 
}}
EExxaammppllee 
PPrriinntt iinn RReevveerrssee oorrddeerr 
ffoorr (( iinntt ii == aarrrraayySSiizzee ;; ii >>== 00 ;; ii ---- )) 
{{ 
ccoouutt <<<< cc [[ ii ]] ;; 
}} Incorrect code
EExxaammppllee 
PPrriinntt iinn RReevveerrssee oorrddeerr 
ffoorr (( iinntt ii == (( aarrrraayySSiizzee –– 11 )) ;; ii >>== 00 ;; ii ---- )) 
{{ 
ccoouutt <<<< cc [[ ii ]] ;; 
}}
EExxaammppllee 
vvooiidd DDaattee :::: ddiissppllaayy (( )) 
{{ 
cchhaarr ** mmoonntthhNNaammee [[ ]] == 
{{ 
""zzeerroo"",, ""JJaannuuaarryy"",, ""FFeebbrruuaarryy"",, ""MMaarrcchh"",, ""AApprriill"",, ""MMaayy"",, 
""JJuunnee"",, ""JJuullyy"",, ""AAuugguusstt"",, ""SSeepptteemmbbeerr"",, ""OOccttoobbeerr"",, 
""NNoovveemmbbeerr"" ,, ""DDeecceemmbbeerr"" 
}} ;; 
ccoouutt <<<< mmoonntthhNNaammee [[ mmoonntthh ]] <<<< '' '' <<<< ddaayy <<<< "",, "" <<<< yyeeaarr 
<<<< eennddll ;; 
}}
DDaattee mmyyddaattee [[ 1100 ]] =={{ 
DDaattee (( 2211 ,, 0011 ,, 
11997799 )) ,, 
DDaattee (( ““0011--JJaann--22000022”” 
)) ,, 
DDaattee (( 2211 ,, 0033 ,, 11997799 ,, 
DDaattee (( ““0011--FFeebb-- 
22000022”” )),, 
DDaattee (( 2211 ,, 0055 ,, 11997799 )) DDaattee (( 0022 ,, 0066 ,, 11997799 ,, 
DDaattee (( 0022 ,, 0077 ,, 11997799 )) DDaattee (( 0022 ,, 0088 ,, 11997799 )) DDaattee (( 0022 ,, 0099 ,, 11997799 )) DDaattee (( 0022 ,, 1100 ,, 11997799 }};;
String mmyySSttrriinngg [[ 55 ]] == {{ 
""FFiirrsstt lliinnee ooff mmeessssaaggeenn"" ,, 
""SSeeccoonndd lliinnee ooff mmeessssaaggeenn"",, 
SSttrriinngg (( ""TThhiirrdd lliinnee ooff 
mmeessssaaggeenn"" )) ,, 
SSttrriinngg (( ''--'' ,, 2255 )) ,, 
SSttrriinngg (( )) 
}} ;;
SSttrriinngg ** tteexxtt ;; 
tteexxtt == nneeww SSttrriinngg [[ 55 ]] ;;
String mmyySSttrriinngg [[ 55 ]] == {{ 
""FFiirrsstt lliinnee ooff mmeessssaaggeenn"",, 
""SSeeccoonndd lliinnee ooff mmeessssaaggeenn"",, 
SSttrriinngg (( ""TThhiirrdd lliinnee ooff 
mmeessssaaggee)) ,, 
SSttrriinngg(( ''--'',, 2255 )),, 
SSttrriinngg (( )) 
}};;
DDeeffaauulltt 
CCoonnssttrruuccttoorr
SSttrriinngg ** tteexxtt ;; 
tteexxtt == nneeww SSttrriinngg [[ 55 ]] ;; 
ddeelleettee tteexxtt ;; 
// Incorrect syntax for 
// deleting array
ddeelleettee [[ ]] tteexxtt ;;
EExxaammppllee 
iinntt ** iiPPttrr ;; 
iiPPttrr == nneeww iinntt [[ 1100 ]] ;; 
ddeelleettee iiPPttrr ;;//// bbaadd uussaaggee
ddeelleettee [[ ]] iiPPttrr ;; 
ddeelleettee [[ ]] tteexxtt ;;
OOvveerrllooaaddiinngg nneeww 
OOppeerraattoorr 
vvooiidd ** ooppeerraattoorr nneeww (( ssiizzee__tt ssiizzee )) 
{{ 
vvooiidd ** rrttnn == ccaalllloocc (( 11 ,, ssiizzee )) ;; 
rreettuurrnn rrttnn ;; 
}}
Overloading ddeelleettee OOppeerraattoorr 
vvooiidd ooppeerraattoorr ddeelleettee (( vvooiidd ** ppttrr )) 
{{ 
ffrreeee (( ppttrr )) ;; 
}}
OOvveerrllooaaddiinngg nneeww 
OOppeerraattoorr ffoorr DDaattee 
ccllaassss 
void * Date :: operator new (( ssiizzee__tt ssiizzee ))
EExxaammppllee 
int iiAArrrraayy [[ 1100 ]] ;; 
iinntt ii ;; 
ffoorr (( ii == 00 ;; ii << 110000 ;; ii ++++ )) 
{{ 
iiAArrrraayy [[ ii ]] == ii ;; 
}}
EExxaammppllee 
iinntt iiAArrrraayy [[ 1100 ]] ;; 
iinntt ii ;; 
ffoorr (( ii == 00;; ii << uuppppeerrLLiimmiitt ;; ii ++++)) 
{{ 
iiAArrrraayy [[ ii ]] == ii ;; 
}}
[[ ]]
iinntt iiAArrrraayy [[ 55 ]] ;;
int & operator [[ ]] (( iinntt iinnddeexx )) ;;
##ddeeffiinnee MMAAXXNNUUMM 1100 
iinntt iiAArrrraayy 
[[ MMAAXXNNUUMM ]] ;;
Overloaded AArrrraayy OOppeerraattoorr 
[[ ]] iinntt && IInnttAArrrraayy :::: ooppeerraattoorr [[ ]] (( iinntt iinnddeexx )) 
{{ 
iinntt dduummmmyy == 00 ;; 
iiff (( ((iinnddeexx >> (( MMAAXXNNUUMM –– 11 )) )) 
{{ 
ccoouutt <<<< ""EErrrroorr:: iinnvvaalliidd iinnddeexx ccaallll..nn““ ;; 
rreettuurrnn dduummmmyy ;; 
}} 
eellssee 
rreettuurrnn aarrrraayy [[ iinnddeexx ]] ;; 
}}
EExxaammppllee 
ccllaassss IInnttAArrrraayy 
{{ 
pprriivvaattee :: 
iinntt lleennggtthh ;; 
iinntt ** iiPPttrr ;; 
ppuubblliicc :: 
IInnttAArrrraayy (( iinntt ii )) ;; 
...... 
}} ;;
mmaaiinn (( )) 
{{ 
IInnttAArrrraayy ii (( 1100 )) ;; 
iinntt jj ;; 
ffoorr (( jj == 00 ;; jj << 1100 ;; jj ++++ )) 
ii [[ jj ]] == jj ;; 
}} 
EExxaammppllee
EExxaammppllee 
iinntt && IInnttAArrrraayy ::::ooppeerraattoorr [[ ]] (( iinntt iinnddeexx )) 
{{ 
iinntt dduummmmyy == 00 ;; 
iiff (( (( iinnddeexx << 00 )) |||| (( iinnddeexx >>== lleennggtthh )) )) 
{{ 
ccoouutt <<<< ""EErrrroorr :: iinnddeexx oouutt ooff rraannggee..nn"" ;; 
rreettuurrnn dduummmmyy ;; 
}} 
eellssee 
rreettuurrnn aarrrraayy [[ iinnddeexx ]] ;; 
}}
EExxaammppllee 
IntArray :: IInnttAArrrraayy (( iinntt ii )) 
{{ 
iinntt ** iiPPttrr ;; 
iiPPttrr == nneeww iinntt (( ii )) ;; 
lleennggtthh == ii ;; 
}}
TTooddaayy’’ss lleeccttuurree 
AArrrraayyss ooff oobbjjeeccttss 
DDyynnaammiiccaallllyy aallllooccaattiinngg aarrrraayyss uussiinngg 
nneeww ooppeerraattoorr 
UUssaaggeess aanndd oovveerrllooaaddiinngg nneeww aanndd 
ddeelleettee OOppeerraattoorr 
AArrrraayy ssuubbssccrriippttiinngg [[ ]] OOppeerraattoorr

More Related Content

What's hot

CS201- Introduction to Programming- Lecture 26
CS201- Introduction to Programming- Lecture 26CS201- Introduction to Programming- Lecture 26
CS201- Introduction to Programming- Lecture 26Bilal Ahmed
 
CS201- Introduction to Programming- Lecture 33
CS201- Introduction to Programming- Lecture 33CS201- Introduction to Programming- Lecture 33
CS201- Introduction to Programming- Lecture 33Bilal Ahmed
 
CS201- Introduction to Programming- Lecture 41
CS201- Introduction to Programming- Lecture 41CS201- Introduction to Programming- Lecture 41
CS201- Introduction to Programming- Lecture 41Bilal Ahmed
 
CS201- Introduction to Programming- Lecture 28
CS201- Introduction to Programming- Lecture 28CS201- Introduction to Programming- Lecture 28
CS201- Introduction to Programming- Lecture 28Bilal Ahmed
 
CS201- Introduction to Programming- Lecture 07
CS201- Introduction to Programming- Lecture 07CS201- Introduction to Programming- Lecture 07
CS201- Introduction to Programming- Lecture 07Bilal Ahmed
 
CS201- Introduction to Programming- Lecture 38
CS201- Introduction to Programming- Lecture 38CS201- Introduction to Programming- Lecture 38
CS201- Introduction to Programming- Lecture 38Bilal Ahmed
 
CS201- Introduction to Programming- Lecture 12
CS201- Introduction to Programming- Lecture 12CS201- Introduction to Programming- Lecture 12
CS201- Introduction to Programming- Lecture 12Bilal Ahmed
 
Edit data base menggunakan web
Edit data base menggunakan webEdit data base menggunakan web
Edit data base menggunakan webhaviedz miftah
 
CS201- Introduction to Programming- Lecture 44
CS201- Introduction to Programming- Lecture 44CS201- Introduction to Programming- Lecture 44
CS201- Introduction to Programming- Lecture 44Bilal Ahmed
 
CS201- Introduction to Programming- Lecture 30
CS201- Introduction to Programming- Lecture 30CS201- Introduction to Programming- Lecture 30
CS201- Introduction to Programming- Lecture 30Bilal Ahmed
 
CS201- Introduction to Programming- Lecture 42
CS201- Introduction to Programming- Lecture 42CS201- Introduction to Programming- Lecture 42
CS201- Introduction to Programming- Lecture 42Bilal Ahmed
 
CS201- Introduction to Programming- Lecture 25
CS201- Introduction to Programming- Lecture 25CS201- Introduction to Programming- Lecture 25
CS201- Introduction to Programming- Lecture 25Bilal Ahmed
 
CS201- Introduction to Programming- Lecture 09
CS201- Introduction to Programming- Lecture 09CS201- Introduction to Programming- Lecture 09
CS201- Introduction to Programming- Lecture 09Bilal Ahmed
 
CS201- Introduction to Programming- Lecture 37
CS201- Introduction to Programming- Lecture 37CS201- Introduction to Programming- Lecture 37
CS201- Introduction to Programming- Lecture 37Bilal Ahmed
 
pengenalan perangkat keras komputer
pengenalan perangkat keras komputerpengenalan perangkat keras komputer
pengenalan perangkat keras komputerzee120196
 
Perangkat Keras Hardware
Perangkat Keras HardwarePerangkat Keras Hardware
Perangkat Keras HardwareJohan19931106
 

What's hot (20)

CS201- Introduction to Programming- Lecture 26
CS201- Introduction to Programming- Lecture 26CS201- Introduction to Programming- Lecture 26
CS201- Introduction to Programming- Lecture 26
 
CS201- Introduction to Programming- Lecture 33
CS201- Introduction to Programming- Lecture 33CS201- Introduction to Programming- Lecture 33
CS201- Introduction to Programming- Lecture 33
 
CS201- Introduction to Programming- Lecture 41
CS201- Introduction to Programming- Lecture 41CS201- Introduction to Programming- Lecture 41
CS201- Introduction to Programming- Lecture 41
 
CS201- Introduction to Programming- Lecture 28
CS201- Introduction to Programming- Lecture 28CS201- Introduction to Programming- Lecture 28
CS201- Introduction to Programming- Lecture 28
 
CS201- Introduction to Programming- Lecture 07
CS201- Introduction to Programming- Lecture 07CS201- Introduction to Programming- Lecture 07
CS201- Introduction to Programming- Lecture 07
 
CS201- Introduction to Programming- Lecture 38
CS201- Introduction to Programming- Lecture 38CS201- Introduction to Programming- Lecture 38
CS201- Introduction to Programming- Lecture 38
 
CS201- Introduction to Programming- Lecture 12
CS201- Introduction to Programming- Lecture 12CS201- Introduction to Programming- Lecture 12
CS201- Introduction to Programming- Lecture 12
 
Edit data base menggunakan web
Edit data base menggunakan webEdit data base menggunakan web
Edit data base menggunakan web
 
CS201- Introduction to Programming- Lecture 44
CS201- Introduction to Programming- Lecture 44CS201- Introduction to Programming- Lecture 44
CS201- Introduction to Programming- Lecture 44
 
CS201- Introduction to Programming- Lecture 30
CS201- Introduction to Programming- Lecture 30CS201- Introduction to Programming- Lecture 30
CS201- Introduction to Programming- Lecture 30
 
CS201- Introduction to Programming- Lecture 42
CS201- Introduction to Programming- Lecture 42CS201- Introduction to Programming- Lecture 42
CS201- Introduction to Programming- Lecture 42
 
Mba ebooks
Mba ebooksMba ebooks
Mba ebooks
 
Ankit
AnkitAnkit
Ankit
 
CS201- Introduction to Programming- Lecture 25
CS201- Introduction to Programming- Lecture 25CS201- Introduction to Programming- Lecture 25
CS201- Introduction to Programming- Lecture 25
 
CS201- Introduction to Programming- Lecture 09
CS201- Introduction to Programming- Lecture 09CS201- Introduction to Programming- Lecture 09
CS201- Introduction to Programming- Lecture 09
 
CS201- Introduction to Programming- Lecture 37
CS201- Introduction to Programming- Lecture 37CS201- Introduction to Programming- Lecture 37
CS201- Introduction to Programming- Lecture 37
 
Perangkat keras komputer
Perangkat keras komputerPerangkat keras komputer
Perangkat keras komputer
 
Hardware
HardwareHardware
Hardware
 
pengenalan perangkat keras komputer
pengenalan perangkat keras komputerpengenalan perangkat keras komputer
pengenalan perangkat keras komputer
 
Perangkat Keras Hardware
Perangkat Keras HardwarePerangkat Keras Hardware
Perangkat Keras Hardware
 

Viewers also liked

MGT101 - Financial Accounting- Lecture 41
MGT101 - Financial Accounting- Lecture 41MGT101 - Financial Accounting- Lecture 41
MGT101 - Financial Accounting- Lecture 41Bilal Ahmed
 
MTH101 - Calculus and Analytical Geometry- Lecture 44
MTH101 - Calculus and Analytical Geometry- Lecture 44MTH101 - Calculus and Analytical Geometry- Lecture 44
MTH101 - Calculus and Analytical Geometry- Lecture 44Bilal Ahmed
 
ENG101- English Comprehension- Lecture 42
ENG101- English Comprehension- Lecture 42ENG101- English Comprehension- Lecture 42
ENG101- English Comprehension- Lecture 42Bilal Ahmed
 
MGT101 - Financial Accounting- Lecture 36
MGT101 - Financial Accounting- Lecture 36MGT101 - Financial Accounting- Lecture 36
MGT101 - Financial Accounting- Lecture 36Bilal Ahmed
 
CS101- Introduction to Computing- Lecture 44
CS101- Introduction to Computing- Lecture 44CS101- Introduction to Computing- Lecture 44
CS101- Introduction to Computing- Lecture 44Bilal Ahmed
 
CS101- Introduction to Computing- Lecture 32
CS101- Introduction to Computing- Lecture 32CS101- Introduction to Computing- Lecture 32
CS101- Introduction to Computing- Lecture 32Bilal Ahmed
 
CS201- Introduction to Programming- Lecture 35
CS201- Introduction to Programming- Lecture 35CS201- Introduction to Programming- Lecture 35
CS201- Introduction to Programming- Lecture 35Bilal Ahmed
 
CS101- Introduction to Computing- Lecture 29
CS101- Introduction to Computing- Lecture 29CS101- Introduction to Computing- Lecture 29
CS101- Introduction to Computing- Lecture 29Bilal Ahmed
 
MGT101 - Financial Accounting- Lecture 44
MGT101 - Financial Accounting- Lecture 44MGT101 - Financial Accounting- Lecture 44
MGT101 - Financial Accounting- Lecture 44Bilal Ahmed
 
CS101- Introduction to Computing- Lecture 23
CS101- Introduction to Computing- Lecture 23CS101- Introduction to Computing- Lecture 23
CS101- Introduction to Computing- Lecture 23Bilal Ahmed
 
MGT101 - Financial Accounting- Lecture 33
MGT101 - Financial Accounting- Lecture 33MGT101 - Financial Accounting- Lecture 33
MGT101 - Financial Accounting- Lecture 33Bilal Ahmed
 
CS101- Introduction to Computing- Lecture 39
CS101- Introduction to Computing- Lecture 39CS101- Introduction to Computing- Lecture 39
CS101- Introduction to Computing- Lecture 39Bilal Ahmed
 
CS101- Introduction to Computing- Lecture 43
CS101- Introduction to Computing- Lecture 43CS101- Introduction to Computing- Lecture 43
CS101- Introduction to Computing- Lecture 43Bilal Ahmed
 
ENG101- English Comprehension- Lecture 24
ENG101- English Comprehension- Lecture 24ENG101- English Comprehension- Lecture 24
ENG101- English Comprehension- Lecture 24Bilal Ahmed
 
MGT101 - Financial Accounting- Lecture 40
MGT101 - Financial Accounting- Lecture 40MGT101 - Financial Accounting- Lecture 40
MGT101 - Financial Accounting- Lecture 40Bilal Ahmed
 
MGT101 - Financial Accounting- Lecture 38
MGT101 - Financial Accounting- Lecture 38MGT101 - Financial Accounting- Lecture 38
MGT101 - Financial Accounting- Lecture 38Bilal Ahmed
 
CS201- Introduction to Programming- Lecture 31
CS201- Introduction to Programming- Lecture 31CS201- Introduction to Programming- Lecture 31
CS201- Introduction to Programming- Lecture 31Bilal Ahmed
 
ENG101- English Comprehension- Lecture 45
ENG101- English Comprehension- Lecture 45ENG101- English Comprehension- Lecture 45
ENG101- English Comprehension- Lecture 45Bilal Ahmed
 
ENG101- English Comprehension- Lecture 40
ENG101- English Comprehension- Lecture 40ENG101- English Comprehension- Lecture 40
ENG101- English Comprehension- Lecture 40Bilal Ahmed
 
PAK301- Pakistan Studies- Lecture 27
PAK301- Pakistan Studies- Lecture 27PAK301- Pakistan Studies- Lecture 27
PAK301- Pakistan Studies- Lecture 27Bilal Ahmed
 

Viewers also liked (20)

MGT101 - Financial Accounting- Lecture 41
MGT101 - Financial Accounting- Lecture 41MGT101 - Financial Accounting- Lecture 41
MGT101 - Financial Accounting- Lecture 41
 
MTH101 - Calculus and Analytical Geometry- Lecture 44
MTH101 - Calculus and Analytical Geometry- Lecture 44MTH101 - Calculus and Analytical Geometry- Lecture 44
MTH101 - Calculus and Analytical Geometry- Lecture 44
 
ENG101- English Comprehension- Lecture 42
ENG101- English Comprehension- Lecture 42ENG101- English Comprehension- Lecture 42
ENG101- English Comprehension- Lecture 42
 
MGT101 - Financial Accounting- Lecture 36
MGT101 - Financial Accounting- Lecture 36MGT101 - Financial Accounting- Lecture 36
MGT101 - Financial Accounting- Lecture 36
 
CS101- Introduction to Computing- Lecture 44
CS101- Introduction to Computing- Lecture 44CS101- Introduction to Computing- Lecture 44
CS101- Introduction to Computing- Lecture 44
 
CS101- Introduction to Computing- Lecture 32
CS101- Introduction to Computing- Lecture 32CS101- Introduction to Computing- Lecture 32
CS101- Introduction to Computing- Lecture 32
 
CS201- Introduction to Programming- Lecture 35
CS201- Introduction to Programming- Lecture 35CS201- Introduction to Programming- Lecture 35
CS201- Introduction to Programming- Lecture 35
 
CS101- Introduction to Computing- Lecture 29
CS101- Introduction to Computing- Lecture 29CS101- Introduction to Computing- Lecture 29
CS101- Introduction to Computing- Lecture 29
 
MGT101 - Financial Accounting- Lecture 44
MGT101 - Financial Accounting- Lecture 44MGT101 - Financial Accounting- Lecture 44
MGT101 - Financial Accounting- Lecture 44
 
CS101- Introduction to Computing- Lecture 23
CS101- Introduction to Computing- Lecture 23CS101- Introduction to Computing- Lecture 23
CS101- Introduction to Computing- Lecture 23
 
MGT101 - Financial Accounting- Lecture 33
MGT101 - Financial Accounting- Lecture 33MGT101 - Financial Accounting- Lecture 33
MGT101 - Financial Accounting- Lecture 33
 
CS101- Introduction to Computing- Lecture 39
CS101- Introduction to Computing- Lecture 39CS101- Introduction to Computing- Lecture 39
CS101- Introduction to Computing- Lecture 39
 
CS101- Introduction to Computing- Lecture 43
CS101- Introduction to Computing- Lecture 43CS101- Introduction to Computing- Lecture 43
CS101- Introduction to Computing- Lecture 43
 
ENG101- English Comprehension- Lecture 24
ENG101- English Comprehension- Lecture 24ENG101- English Comprehension- Lecture 24
ENG101- English Comprehension- Lecture 24
 
MGT101 - Financial Accounting- Lecture 40
MGT101 - Financial Accounting- Lecture 40MGT101 - Financial Accounting- Lecture 40
MGT101 - Financial Accounting- Lecture 40
 
MGT101 - Financial Accounting- Lecture 38
MGT101 - Financial Accounting- Lecture 38MGT101 - Financial Accounting- Lecture 38
MGT101 - Financial Accounting- Lecture 38
 
CS201- Introduction to Programming- Lecture 31
CS201- Introduction to Programming- Lecture 31CS201- Introduction to Programming- Lecture 31
CS201- Introduction to Programming- Lecture 31
 
ENG101- English Comprehension- Lecture 45
ENG101- English Comprehension- Lecture 45ENG101- English Comprehension- Lecture 45
ENG101- English Comprehension- Lecture 45
 
ENG101- English Comprehension- Lecture 40
ENG101- English Comprehension- Lecture 40ENG101- English Comprehension- Lecture 40
ENG101- English Comprehension- Lecture 40
 
PAK301- Pakistan Studies- Lecture 27
PAK301- Pakistan Studies- Lecture 27PAK301- Pakistan Studies- Lecture 27
PAK301- Pakistan Studies- Lecture 27
 

Similar to CS201- Introduction to Programming- Lecture 34

CS201- Introduction to Programming- Lecture 23
CS201- Introduction to Programming- Lecture 23CS201- Introduction to Programming- Lecture 23
CS201- Introduction to Programming- Lecture 23Bilal Ahmed
 
CS201- Introduction to Programming- Lecture 45
CS201- Introduction to Programming- Lecture 45CS201- Introduction to Programming- Lecture 45
CS201- Introduction to Programming- Lecture 45Bilal Ahmed
 
CS201- Introduction to Programming- Lecture 03
CS201- Introduction to Programming- Lecture 03CS201- Introduction to Programming- Lecture 03
CS201- Introduction to Programming- Lecture 03Bilal Ahmed
 
CS201- Introduction to Programming- Lecture 08
CS201- Introduction to Programming- Lecture 08CS201- Introduction to Programming- Lecture 08
CS201- Introduction to Programming- Lecture 08Bilal Ahmed
 
21 High-quality programming code construction part-ii
21 High-quality programming code construction part-ii21 High-quality programming code construction part-ii
21 High-quality programming code construction part-iimaznabili
 
CS201- Introduction to Programming- Lecture 22
CS201- Introduction to Programming- Lecture 22CS201- Introduction to Programming- Lecture 22
CS201- Introduction to Programming- Lecture 22Bilal Ahmed
 
CS201- Introduction to Programming- Lecture 10
CS201- Introduction to Programming- Lecture 10CS201- Introduction to Programming- Lecture 10
CS201- Introduction to Programming- Lecture 10Bilal Ahmed
 
CS201- Introduction to Programming- Lecture 27
CS201- Introduction to Programming- Lecture 27CS201- Introduction to Programming- Lecture 27
CS201- Introduction to Programming- Lecture 27Bilal Ahmed
 
CS201- Introduction to Programming- Lecture 06
CS201- Introduction to Programming- Lecture 06CS201- Introduction to Programming- Lecture 06
CS201- Introduction to Programming- Lecture 06Bilal Ahmed
 
TOP Downloaded Papers (January)--International Journal of Computer Networks &...
TOP Downloaded Papers (January)--International Journal of Computer Networks &...TOP Downloaded Papers (January)--International Journal of Computer Networks &...
TOP Downloaded Papers (January)--International Journal of Computer Networks &...IJCNCJournal
 
CS201- Introduction to Programming- Lecture 04
CS201- Introduction to Programming- Lecture 04CS201- Introduction to Programming- Lecture 04
CS201- Introduction to Programming- Lecture 04Bilal Ahmed
 
CS201- Introduction to Programming- Lecture 19
CS201- Introduction to Programming- Lecture 19CS201- Introduction to Programming- Lecture 19
CS201- Introduction to Programming- Lecture 19Bilal Ahmed
 
Contrarrazoes ro vinculo empregaticio reclamada ilovepdf-compressed
Contrarrazoes ro vinculo empregaticio reclamada ilovepdf-compressedContrarrazoes ro vinculo empregaticio reclamada ilovepdf-compressed
Contrarrazoes ro vinculo empregaticio reclamada ilovepdf-compressedLeve Desejo
 
Termoquímica - Setor Leste
Termoquímica - Setor LesteTermoquímica - Setor Leste
Termoquímica - Setor LesteMarianaMartinsR
 

Similar to CS201- Introduction to Programming- Lecture 34 (16)

CS201- Introduction to Programming- Lecture 23
CS201- Introduction to Programming- Lecture 23CS201- Introduction to Programming- Lecture 23
CS201- Introduction to Programming- Lecture 23
 
CS201- Introduction to Programming- Lecture 45
CS201- Introduction to Programming- Lecture 45CS201- Introduction to Programming- Lecture 45
CS201- Introduction to Programming- Lecture 45
 
CS201- Introduction to Programming- Lecture 03
CS201- Introduction to Programming- Lecture 03CS201- Introduction to Programming- Lecture 03
CS201- Introduction to Programming- Lecture 03
 
CS201- Introduction to Programming- Lecture 08
CS201- Introduction to Programming- Lecture 08CS201- Introduction to Programming- Lecture 08
CS201- Introduction to Programming- Lecture 08
 
21 High-quality programming code construction part-ii
21 High-quality programming code construction part-ii21 High-quality programming code construction part-ii
21 High-quality programming code construction part-ii
 
CS201- Introduction to Programming- Lecture 22
CS201- Introduction to Programming- Lecture 22CS201- Introduction to Programming- Lecture 22
CS201- Introduction to Programming- Lecture 22
 
CS201- Introduction to Programming- Lecture 10
CS201- Introduction to Programming- Lecture 10CS201- Introduction to Programming- Lecture 10
CS201- Introduction to Programming- Lecture 10
 
CS201- Introduction to Programming- Lecture 27
CS201- Introduction to Programming- Lecture 27CS201- Introduction to Programming- Lecture 27
CS201- Introduction to Programming- Lecture 27
 
CS201- Introduction to Programming- Lecture 06
CS201- Introduction to Programming- Lecture 06CS201- Introduction to Programming- Lecture 06
CS201- Introduction to Programming- Lecture 06
 
Tiro parabólico
Tiro parabólicoTiro parabólico
Tiro parabólico
 
TOP Downloaded Papers (January)--International Journal of Computer Networks &...
TOP Downloaded Papers (January)--International Journal of Computer Networks &...TOP Downloaded Papers (January)--International Journal of Computer Networks &...
TOP Downloaded Papers (January)--International Journal of Computer Networks &...
 
CS201- Introduction to Programming- Lecture 04
CS201- Introduction to Programming- Lecture 04CS201- Introduction to Programming- Lecture 04
CS201- Introduction to Programming- Lecture 04
 
CS201- Introduction to Programming- Lecture 19
CS201- Introduction to Programming- Lecture 19CS201- Introduction to Programming- Lecture 19
CS201- Introduction to Programming- Lecture 19
 
Contrarrazoes ro vinculo empregaticio reclamada ilovepdf-compressed
Contrarrazoes ro vinculo empregaticio reclamada ilovepdf-compressedContrarrazoes ro vinculo empregaticio reclamada ilovepdf-compressed
Contrarrazoes ro vinculo empregaticio reclamada ilovepdf-compressed
 
Angular.js
Angular.jsAngular.js
Angular.js
 
Termoquímica - Setor Leste
Termoquímica - Setor LesteTermoquímica - Setor Leste
Termoquímica - Setor Leste
 

More from Bilal Ahmed

CS201- Introduction to Programming- Lecture 43
CS201- Introduction to Programming- Lecture 43CS201- Introduction to Programming- Lecture 43
CS201- Introduction to Programming- Lecture 43Bilal Ahmed
 
CS201- Introduction to Programming- Lecture 39
CS201- Introduction to Programming- Lecture 39CS201- Introduction to Programming- Lecture 39
CS201- Introduction to Programming- Lecture 39Bilal Ahmed
 
CS201- Introduction to Programming- Lecture 32
CS201- Introduction to Programming- Lecture 32CS201- Introduction to Programming- Lecture 32
CS201- Introduction to Programming- Lecture 32Bilal Ahmed
 
CS201- Introduction to Programming- Lecture 29
CS201- Introduction to Programming- Lecture 29CS201- Introduction to Programming- Lecture 29
CS201- Introduction to Programming- Lecture 29Bilal Ahmed
 
CS201- Introduction to Programming- Lecture 24
CS201- Introduction to Programming- Lecture 24CS201- Introduction to Programming- Lecture 24
CS201- Introduction to Programming- Lecture 24Bilal Ahmed
 
CS201- Introduction to Programming- Lecture 21
CS201- Introduction to Programming- Lecture 21CS201- Introduction to Programming- Lecture 21
CS201- Introduction to Programming- Lecture 21Bilal Ahmed
 
CS201- Introduction to Programming- Lecture 18
CS201- Introduction to Programming- Lecture 18CS201- Introduction to Programming- Lecture 18
CS201- Introduction to Programming- Lecture 18Bilal Ahmed
 
CS201- Introduction to Programming- Lecture 17
CS201- Introduction to Programming- Lecture 17CS201- Introduction to Programming- Lecture 17
CS201- Introduction to Programming- Lecture 17Bilal Ahmed
 

More from Bilal Ahmed (8)

CS201- Introduction to Programming- Lecture 43
CS201- Introduction to Programming- Lecture 43CS201- Introduction to Programming- Lecture 43
CS201- Introduction to Programming- Lecture 43
 
CS201- Introduction to Programming- Lecture 39
CS201- Introduction to Programming- Lecture 39CS201- Introduction to Programming- Lecture 39
CS201- Introduction to Programming- Lecture 39
 
CS201- Introduction to Programming- Lecture 32
CS201- Introduction to Programming- Lecture 32CS201- Introduction to Programming- Lecture 32
CS201- Introduction to Programming- Lecture 32
 
CS201- Introduction to Programming- Lecture 29
CS201- Introduction to Programming- Lecture 29CS201- Introduction to Programming- Lecture 29
CS201- Introduction to Programming- Lecture 29
 
CS201- Introduction to Programming- Lecture 24
CS201- Introduction to Programming- Lecture 24CS201- Introduction to Programming- Lecture 24
CS201- Introduction to Programming- Lecture 24
 
CS201- Introduction to Programming- Lecture 21
CS201- Introduction to Programming- Lecture 21CS201- Introduction to Programming- Lecture 21
CS201- Introduction to Programming- Lecture 21
 
CS201- Introduction to Programming- Lecture 18
CS201- Introduction to Programming- Lecture 18CS201- Introduction to Programming- Lecture 18
CS201- Introduction to Programming- Lecture 18
 
CS201- Introduction to Programming- Lecture 17
CS201- Introduction to Programming- Lecture 17CS201- Introduction to Programming- Lecture 17
CS201- Introduction to Programming- Lecture 17
 

Recently uploaded

Tekoäly ja opinto-ohjaus, webinaari 26.4.24
Tekoäly ja opinto-ohjaus, webinaari 26.4.24Tekoäly ja opinto-ohjaus, webinaari 26.4.24
Tekoäly ja opinto-ohjaus, webinaari 26.4.24Matleena Laakso
 
Valkohäntäpeura (Odocoileus virginianus).pptx
Valkohäntäpeura (Odocoileus virginianus).pptxValkohäntäpeura (Odocoileus virginianus).pptx
Valkohäntäpeura (Odocoileus virginianus).pptxpurmonen8
 
Tekoäly opetuksessa. Seinäjoen lyseo 24.4.24
Tekoäly opetuksessa. Seinäjoen lyseo 24.4.24Tekoäly opetuksessa. Seinäjoen lyseo 24.4.24
Tekoäly opetuksessa. Seinäjoen lyseo 24.4.24Matleena Laakso
 
Tekoäly ja oppiminen. Airut-hanke 23.4.24
Tekoäly ja oppiminen. Airut-hanke 23.4.24Tekoäly ja oppiminen. Airut-hanke 23.4.24
Tekoäly ja oppiminen. Airut-hanke 23.4.24Matleena Laakso
 
Tekoäly opetuksessa, opettajien kevätpäivä 26.4.24
Tekoäly opetuksessa, opettajien kevätpäivä 26.4.24Tekoäly opetuksessa, opettajien kevätpäivä 26.4.24
Tekoäly opetuksessa, opettajien kevätpäivä 26.4.24Matleena Laakso
 
Opettaja ja tekoäly. Pedaiiltapäivä 25.4.24
Opettaja ja tekoäly. Pedaiiltapäivä 25.4.24Opettaja ja tekoäly. Pedaiiltapäivä 25.4.24
Opettaja ja tekoäly. Pedaiiltapäivä 25.4.24Matleena Laakso
 
Tekoälyä koulunkäynninohjaajille. Jyty 27.4.24
Tekoälyä koulunkäynninohjaajille. Jyty 27.4.24Tekoälyä koulunkäynninohjaajille. Jyty 27.4.24
Tekoälyä koulunkäynninohjaajille. Jyty 27.4.24Matleena Laakso
 

Recently uploaded (8)

Tekoäly ja opinto-ohjaus, webinaari 26.4.24
Tekoäly ja opinto-ohjaus, webinaari 26.4.24Tekoäly ja opinto-ohjaus, webinaari 26.4.24
Tekoäly ja opinto-ohjaus, webinaari 26.4.24
 
Valkohäntäpeura (Odocoileus virginianus).pptx
Valkohäntäpeura (Odocoileus virginianus).pptxValkohäntäpeura (Odocoileus virginianus).pptx
Valkohäntäpeura (Odocoileus virginianus).pptx
 
Tekoäly opetuksessa. Seinäjoen lyseo 24.4.24
Tekoäly opetuksessa. Seinäjoen lyseo 24.4.24Tekoäly opetuksessa. Seinäjoen lyseo 24.4.24
Tekoäly opetuksessa. Seinäjoen lyseo 24.4.24
 
Tekoäly ja oppiminen. Airut-hanke 23.4.24
Tekoäly ja oppiminen. Airut-hanke 23.4.24Tekoäly ja oppiminen. Airut-hanke 23.4.24
Tekoäly ja oppiminen. Airut-hanke 23.4.24
 
Tekoäly opetuksessa, opettajien kevätpäivä 26.4.24
Tekoäly opetuksessa, opettajien kevätpäivä 26.4.24Tekoäly opetuksessa, opettajien kevätpäivä 26.4.24
Tekoäly opetuksessa, opettajien kevätpäivä 26.4.24
 
Koulutuksen palkat ja kustannukset sekä koulutuksen ansiot
Koulutuksen palkat ja kustannukset sekä koulutuksen ansiotKoulutuksen palkat ja kustannukset sekä koulutuksen ansiot
Koulutuksen palkat ja kustannukset sekä koulutuksen ansiot
 
Opettaja ja tekoäly. Pedaiiltapäivä 25.4.24
Opettaja ja tekoäly. Pedaiiltapäivä 25.4.24Opettaja ja tekoäly. Pedaiiltapäivä 25.4.24
Opettaja ja tekoäly. Pedaiiltapäivä 25.4.24
 
Tekoälyä koulunkäynninohjaajille. Jyty 27.4.24
Tekoälyä koulunkäynninohjaajille. Jyty 27.4.24Tekoälyä koulunkäynninohjaajille. Jyty 27.4.24
Tekoälyä koulunkäynninohjaajille. Jyty 27.4.24
 

CS201- Introduction to Programming- Lecture 34

  • 2. IInn TTooddaayy’’ss LLeeccttuurree  AArrrraayyss ooff oobbjjeeccttss  IInntteerraaccttiioonn ooff AArrrraayyss wwiitthh FFrreeee SSttoorree  nneeww aanndd ddeelleettee ooppeerraattoorrss OOvveerrllooaaddiinngg ooff AArrrraayyss OOppeerraattoorr
  • 4. Date mmyyddaattee [[ 1100 ]] ;;
  • 5. int intArray [ 10 ] = { 1 ,, 22 ,, 33 ,, 44 ,, 55 66 ,, 77 ,, 88 ,, 99 ,, 1100 }} ;;
  • 6. DDaattee mmyyddaattee [[ 1100 ]] == {{ DDaattee (( 2211 ,, 0011 ,, 11997799 )) DDaattee (( 2211 ,, 0022 ,, 11997799 )) DDaattee (( 2211 ,, 0033 ,, 11997799 )) DDaattee (( 2211 ,, 0044 ,, 11997799 )) DDaattee (( 2211 ,, 0055 ,, 11997799 )) DDaattee (( 0022 ,, 0066 ,, 11997799 )) DDaattee (( 0022 ,, 0077 ,, 11997799 ,, DDaattee (( 0022 ,, 0088 ,, 11997799 )) DDaattee (( 0022 ,, 0099 ,, 11997799 )) DDaattee (( 0022 ,, 1100 ,, 11997799 )) }};;
  • 7. EExxaammppllee FFiillll tthhee aarrrraayy ffoorr (( iinntt ii == 00 ;; ii << aarrrraayySSiizzee ;; ii ++++ )) {{ cciinn >>>> cc [[ ii ]] ;; }}
  • 8. EExxaammppllee PPrriinntt iinn RReevveerrssee oorrddeerr ffoorr (( iinntt ii == aarrrraayySSiizzee ;; ii >>== 00 ;; ii ---- )) {{ ccoouutt <<<< cc [[ ii ]] ;; }} Incorrect code
  • 9. EExxaammppllee PPrriinntt iinn RReevveerrssee oorrddeerr ffoorr (( iinntt ii == (( aarrrraayySSiizzee –– 11 )) ;; ii >>== 00 ;; ii ---- )) {{ ccoouutt <<<< cc [[ ii ]] ;; }}
  • 10. EExxaammppllee vvooiidd DDaattee :::: ddiissppllaayy (( )) {{ cchhaarr ** mmoonntthhNNaammee [[ ]] == {{ ""zzeerroo"",, ""JJaannuuaarryy"",, ""FFeebbrruuaarryy"",, ""MMaarrcchh"",, ""AApprriill"",, ""MMaayy"",, ""JJuunnee"",, ""JJuullyy"",, ""AAuugguusstt"",, ""SSeepptteemmbbeerr"",, ""OOccttoobbeerr"",, ""NNoovveemmbbeerr"" ,, ""DDeecceemmbbeerr"" }} ;; ccoouutt <<<< mmoonntthhNNaammee [[ mmoonntthh ]] <<<< '' '' <<<< ddaayy <<<< "",, "" <<<< yyeeaarr <<<< eennddll ;; }}
  • 11. DDaattee mmyyddaattee [[ 1100 ]] =={{ DDaattee (( 2211 ,, 0011 ,, 11997799 )) ,, DDaattee (( ““0011--JJaann--22000022”” )) ,, DDaattee (( 2211 ,, 0033 ,, 11997799 ,, DDaattee (( ““0011--FFeebb-- 22000022”” )),, DDaattee (( 2211 ,, 0055 ,, 11997799 )) DDaattee (( 0022 ,, 0066 ,, 11997799 ,, DDaattee (( 0022 ,, 0077 ,, 11997799 )) DDaattee (( 0022 ,, 0088 ,, 11997799 )) DDaattee (( 0022 ,, 0099 ,, 11997799 )) DDaattee (( 0022 ,, 1100 ,, 11997799 }};;
  • 12. String mmyySSttrriinngg [[ 55 ]] == {{ ""FFiirrsstt lliinnee ooff mmeessssaaggeenn"" ,, ""SSeeccoonndd lliinnee ooff mmeessssaaggeenn"",, SSttrriinngg (( ""TThhiirrdd lliinnee ooff mmeessssaaggeenn"" )) ,, SSttrriinngg (( ''--'' ,, 2255 )) ,, SSttrriinngg (( )) }} ;;
  • 13. SSttrriinngg ** tteexxtt ;; tteexxtt == nneeww SSttrriinngg [[ 55 ]] ;;
  • 14. String mmyySSttrriinngg [[ 55 ]] == {{ ""FFiirrsstt lliinnee ooff mmeessssaaggeenn"",, ""SSeeccoonndd lliinnee ooff mmeessssaaggeenn"",, SSttrriinngg (( ""TThhiirrdd lliinnee ooff mmeessssaaggee)) ,, SSttrriinngg(( ''--'',, 2255 )),, SSttrriinngg (( )) }};;
  • 16. SSttrriinngg ** tteexxtt ;; tteexxtt == nneeww SSttrriinngg [[ 55 ]] ;; ddeelleettee tteexxtt ;; // Incorrect syntax for // deleting array
  • 17. ddeelleettee [[ ]] tteexxtt ;;
  • 18. EExxaammppllee iinntt ** iiPPttrr ;; iiPPttrr == nneeww iinntt [[ 1100 ]] ;; ddeelleettee iiPPttrr ;;//// bbaadd uussaaggee
  • 19. ddeelleettee [[ ]] iiPPttrr ;; ddeelleettee [[ ]] tteexxtt ;;
  • 20. OOvveerrllooaaddiinngg nneeww OOppeerraattoorr vvooiidd ** ooppeerraattoorr nneeww (( ssiizzee__tt ssiizzee )) {{ vvooiidd ** rrttnn == ccaalllloocc (( 11 ,, ssiizzee )) ;; rreettuurrnn rrttnn ;; }}
  • 21. Overloading ddeelleettee OOppeerraattoorr vvooiidd ooppeerraattoorr ddeelleettee (( vvooiidd ** ppttrr )) {{ ffrreeee (( ppttrr )) ;; }}
  • 22. OOvveerrllooaaddiinngg nneeww OOppeerraattoorr ffoorr DDaattee ccllaassss void * Date :: operator new (( ssiizzee__tt ssiizzee ))
  • 23. EExxaammppllee int iiAArrrraayy [[ 1100 ]] ;; iinntt ii ;; ffoorr (( ii == 00 ;; ii << 110000 ;; ii ++++ )) {{ iiAArrrraayy [[ ii ]] == ii ;; }}
  • 24. EExxaammppllee iinntt iiAArrrraayy [[ 1100 ]] ;; iinntt ii ;; ffoorr (( ii == 00;; ii << uuppppeerrLLiimmiitt ;; ii ++++)) {{ iiAArrrraayy [[ ii ]] == ii ;; }}
  • 25. [[ ]]
  • 27. int & operator [[ ]] (( iinntt iinnddeexx )) ;;
  • 28. ##ddeeffiinnee MMAAXXNNUUMM 1100 iinntt iiAArrrraayy [[ MMAAXXNNUUMM ]] ;;
  • 29. Overloaded AArrrraayy OOppeerraattoorr [[ ]] iinntt && IInnttAArrrraayy :::: ooppeerraattoorr [[ ]] (( iinntt iinnddeexx )) {{ iinntt dduummmmyy == 00 ;; iiff (( ((iinnddeexx >> (( MMAAXXNNUUMM –– 11 )) )) {{ ccoouutt <<<< ""EErrrroorr:: iinnvvaalliidd iinnddeexx ccaallll..nn““ ;; rreettuurrnn dduummmmyy ;; }} eellssee rreettuurrnn aarrrraayy [[ iinnddeexx ]] ;; }}
  • 30. EExxaammppllee ccllaassss IInnttAArrrraayy {{ pprriivvaattee :: iinntt lleennggtthh ;; iinntt ** iiPPttrr ;; ppuubblliicc :: IInnttAArrrraayy (( iinntt ii )) ;; ...... }} ;;
  • 31. mmaaiinn (( )) {{ IInnttAArrrraayy ii (( 1100 )) ;; iinntt jj ;; ffoorr (( jj == 00 ;; jj << 1100 ;; jj ++++ )) ii [[ jj ]] == jj ;; }} EExxaammppllee
  • 32. EExxaammppllee iinntt && IInnttAArrrraayy ::::ooppeerraattoorr [[ ]] (( iinntt iinnddeexx )) {{ iinntt dduummmmyy == 00 ;; iiff (( (( iinnddeexx << 00 )) |||| (( iinnddeexx >>== lleennggtthh )) )) {{ ccoouutt <<<< ""EErrrroorr :: iinnddeexx oouutt ooff rraannggee..nn"" ;; rreettuurrnn dduummmmyy ;; }} eellssee rreettuurrnn aarrrraayy [[ iinnddeexx ]] ;; }}
  • 33. EExxaammppllee IntArray :: IInnttAArrrraayy (( iinntt ii )) {{ iinntt ** iiPPttrr ;; iiPPttrr == nneeww iinntt (( ii )) ;; lleennggtthh == ii ;; }}
  • 34. TTooddaayy’’ss lleeccttuurree AArrrraayyss ooff oobbjjeeccttss DDyynnaammiiccaallllyy aallllooccaattiinngg aarrrraayyss uussiinngg nneeww ooppeerraattoorr UUssaaggeess aanndd oovveerrllooaaddiinngg nneeww aanndd ddeelleettee OOppeerraattoorr AArrrraayy ssuubbssccrriippttiinngg [[ ]] OOppeerraattoorr