23.4.2. Class Screen

Class Screen (Figs. 23.1623.17) represents the screen of the ATM and encapsulates all aspects of displaying output to the user. Class Screen approximates a real ATM’s screen with a computer monitor and outputs text messages using cout and the stream insertion operator (<<). In this case study, we designed class Screen to have one operation—displayMessage. For greater flexibility in displaying messages to the Screen, we now declare three Screen member functions—displayMessage, displayMessageLine and displayDollarAmount. The prototypes for these member functions appear in lines 12–14 of Fig. 23.16.

Screen Class Member-Function Definitions

Figure 23.17 contains the member-function definitions for class Screen. Line 5 #includes the Screen class definition. Member function displayMessage (lines 9–12) takes a string as an argument and prints it to the console using cout and the stream insertion operator (<<). The cursor stays on the same line, making this member function appropriate for displaying prompts to the user. Member function displayMessageLine (lines 15–18) also prints a string, but outputs a newline to move the cursor to the next line. Finally, member function displayDollarAmount (lines 21–24) outputs a properly formatted dollar amount (e.g., $123.45). Line 23 uses stream manipulators fixed and setprecision to output a value formatted with two decimal places.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.143.218.146