Docsity

CSI 3471 Door Class Exercise Solution - Prof. Paul C. Grabow, Assignments of Software Engineering

Toggle sidebar
bg1
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. Printsthestatusofthedoor
Part3
CreateasecondclasscalledDoor2thatisidenticaltoDoorexceptthateachDoorthatiscreatedhasan
ID.(WewillassumethateachDoorinacollectionofDoorshasauniqueID.)Thatmeansthatboth
constructorsshouldhavean“IDparameter”.
AddaBooleanfunctioncalledgetIDthatreturnsthevalueoftheDoor’sID
Part4
ModifyMyMainbyaddinganotherstaticvoidfunctioncalledtest2that“teststhenewfunctionsthat
youhaveaddedtotheDoorclass.

Partial preview of the text

Download CSI 3471 Door Class Exercise Solution - Prof. Paul C. Grabow and more Assignments Software Engineering in PDF only on Docsity!

CSI 3471

Exercise: Door class Part 1 Define a Door class that contains a single Boolean variable called status that indicates whether or not the Door is open. (You can assume that the Door is either open or closed.) Define the following functions:

  • Null constructor, which sets status to false
  • A constructor that accepts a single Boolean parameter, aStatus, that indicates whether the new Door is either open or not
  • A function that opens the door, called open
  • A function that closes the door, called close
  • A Boolean function that indicates whether the Door is open or not Part 2 Define a class called MyMain that contains a main function. (This function will be the “top‐level” function in the project. The main function serves essentially the same purpose as a main function in a C++ program.) Define a static void function called test1 within MyMain that
  1. Creates a door that is initially open
  2. Closes the door
  3. Prints the status of the door
  4. Opens the door
  5. Prints the status of the door Part 3 Create a second class called Door2 that is identical to Door except that each Door that is created has an ID. (We will assume that each Door in a collection of Doors has a unique ID.) That means that both constructors should have an “ID parameter”. Add a Boolean function called getID that returns the value of the Door’s ID Part 4 Modify MyMain by adding another static void function called test2 that “tests the new functions that you have added to the Door class.