Just as a header file provides clues as to how a class can be used, but doesn't show how it's implemented, the buttons/dials on a stereo provide clues as to how to use the stereo, but not how it's put together. The header file does give away some information since the private section is visible to the user/client even though the variables cannot be accessed. A see-through stereo might be similar: users could see the circuit-boards and so on, but not access or touch them except via the dials/buttons of the stero.
NumSides() provides access to the
value of the data. The line
will not compile (accept in the implementation file dice.cpp). Instead the access functionDice::NumSides() is used.
myRollCount++ can be used
in place of myRollCount = myRollCount+1.
The function Dice::Roll would change as follows:
The statement
If the value of num in main is initialized to 3, the value printed will be 10 (first 2 is added to num making it 5, then this value is multiplied by 2).
This is the start, this is the end --- nothing is in betweenwill indicate 7 words have been read. The words are "This", "is", "the", "start," , "this", "is", "the".
The value of 20/static_cast<double>(6) is 3.3333 since the
cast converts the 6 to 6.0 and double arithmetic is used.
If the statement below is used, the average is not correctly printed (note: typo in book).