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
 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

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
 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

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.

Introduction to Computers, the Internet and World Wide Web

Introduction to C++ Programming

Introduction to Classes and Objects

Control Statements: Part 1

Control Statements: Part 2

Functions and an Introduction to Recursion

Arrays and Vectors

Pointers and Pointer-Based Strings

Classes: A Deeper Look, Part 1

Classes: A Deeper Look, Part 2

Operator Overloading; String and Array Objects

Object-Oriented Programming: Inheritance

Object-Oriented Programming: Polymorphism

Templates

Stream Input/Output

Exception Handling

File Processing

Class string and String Stream Processing

Web Programming

Searching and Sorting

Data Structures

Bits, Characters, C-Strings and structs

Standard Template Library (STL)

Other Topics

Appendix A. Operator Precedence and Associativity Chart

Appendix B. ASCII Character Set

Appendix C. Fundamental Types

Appendix D. Number Systems

Appendix E. C Legacy Code Topics

Appendix F. Preprocessor

Appendix G. ATM Case Study Code

Appendix H. UML 2: Additional Diagram Types

Appendix I. C++ Internet and Web Resources

Appendix J. Introduction to XHTML

Appendix K. XHTML Special Characters

Appendix L. Using the Visual Studio .NET Debugger

Appendix M. Using the GNU C++ Debugger

Bibliography



C++ How to Program
C++ How to Program (5th Edition)
ISBN: 0131857576
EAN: 2147483647
Year: 2004
Pages: 627

Flylib.com © 2008-2020.
If you may any questions please contact us: flylib@qtcs.net