Chapter 7

 < Day Day Up > 



Chapter 6

  1. What characters are used to begin and end compound statements?

    opening and closing braces { ... }

  2. 2.How does the if-else statement differ from the if statement?

    The if...else statement offers an alternative course of action in the event the expression evaluates to false.

  3. What control statement can be used in place of nested if-else statements?

    switch

  4. Why should a break statement be added to the end of each case of a switch statement?

    To prevent execution falling through to the next case statement.

  5. What is the purpose of a default case in a switch statement?

    To provide a default course of action should no previous case apply.

  6. What is the difference between a while and a do-while statement? When would you use a do-while instead of a while statement?

    A do...while executes the body at least once regardless of the value of the expression. Use a do...while when your have to execute the body of the statement at least once.

  7. Convert the following while statement to a for statement:

    int i = 0; while(i<10){    //do something    i++; }

    for(int i=0; i<10; i++){

    //do something

    }

  8. What will happen when the following code executes:

    int i = 0; while(i++ < 3){    cout<<"i = "<<i<<endl;    break; }

    The value of i is incremented to 1 and the string i = 1 is printed to the screen, then the break causes the while loop to terminate.

  9. What happens when the following code executes:

    int i = 0; while(i < 3){    cout<<"i = "<<i<<endl;    continue;    i++; } 

    The string i = 0 is repeatedly printed to the screen. The continue forces the while loop to repeat forever because i is never allowed to increment.

  10. True/False: Goto statements can be used to jump outside of functions.

    FALSE



 < Day Day Up > 



C++ for Artists. The Art, Philosophy, and Science of Object-Oriented Programming
C++ For Artists: The Art, Philosophy, And Science Of Object-Oriented Programming
ISBN: 1932504028
EAN: 2147483647
Year: 2003
Pages: 340
Authors: Rick Miller

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