C++ Chapter 3: Using Boolean Expressions

Card Set Information

Author:
senator77
ID:
133738
Filename:
C++ Chapter 3: Using Boolean Expressions
Updated:
2012-02-08 13:20:36
Tags:
boolean expressions if else switch while loops designing
Folders:

Description:
C++ Chapter 3: Using Boolean Expressions
Show Answers:

Home > Flashcards > Print Preview

The flashcards below were created by user senator77 on FreezingBlue Flashcards. What would you like to do?


  1. The order in which the statements in your program are performed is called:
    flow of control
  2. The C++ type bool provides you the ability to declare variables that can carry the values:
    true and false
  3. An enumeration type is a type whose values are defined by a list of constants of type:
    int
  4. Any programming construct that chooses one from a number of alternative actions is called a:
    branching mechanism
  5. The compiler always pairs an else with the nearest previous if that is not already paired with some else.
  6. Another kind of C++ statement that also implements multiway branches is called a:
    switch statement
  7. The choice of which branch to execute is determined by a controlling expression given in parentheses after the keyword switch.
  8. The controlling expression for a switch statement must always return either a bool value, an enum constant, one of the integer types, or a character.
  9. A variable that exists only within the compound statement in which they are declared are called:
    local variables.
  10. A program construction that repeats a statement or sequence of statements a number of times is called a:
    loop.
  11. When a while statement is executed, the Boolean expression is checked before the loop body is executed.
  12. With a do-while statement, the body of the loop is executed first and the Boolean expression is checked after the loop body is executed.
  13. If the ++ is before the variable, then the incrementing is done before the value is returned (++number).
  14. If the ++ is after the variable, then the incrementing is done after the value is returned (number++).
  15. You cannot apply the increment and decrement operators to anything other than a single variable (i.e. (x+y)++, --(x+y), 5++).
  16. A for statement begins with the keyword for followed by 3 things in parentheses that tell the computer what to do with the controlling variable:
    for (initialization_action; boolean_expression; update_action)

    or

    for (n = 1; n <= 10; n++)
  17. When designing a loop, you need to design 3 things:
    1. The body of the loop.
    2. The initializing statements.
    3. The conditions for ending the loop
  18. The break statement can be used to exit a loop statement.
  19. There are 4 commonly used methods for terminating an input loop.
    1. List headed by size
    2. Ask before iterating
    3. List ended with a sentinal value
    4. Running out of input
  20. A sentinal value is one that is somehow distinct from all the possible values on the list being read in and so can be sued to signal the end of the list.
  21. A count-controlled loop is any loop that determines the number of iterations before the loop begins and then iterates the loop body that many times.
  22. A variable that changes value to indicate that some event has taken place is often called a:
    flag.
  23. Loops that iterate one too many times or one too few times are said to have an:
    off-by-one error.
  24. Watching the value of a variable change while the program is running is called:
    tracing the variable.
  25. Boolean expressions are evaluated similarly to the way arithmetic expression are evaluated.
  26. Most modern compilers have a bool type having the values true and false.
  27. You can write a function so that is returns a value of true or false. A call to such a function can be used as a Boolean expression in an if-else statement or anywhere else that a Boolean expression is permitted.
  28. One approach to solving a task or subtask is to write down conditions and corresponding actions that need to be taken under each condition. This can be implemented in C++ as a multiway if-else statement.
  29. A switch statement is a good way to implement a menu for the user of your program.
  30. A block is a compound statement that contains variable declarations. The variables declared in a block are local to the block. Among other uses, blocks can be used for the action in one branch of a multiway branch statement, such as a multiway if-else statement.
  31. A for loop can be used to obtain the equivalent of the instruction "repeat the loop body n times".
  32. Its usually best to design loops in pseudocode that does not specify a choice of C++ looping mechanism. Once the algorithm has been designed, the choice of which C++ loop statement to use is usually clear.
  33. One way to simplify your reasoning about nested loops is to make the loop body a function call.
  34. Always check loops to be sure that the variables used by the loop are properly initialized before the loop begins.
  35. Always check loops to be certain they are not iterated one too many or one to few times.
  36. When debugging loops, it helps to trace key variables in the loop body.
  37. If a program or algorithm is very difficult to understand or performs very poorly, do not try to fix it, throw it away and start over.

What would you like to do?

Home > Flashcards > Print Preview