SHARE
SPREAD
HELP

The Tradition of Sharing

Help your friends and juniors by posting answers to the questions that you know. Also post questions that are not available.


To start with, Sr2Jr’s first step is to reduce the expenses related to education. To achieve this goal Sr2Jr organized the textbook’s question and answers. Sr2Jr is community based and need your support to fill the question and answers. The question and answers posted will be available free of cost to all.

 

#
Authors:
Walter Savitch ,julia Lobur
Chapter:
Defining Classes
Exercise:
Programming Projects
Question:9 | ISBN:9780321531346 | Edition: 7

Question

My mother always took a little red counter to the grocery store. The

counter was used to keep tally of the amount of money she would have

spent so far on that visit to the store, if she bought all the items in her basket.

There was a four-digit display, increment buttons for each digit, and a

reset button. There was an overflow indicator that came up red if more

money was entered than the $99.99 it would register. (This was a long

time ago.)

Write and implement the member functions of a class Counter that

simulates and slightly generalizes the behavior of this grocery store

counter. The constructor should create a Counter object that can count up

to the constructor’s argument. That is, Counter(9999) should provide a

counter that can count up to 9999. A newly constructed counter displays a reading of 0. The member function void reset( ); sets the counter’s

number to 0. The member functions void incr1( ); increments the units

digit by 1, void incr10( ); increments the tens digit by 1, and void

incr100( ); and void incr1000( ); increment the next two digits,

respectively. Accounting for any carry when you increment should require

no further action than adding an appropriate number to the private data

member. A member function bool overflow( ); detects overflow.

(Overflow is the result of incrementing the counter’s private data member

beyond the maximum entered at counter construction.)

Use this class to provide a simulation of my mother’s little red clicker.

Even though the display is an integer, in the simulation, the rightmost

(lower-order) two digits are always thought of as cents, and tens of cents,

the next digit is dollars, and the fourth digit is tens of dollars.

Provide keys for cents, dimes, dollars, and tens of dollars. Unfortunately,

no choice of keys seems particularly mnemonic. One choice is to use the

keys asdfo: a for cents, followed by a digit 1 to 9; s for dimes, followed by

digits 1 to 9; d for dollars, followed by a digit 1 to 9; and f for tens of

dollars, again followed by a digit 1 to 9. Each entry (one of asdf followed

by 1 to 9) is followed by pressing the Return key. Any overflow is reported after each operation. Overflow can be requested by pressing the o key.

TextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbook

Sorry the answer is not available at the moment…

If you are able to find the answer, please make sure to post it here. So that your Juniors have smile on their lips and feel happy.

Spread the 'tradition of sharing'.