
CSI3471
Exercise:Doorclass
Part1
DefineaDoorclassthatcontainsasingleBooleanvariablecalledstatusthatindicateswhetherornot
theDoorisopen.(YoucanassumethattheDooriseitheropenorclosed.)
Definethefollowingfunctions:
• Nullconstructor,whichsetsstatustofalse
• AconstructorthatacceptsasingleBooleanparameter,aStatus,thatindicateswhetherthenew
Dooriseitheropenornot
• Afunctionthatopensthedoor,calledopen
• Afunctionthatclosesthedoor,calledclose
• ABooleanfunctionthatindicateswhethertheDoorisopenornot
Part2
DefineaclasscalledMyMainthatcontainsamainfunction.(Thisfunctionwillbethe“top‐level”
functionintheproject.Themainfunctionservesessentiallythesamepurposeasamainfunctionina
C++program.)
Defineastaticvoidfunctioncalledtest1withinMyMainthat
1. Createsadoorthatisinitiallyopen
2. Closesthedoor
3. Printsthestatusofthedoor
4. Opensthedoor
5. Printsthestatusofthedoor
Part3
CreateasecondclasscalledDoor2thatisidenticaltoDoorexceptthateachDoorthatiscreatedhasan
ID.(WewillassumethateachDoorinacollectionofDoorshasauniqueID.)Thatmeansthatboth
constructorsshouldhavean“IDparameter”.
AddaBooleanfunctioncalledgetIDthatreturnsthevalueoftheDoor’sID
Part4
ModifyMyMainbyaddinganotherstaticvoidfunctioncalledtest2that“teststhenewfunctionsthat
youhaveaddedtotheDoorclass.