Tutorial_6
Tutorial_6
EEN-103
Autumn201 9
1
.Dec lar
ationac l
as s‘EmployeeRec’wit
hthr
eepr i
vatedat
amembers:‘
employ
eeNo’oft ype
i
nt,‘
monSal ar
y’oft y
pef l
oatand‘ desi
gnat
ion’ofty
pestri
ng.Cr
eat
eobjec
ts‘f
irs
tEmp’and
‘
secondEmp’ofc lass‘EmployeeRec’andiniti
ali
zethem t
hroug
hpubl
icmemberf unc
tions
f
oras s
igningval
uesanddi s
playi
ngt h
esevalues.
2.Declar
eac l
as snamed‘ StudentRec’wit
ht hreepr i
vatemember s:‘
enrolNo’oft y
pei nt
,
‘
CGPA’ oftypef l
oatand‘ branch’oftypestr
ing.Declareanarrayofobject
snamed‘ Student’
ofsize5ofc l
as s‘StudentRec ’
.Writ
epubl i
cmemberf unct
ions:(i
)voids ort(s
tudentRec
St
udent[],intN)t os or
tt hedat ainascendingorderwithrespectto‘CGPA’and( ii
)v oid
pri
nt(studentRecSt udent[],intN)t odisplaythes ort
edanduns ort
eds tudent
s’records.
Wri
temai ntot estt
h esememberf uncti
ons.
3.Createac l
as s‘Ti
me’wh osepr i
vatedat amember sar eh ours,minutesands econds,allof
typeint.Twomemberf unctionsar e:i)'s
etTime' t
hatt akesth r
eepar ametersoftypei ntand
isoft y
pev oid.Thet askoft hisf uncti
oni stos ett imei nh ours,minutesands econds
proper l
y,i
i)'dis
playTime'oft ypev oidthatdisplaystheuni versalti
meobj ectpr
oper ly(
i.
e,1
hour,22mi nutesand5s econdsi sdi spl
ayedas01 :
22:05;23h ours,59minutesand0s econd
isdis pl
ayedas23: 59:
00andi i
i)'toSeconds'thatt akesapar ameteroft ype'Time'and
returnstypeintafterconver t
ingt hetimei nt
os econds )
.
4.Inquesti
on3,addadef aultconst
ructorth atset
st i
met omi dni
ghttimeandac onstruct
or
withthr
eeparameterstos ethour
s,mi nutesands econdsproperly
.Furt
her,addamember
funct
ion‘t
oSeconds
’thattakesapar amet eroftype‘Time’andreturnst
ypeint.Th etaskof
thi
sfuncti
onist oconver
tt imeintos econds.Writethedr i
veroft hecl
asst ot estthese
funct
ions.
5
.Inquesti
on4,addac opyconst
ruct
orandus
eitt
odec
lar
eandi
nit
ial
ize‘
Time’obj
ect
.
Wr
itet
hec l
ientc
odet
otestthecl
ass.
6
.WAPt ocreatecl
assDat ehavingthr
eeprivatedatamember s(day ,month,y
ear).Cl
ass
sh
ouldhave(i)appropr
iateconstr
uctor
s(i
i)memberf unc
tionstoc alculat
edayssinc
ea
gi
vendate,i
ntdays(
Dated)( i
ii
)displ
aydat
e( iv
)BooleanmethodisEarlier(
Dat
ed)t ofi
nd
whet
herdi saft
erorbef orecall
ingdateobject.Not
e–Donott akec areofleapyear
matt
er,l
etFebbe28day salways.
WAPwh i
chusestheDat
ecl
asstorepr
esentdat
eofbir
thobj
ects
.Giv
entwodatesofbi
rth
wri
tecodetofindth
eagedi
ffer
encebet
weenthem.Note–tr
eatcurr
entdat
ealsoasan
obj
ect
7.Defi
neac l
assf orabowleroffi
eldingsidei
naf i
fty-
fif
tycr
icketmatch.I
tshouldhaveal
l
rel
evantdata(no.ofoversbowled,no.ofmaidens,runsgi
ven,wicket
staken,extr
as(no
bal
ls,wi
des)g i
ven),adi
s pl
aymethodt odis
playdatai nt
abularform.Cr
eatefivebowl
er
obj
ectsandfindthebestbowlerwit
hs omecrit
eri
a.
8.Obj
ect
-or
ient
edv
ers
ionofs
addl
e-poi
ntpr
ogr
am:A s
addl
epoi
ntofanx
nmat
rixi
s
definedasf ollows :Th es mal les telementofar owi sas addlepointifitisthelarges tin
it
sc olumn, e.g.inth ef ollowi ngmat rix
,
7 5 8
1
0 2 3
1 3 4
theelement5atpos ition( 1,
2)i nthemat rixisas addl epoi nt
.Noot herrowh asas addl e
point.Assumet hatt her ear enodupl i
c atesi nar ow,andt hereisonlyoneorz eronumber
ofsaddl epoi ntsi nth emat r
ix.
Dev el
opac las snamed‘ Saddl e’ withfollowings c heme:
(i
)I ts houldh av et hr ee pr iv ate dat a member s,( a)a t wo-dimensionalar r
aynamed
‘matrix’
, (b)r ownumberofs addle-poi nt,(c
)c ol umnnumberofs addl e-
point
(i
i)A par amet erised c ons truc torwh icht akest hes izen( aspar amet er)
,alloc ates
dynami cs pac ef ort hear ray ,andput sv aluesi ni tfromt hekeyboard. I
talsoini
tializes
thedat amember s( b)and( c)abov et oav alue- 1,indicati
ngthatt hesaddlehasnot
yetbeendet ermi ned.
(i
ii) Appr opr i
at ememberf unc ti
onsf orac compl is
h i
ngt hetask.
(i
v) Ar es ultmet hodt hati nf ormswh et hers addl epoi ntex i
stsornotandi fyesth enat
wh atpos iti
on.
Writeat estc lassf ort es tingt heabov ec lass.