0% found this document useful (0 votes)
150 views5 pages

C++ Class and Object Concepts Quiz

A class describes a data type, while an instance of a class is an object that exists in memory. A mutator/setter function stores a value in a private member variable or changes an attribute, while an accessor function retrieves the value of a private member variable. It is not possible to have more than one default constructor. Classes are identified by finding nouns in a problem domain description. C++ uses classes to create objects. Member variables of a class are private by default for protection. It is possible to have multiple constructors but only one destructor. Object-oriented programming and procedural programming are two common programming methods. Defining a class object is called instantiation.

Uploaded by

Ali Nasir
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
150 views5 pages

C++ Class and Object Concepts Quiz

A class describes a data type, while an instance of a class is an object that exists in memory. A mutator/setter function stores a value in a private member variable or changes an attribute, while an accessor function retrieves the value of a private member variable. It is not possible to have more than one default constructor. Classes are identified by finding nouns in a problem domain description. C++ uses classes to create objects. Member variables of a class are private by default for protection. It is possible to have multiple constructors but only one destructor. Object-oriented programming and procedural programming are two common programming methods. Defining a class object is called instantiation.

Uploaded by

Ali Nasir
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

eQuizShow

COMSC200Ch13Part1
ch13part1

Question:Whatisthedifferencebetweenaclassandaninstanceoftheclass?

Answer:

Aclassdescribesadatatype.Aninstanceofaclassisanobjectofthedatatypethatexistsinmemory.

Question:Whatisamutator/setterfunction?Whatisanaccessorfunction?

Answer:Amutator/setterisamemberfunctionthatstoresavalueinaprivatemembervariable,orinsomewaychanges
anattribute.Anaccessorisamemberfunctionthatretrievesthevaluestoredinaprivatemembervariable.

Question:Whatisadefaultconstructor?Isitpossibletohavemorethanonedefault
constructor?
Answer:

Adefaultconstructorisaconstructorthatiscalledwithoutanyarguments.Itisnotpossibletohavemorethanonedefault
constructor.

Question:Howdoyouidentifytheclassesinaproblemdomaindescription?
Answer:

Identifyallthenouns(includingpronounsandnounphrases)intheproblemdomaindescription.Eachoftheseisa
potentialclass.Then,refinethelisttoincludeonlytheclassesthatarerelevanttotheproblem.

Question:InC++theistheconstructprimarilyusedtocreateobjects.
Answer:class

ch13part1

Question:
Whatisthedifferencebetweenthefollowing Person structureand Person class?

structPerson{stringnameintage}classPerson{stringnameintage}

Answer:

Allmembersofastructarepublicbydefault.Themembersofaclass,however,areprivateprivatebydefault.

Question:Isitagoodideatomakemembervariablesprivate?Whyorwhynot?
Answer:

Yesitis.Thisprotectsthevariablesfrombeingdirectlymanipulatedbycodeoutsidetheclass,andpreventsthemfrom
receivinginvaliddata.

Question:Isitpossibletohavemorethanoneconstructor?Isitpossibletohavemore
thanonedestructor?
Answer:

Yes,itispossibletohavemorethanoneconstructor.Itisnotpossibletohavemorethanonedestructor.

Question:Thetwocommonprogrammingmethodsinpracticetodayareand
.
Answer:proceduralprogramming,objectorientedprogramming

Question:Definingaclassobjectisoftencalledtheofaclass.
Answer:instantiation

ch13part1

Question:Whatisthedefaultaccessspecificationofclassmembers?
Answer:private

Question:Canyouthinkofagoodreasontoavoidwritingstatementsinaclassmember
functionthatuse cout or cin ?
Answer:

UnlessaclassisspecificallydesignedtoperformI/O,operationslikeuserinputandoutputarebestlefttotheperson
designingtheapplication.Classesshouldprovidememberfunctionsforretrievinganyimportantdatawithout
displayingthemonthescreen.Likewise,theyshouldprovidememberfunctionsthatstoredataintoprivate
membervariableswithoutusingcin.Thisallowsaprogrammertousetheclasswithoutbeinglockedinto
aparticularmethodofperformingI/O.

Question:Ifaclassobjectisdynamicallyallocatedinmemory,doesitsconstructor
execute?Ifso,when?
Answer:

Yes,theconstructorexecuteswhentheobjectiscreated.

Question:programmingiscenteredaroundfunctionsorprocedures
Answer:procedural

Question:Membersofaclassobjectmaybeaccessedthroughapointertotheobject
byusingtheoperator.
Answer:>

ch13part1

Question:
Lookatthefollowingfunctionheaderforamemberfunction.

voidCircle::getRadius()

Whatisthenameofthefunction?
Whatclassisthefunctionamemberof?

Answer:

Thefunction'snameisgetRadius.ItisamemberoftheCircleclass.
Question:Underwhatcircumstancesshouldamemberfunctionbeprivate?
Answer:

Whenthefunctionisnecessaryforinternalprocessing,butnotusefultotheprogramoutsidetheclass.Insomecasesa
classmaycontainmemberfunctionsthatinitializemembervariablesordestroytheircontents.Thosefunctions
shouldnotbeaccessiblebyanexternalpartofprogrambecausetheymaybecalledatthewrongtime.

Question:Whendefininganarrayofclassobjects,howdoyoupassargumentstothe
constructorforeachobjectinthearray?
Answer:Youspecifytheargumentsforeachobjectindividuallyinaninitializationlist.

Question:programmingiscenteredaroundobjects.
Answer:objectoriented

Question:Ifyouwerewritingthedeclarationofaclassnamed Canine ,whatwouldyou


namethefileitwasstoredin?
Answer:canine.h

ch13part1

Question:Acontractorusesablueprinttobuildasetofidenticalhouses.Areclasses
analogoustotheblueprintorthehouses?
Answer:Aclassisanalogoustotheblueprint.

Question:Whatisaconstructor?Whatisadestructor?
Answer:

Aconstructorisamemberfunctionthatisautomaticallycalledwhenaclassobjectiscreated.Adestructorisamember
functionthatisautomaticallycalledwhenaclassobjectisdestroyed.

Question:Whatareaclasssresponsibilities?
Answer:

Aclass'sresponsibilitiesarethethingsthattheclassisresponsibleforknowingandtheactionsthattheclassisresponsible
fordoing.

Question:isanobjectsabilitytocontainandmanipulateitsowndata.
Answer:encapsulation
Question:Ifyouwerewritingtheexternaldefinitionsofthe Canine classsmember
functions,youwouldsavetheminafilenamed
Answer:canine.cpp

You might also like