SY_BCS_CPP







1.DefineaclassMessagewithtwodatamembersonecharacterpointerandanintegerstoringlength.Implementfollowingfunctions: a) DefaultconstructorandParameterizedconstructor [2+3] b) Overloadbinary+operatortorepresentconcatenationofmessages [7] c) Overload[]operatortoreturnacharacterataspecificposition [8] d) Overload=operatortocopyoneMessageobjecttoanother. [5]Writeamainfunctionthatusestheaboveclassanditsmemberfunctions. [5]

2. Implementaclass“data”tooverloadfollowingfunctionsasfollows: a) intmaximum(int,int)–returnsthemaximumbetweenthetwointegerarguments [2] b) intmaximum(int*a,intarraylength)–returnsthemaximumintegerfromanarray'a' [5] c) voidmaximum(int*a,intarrarylength,intn)–displayallelementsfromthearray'a'whicharegreaterthangivennumber'n'. [5] d) intminimum(int,int)–returnstheminimumbetweenthetwointegerarguments [2] e) intminimum(int*,intarraylength)–returnstheminimumintegerfromanarray'a' [5] f) voidminimum(int*a,intarrarylength,intn)–displayallelementsfromthearray'a'which aresmallerthangivennumber„n‟. [5] Writeamainfunctionthatusestheaboveclassanditsmemberfunctions. [6]

3. Implementaclass"printdata”tooverload"print"functionasfollows: a) voidprint(int)-outputsvalue-,thatis,valuefollowedbythevalueofthe integer.eg.print(10)outputvalue-<10> [5] b) voidprint(int,int)–outputsvalue–[,],thatis,valuefollowedbythetwointegersseparatedbycommainsquarebrackets. [5] egprint(4,6)outputvalue-[<4>,<6>] c) voidprint(char*)–outputsvalue–“char*”,thatis,valuefollowedbythestringindoublequotes.egprint(“hi”)outputvalue-“hi” [5] d) voidprint(intn,char*)-displayfirstncharactersfromthegivenstring.egprint(3,”Object”)-output–“Obj” [5] e) voidprint(charch,char*)-countoccurrencesofacharacterfromthegivenstring.egprint("P",”CPPProgramming”)-output–3 [5] Writeamainfunctionthatusestheaboveclassanditsmemberfunctions. [5]

4. Implementthefollowingclasshierarchy:Student:id,name, StudentExam(derivedfromStudent):withnsubjects(ncanbevariable)StudentResult(derivedfromStudentExam):withpercentage,grade Defineaparameterizedconstructorforeachclassandappropriatefunctionstoacceptanddisplaydetails.CreatenobjectsoftheStudentResultclassanddisplaythemarklistusingsuitablemanipulators. a) Parameterizedconstructor,acceptanddisplayforeachclass-eachfunctioncarries2marks [18] b) DisplaymarklistwithUseofmanipulators [7] Writemainfunctionthatusestheaboveclassanditsmemberfunctions. [5]

5. DefineaclassnamedClockwiththreeintegerdatamembers forhours,minutesandseconds.Defineparameterizedanddefaultconstructors.Overloadincrementanddecrementoperatorsappropriately.Overloadextractionandinsertionoperators. a) DefaultconstructorandParameterizedconstructor[2+3] b) Overloadingofeachoperatorcarries5marks[20] Writeamainfunctionthatusestheaboveclassanditsmemberfunctions.[5]

6. DefineaclassnamedComplexforrepresentingcomplexnumbers.Acomplexnumberhasthegeneralforma+ib,wherea-therealpart,b-theimaginarypartarebothrealnumbersandi2=-1.Defineparameterizedanddefaultconstructor.Overload+,-and*operatorswithusualmeaning. a) Defaultconstructor&Parameterizedconstructor-eachcarries3marks [6] b) Overloadingof+operator&-operator-eachcarries5marks [10] c) Overloadingof*operator [9] Write amainfunctionthatusestheaboveclassanditsmemberfunctions. [5]

7. Giventhefollowinginheritancehierarchy,implementeachoftheclasses. Thepersonclasshasparameterizedconstructor,acceptanddisplayfunctions.Theemployeeidisautogeneratedfromthelastallottedvaluestoredinemployeeclass.Writeconstructors,acceptanddisplayfunctionsforderivedclasses.Definememberfunctioncomputepayforemployeeandoverrideappropriatelyinderivedclass.Write mainprogramtoillustrateuseoftheclasses a) Parameterizedconstructor,acceptanddisplayforeachclasscarries-(2+1+1)marks [16] b) Computepay()foremployee [1] c) Overridingofcomputepay()inderivedclasses-functionineachclasscarries4marks [8]Writeamainfunctionthatusestheaboveclassanditsmemberfunctions. [5]

