[Page 1297 (continued)]|
G.6. Class DepositSlot
Class DepositSlot (Figs. G.9G.10) represents the deposit slot of the ATM. Like the version of class CashDispenser presented here, this version of class DepositSlot merely simulates the functionality of a real hardware deposit slot. DepositSlot has no data members and only one member functionisEnvelopeReceived (declared in line 9 of Fig. G.9 and defined in lines 710 of Fig. G.10)that indicates whether a deposit envelope was received.
Figure G.9. DepositSlot class definition.
1 // DepositSlot.h
2 // DepositSlot class definition. Represents the ATM's deposit slot.
3 #ifndef DEPOSIT_SLOT_H
4 #define DEPOSIT_SLOT_H
6 class DepositSlot
9 bool isEnvelopeReceived() const; // tells whether envelope was received
10 }; // end class DepositSlot
12 #endif // DEPOSIT_SLOT_H
Figure G.10. DepositSlot class member-function definition.
1 // DepositSlot.cpp
2 // Member-function definition for class DepositSlot.
3 #include "DepositSlot.h" // DepositSlot class definiton
5 // indicates whether envelope was received (always returns true,
6 // because this is only a software simulation of a real deposit slot)
7 bool DepositSlot::isEnvelopeReceived() const
9 return true; // deposit envelope was received
10 } // end function isEnvelopeReceived
Recall from the requirements document that the ATM allows the user up to two minutes to insert an envelope. The current version of member function isEnvelopeReceived simply returns true immediately (line 9 of Fig. G.10), because this is only a software simulation, and we assume that the user has inserted an envelope within the required time frame. If an actual hardware deposit slot were connected to our system, member function isEnvelopeReceived might be implemented to wait for a maximum of two minutes to receive a signal from the hardware deposit slot indicating that the user has indeed inserted a deposit envelope. If isEnvelopeReceived were to receive such a signal within two minutes, the member function would return TRue. If two minutes elapsed and the member function still had not received a signal, then the member function would return false.