Sams Teach Yourself C++ in 21 Days

(singke) #1

  1. Class declarations must end with a semicolon.

  2. The accessor GetAge()is private. Remember: All class members are private unless
    you say otherwise.

  3. You can’t access itsStationdirectly. It is private.
    You can’t call SetStation()on the class. You can call SetStation()only on
    objects.
    You can’t initialize myOtherTVbecause there is no matching constructor.


Day 7....................................................................................................................


Quiz ................................................................................................................


  1. Separate the initializations with commas, such as
    for (x = 0, y = 10; x < 100; x++, y++).
    2.gotojumps in any direction to any arbitrary line of code. This makes for source
    code that is difficult to understand and, therefore, difficult to maintain.

  2. Yes, if the condition is false after the initialization, the body of the forloop will
    never execute. Here’s an example:
    for (int x = 100; x < 100; x++)

  3. The variable xis out of scope; thus, it has no valid value.

  4. Yes. Any loop can be nested within any other loop.

  5. Yes. Following are examples for both a forloop and a whileloop:
    for(;;)
    {
    // This for loop never ends!
    }
    while(true)
    {
    // This while loop never ends!
    }

  6. Your program appears to “hang” because it never quits running. This causes you to
    have to reboot the computer or to use advanced features of your operating system
    to end the task.


Exercises ........................................................................................................


  1. The following is one possible answer:
    for (int i = 0; i< 10; i++)
    {
    for ( int j = 0; j< 10; j++)


832 Appendix D

32 0672327112_app_d.qxd 11/19/04 12:30 PM Page 832

Free download pdf