2017 12 Usp Sp Sa1 Computer Science 02 Ans | Constructor (Object Oriented Programming)

Please download to get full document.

View again

of 5
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.
Information Report



Views: 6 | Pages: 5

Extension: DOCX | Download: 0

Related documents
2017 12 Usp Sp Sa1 Computer Science 02 Ans
  COMPUTER SCIENCE (083) SHORT TEST, SET-1 Marking S c h e m eCa!! #II Time 3hr! Ma$% Mark! &0' e n e r a I n ! (r  c( i * n ! ã Thi! +e!(i*n aer ha! - +e!(i*n!% ã . (he +e!(i*n! are c*m!*r/% ã ri(e (he c*rrec( !eria nmer *2 (he +e!(i*n e2*re a((em(ing i(% Ans1 a) break, continue, goto, exit 4 * ½ = 2 b) Run Time Error : Error occurring in a program uring its execution! rogram execution #a$ts %#ensuc# an error is encountere!Examp$e:int A, &, '(cinA&(' = A  &( Runtime error i+ a$ue o+ & is -ero!./ntax Error: Error occurre ue to %rong s/ntax o+ $anguage etecte b/ t#e compi$er uringcompi$ation!Examp$e:cout0A ' rogram0( c) i) ct/pe!#, iomanip!#, iostream!#, mat#!# 4 * ½ = 2 ii) conio!#, string!#, stio!#, process!# 4 * ½ = 2 ) i) inc$ue 3iostream!#const int ax   15( assignment operator %as missing ½oi main6)7 i n( N  m  e r !4 M a $ 5  670,80,10,30, - 09: initia$i-ation %as incorrect ½+or6 in ( 8oc=ax91( 8oc=5( 8oc99) 8oc %as une+ine ½cout ;;  umbers;8oc<( input operator %as useii) C*rrec(e< Pr*gram inc$ue3iostream!# i n c $ u e 3s t i o !# == #eaer +i$e %as missing > oi main6)7 struct .T>?ET7 c#ar stu@name;25<(c#ar stu@sex(i nt st u    @ a g e ( = initia$i-ation not a$$o%e insie structure e+inition ½ stuent(gets6s t u e n t !s t u@ n a m e   ): = structure re+erence %as missing ½cins tu e n t !s t u@ s e x ( == cannot use gets6) +unction +or a c#aracter input ½st u e n t !st u @ a g e = 1  ( = Bgnore e) i) ECE/CEpEB. D ii) 15121!F12 G 1H G D5 G D1!F +) 6ii) I4 2  Ans2 a) A constructor t#at accepts no parameters is ca$$e t#e e+au$t constructor! T#e compi$er supp$ies a e+au$t constructor, i+ a c$ass #as no exp$icit constructor e+ine! Bt initia$i-es t#eata members b/ a umm/ a$ue! Bt is a$so use to create obJects %it# e+au$t a$ues! 1?estructor is use to estro/ t#e obJects an ea$$ocate t#e memor/ resources t#at #ae  been a$$ocate b/ a constructor! Bt #as same name as t#e c$ass precee b/ ti$e 6K)! Bt takes no arguments an no return t/pes can be speci+ie! 1  b)  pub$ic isibi$it/ mo e:embers o+ a c$ass ec$are uner t#is isibi$it/ are accessib$e insie t#e c$ass 6in member +unctions o+ t#e c$ass) as %e$$ as b/ t#e CbJects o+ t#at c$ass 6in an/ non member +unction o+ t#e program, protot/pe  e+ine a+ter t#e c$ass ec$aration)! 1  priate isibi$it/ moe:embers o+ a c$ass ec$are uner t#is isibi$it/ are accessib$e on$/ insie t#e c$ass 6in member +unctions o+ t#e c$ass)! T#e/ can not be accesse outsie t#e c$ass! 1c$ass Examp$e7 int ri( pub$ic:oi Assign6)7 ri =15( priate member accessib$e on$/ insie c$ass( oi main6)7Examp$e E(E!Assign6 )( pub$ic member accessib$e b/ CbJectc) O?ec( Orien(e< Pr*gramming Bt emp#asis on obJectsBt +o$$o%s &ottom9>p approac# in program esign! 1Bts ?ata #iing +eature preents accienta$ c#ange in ata!Bts +eatures $ike ata encapsu$ation, po$/morp#ism, in#eritance are present! Pr*ce<ra Pr*gramming Bt emp#asis on oing t#ingsBt +o$$o%s Top9o%n approac# in program esign! resence o+ L$oba$ ariab$es increase c#anges o+ accienta$ c#ange in ata 1Meatures $ike encapsu$ation, po$/morp#ism, Bn#eritance are not aai$ab$e in t#is t/pe o+  programming!) i) o, since t#e constructor Retai$ #as been e+ine in priate section! ½.uggeste 'orrection: 'onstructor Retai$6) to be e+ine in pub$ic section o+ c$ass! ½ii) ' e r ea$ 9 R ice :155 G 2F 1e) 'onstructor A'onstructor A'onstructor &'onstructor '2'onstructor &'onstructor A?estructor A?estructor &?estructor '1?estructor &?estructor A?estructor A+) 'reating obJect 1  'reating obJect 2'reating obJect D1!F'reating obJect 4'reating obJect F?estro/ing obJect F?estro/ing obJect 4?estro/ing obJect D1!F?estro/ing obJect 2?estro/ing obJect 1g) i) o$/morp#ism6'onstructor Cer$oaing) 1ii) Test::Test6c#ar ;<, int )7 strcp/6 aper, )( 1arks = (iii) Test::Test6Test Nt)7 strcp/6 aper, t! aper)( 1arks = t!arks(i) Test T1( +or Munction 1 ½Test T26 O'omputer .cience0, 155)(+or Munction D½) ?estructor1i) Test TD=T2( or Test TD6T2)(1AnsD a) ariab$e x is not a static so it cannot be use in static member +unction prn6 ) 1 b) T#e main aantage o+ in$ine +unctions is t#at t#e/ sae on t#e oer#eas o+ a +unction ca$$ as t#e+unction is not inoke, rat#er its coe is rep$ace in t#e program! 1T#e maJor isaantage o+ in$ine +unctions is t#at %it# more +unction ca$$s, more memor/ is %aste as +or eer/ +unction ca$$, t#e same +unction coe is inserte in t#e program! Repeate occurrences o+ same +unction coe %aste memor/ space! 1c) ember +unctions #ae +u$$ access prii$ege to bot# t#e pub$ic an priate members o+ t#e c$ass %#i$e, in genera$, nonmember +unctions #ae access on$/ to t#e pub$ic members o+ t#e c$ass 1ember +unctions are e+ine %it#in t#e c$ass scope t#at is t#e/ are not isib$e t#e scope o+ c$ass!  onmember +unctions are a$so isib$e outsie t#e scope o+ c$ass! 1) c$ass Tour 7 c#ar T'oe;F<(int oo+Au$ts(int oo+Pis( 1int Pi$ometres(+$oat Tota$Mare( pub$ic:Tour6)7T'oe = O>880( oo+Au$ts = 5( oo+Pis = 5( 1Pi$ometres = 5(Tota$Mare = 5(oi AssignMare6 )7 i+6Pi$ometres=1555)Tota$Mare = oo+Au$ts*F55  oo+Pis*2F5(e$se i+6Pi$ometres=F55) 1Tota$Mare = oo+Au$ts*D55  oo+Pis*1F5(e$seTota$Mare = oo+Au$ts*255  oo+Pis*155(  oi EnterTour6 )7 cinT'oe(cinoo+Au$ts(cinoo+Pis( cinPi$ometres(AssignMare6 )( 1oi .#o%Tour6 )7 cout33T'oe33 O 033oo+Au$ts33 O 033oo+Pis33 O 033Pi$ometres(cout33Tota$Mare( 1(e) c$ass RE.CRT7 int Rno(c#ar ame;25<(+$oat '#arges( 1int ?a/s(+$oat 'C >TE6)( pub$ic:oi Letin+o6)(oi ?ispin+o6)((oi RE.CRT::Letin+o6)7 cinRno(gets6ame)( 1cin'#arges(cin?a/s(oi RE.CRT::?ispin+o6)7cout33Rno330 O33ame330 O33'#arges330 O33?a/s33 O 0( 1 cout33'C >TE6)33en$( ½+$oat RE.CRT::'C >TE6)7 +$oat Amount = '#arges*?a/s(i+6Amount11555) 1Amount = 1!52*?a/s*'#arges(return Amount( ½ Ans 4 a) Bn u$ti$ee$ in#eritance, a c$ass in#erits itQs properties +rom anot#er erie c$ass transitie$/! ½ A & ½ ' Bn /bri in#eritance, ½ A & ' ½ ?
View more...
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