Class DepositSlot
(Figs. 23.22–23.23) 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 function—isEnvelopeReceived
(declared in line 9 of Fig. 23.22 and defined in lines 7–10 of Fig. 23.23)—that indicates whether a deposit envelope was received.
1 // DepositSlot.h
2 // DepositSlot class definition. Represents the ATM's deposit slot.
3 #ifndef DEPOSIT_SLOT_H
4 #define DEPOSIT_SLOT_H
5
6 class DepositSlot
7 {
8 public:
9 bool isEnvelopeReceived() const; // tells whether envelope was received
10 }; // end class DepositSlot
11
12 #endif // DEPOSIT_SLOT_H
Fig. 23.22. DepositSlot class definition.
1 // DepositSlot.cpp
2 // Member-function definition for class DepositSlot.
3 #include "DepositSlot.h" // DepositSlot class definiton
4
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
8 {
9 return true; // deposit envelope was received
10 } // end function isEnvelopeReceived
Fig. 23.23. DepositSlot class member-function definition.
Recall from the requirements specification 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. 23.23), 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
.
3.147.205.57