8. Implementthefollowingclasshierarchy Defineconstructorsandappropriatefunctionstomacceptanddisplaydetails.Parameterizedconstructor,acceptanddisplayforeachclasscarries-(2+2+2)marks[24]Writemainfunctiontoacceptdetailsof"n"Teaching-Assistantsanddisplaythedetails. [6]

9. Write thedefinitionforaclasscalled"time"thathashours,minutes&secondsasintegerdatamembers.Consider24hrformat.Theclasshasthefollowingmemberfunctions: a) voidsettime(int,int,int)tosetthespecifiedvaluesofhours,minutesandsecondsinobject.[5] b) voidshowtime()todisplaycontentsoftimeobject.[5] c) timeadd(time)addthecorrespondingvaluesofhours,minutesandseconds(<60 a="" amainprogramtoillustratetheuseofaboveclassandmemberfunction.="" d="" intimeobjectargumenttocurrenttimeobjectandmakeappropriateconversionsandreturntime.="" minutesandsecondsintimeobjectargumentfromcurrenttimeobjectaftermakingappropriateconversionsandreturntimedifference.="" subtractvaluesofhours="" time="" timediff="" write=""> 

10. WritethedefinitionforaclasscalledRectanglethathasfloatingpointdataMemberslengthandwidth.Theclasshasthefollowingmemberfunctions: a) voidsetlength(float)tosetthelengthofdatamember [2] b) voidsetwidth(float)tosetthewidthofdatamember [2] c) floatperimeter()tocalculateandreturntheperimeteroftherectangle [2] d) floatarea()tocalculateandreturntheareaoftherectangle [2] e) voidshow()todisplaythelengthandwidthoftherectangle [2] f) Overloadcompare()to comparetworectanglesbylengthandwidth [7] comparetworectanglesbyarea [8] Writemainfunctiontocreatetworectangleobjectsanddisplayeachrectangleanditsareaandperimeter. [5]

11. Implementaclass"invertdata"tooverload"invert"functionasfollows: a) intinvert(int)-returnstheinverted integer.Eg.invert(5438)willreturn8345 [10] b) char*invert(char*)–returnsthereversedstring–reverse(“comp”)willreturn”pmoc” [8] c) voidinvert( int*)–willreverse thearray order–Anarray[5,7,12,4]willbeinvertedto[4,12,7,5]. [7] Write amainfunctionthatusestheaboveclassanditsmemberfunctions. [5]

 12. Writethedefinitionforaclasscalled“cuboidSolid”thathaslength,breadth,heightandmasshasfloatdatamembers.Theclasshasthefollowingmemberfunctions. a) Accept()andDisplay()functions–eachcarries5marks [10] b) floatgetVolume()thatreturnsthevolumeofthemetal [5] c) floatgetSurfaceArea()thatreturnsthesurfacearea [5] d) floatgetDensity()thatreturnsthedensity [5] Writeamainprogramtoillustratetheuseofaboveclassandmemberfunction. [5]

13. Defineaclass"Fraction"havingintegerdatamembersnumeratoranddenominator.Defineparameterizedanddefaultconstructors(defaultvalues0and1).Parameterizedconstructorshouldstorethefractioninreducedformafterdividingbothnumeratoranddenominatorbygcd(greatestcommondivisor).Writeaprivatefunctionmembertocomputegcdoftwointegers.Writefourmemberfunctionsforaddition,subtraction.multiplicationanddivisionoffractionobjects.Eachfunctionwillhavetwofractionobjectsasarguments. a) gcd()function [3] b) DefaultconstructorandParameterizedconstructor [1+4=5] c) Addition,SubtractionandDivisionfunction-eachcarries5marks [15] d) Multiplication()function [2] Write themainfunctiontoillustratetheuseoftheclassandmemberfunction. [5]

14. Implementaclassvectorwhichcontainsintegersinsortedorder.Thesizeofthevectorvariessothememoryshouldbedynamicallyallocated.Itshouldhavethreedatamembersvectorarray–apointertointeger, maxsize–themaximumallocatedsizetotakecareofinsertionsandsize–actualsize.Writememberfunctionfor: a) Parameterizedconstructor&copyconstructor-eachcarries5marks. [10] b) getvalueataparticularpositioninvector [3] c) insertvalues invectortokeepitinsortedorder [5] d) printthevector [2] e) Implementthememberfunctionstoformunionoftwovectors. [5]Write themainfunctiontoillustratetheuseoftheclassandmemberfunction. [5]

4 comments:

  1. 6_2 is not available... please!upload it...m waiting

    ReplyDelete
  2. This comment has been removed by the author.

    ReplyDelete
  3. plz Post Inheritance program...
    S.Y.B.Sc( C.S )
    Assignment NO : 15 Set A

    ReplyDelete