5/24/09

General Questions & Code related questions


  1. What is whitespace? 

  2. What is meant by freeform? 

  3. What does it mean to maintain programs? 

  4. What does C++ prefer most, uppercase or lowercase letters in programs? 

  5. What are comments? 

  6. Why are comments necessary? 

  7. What does the compiler do when it sees a comment? 

  8. What do all C++ comments begin with? 

  9. What is the difference between a C-style comment and a C++-style comment? 

  10. What happens when you nest C-style comments? 

  11. True or false: Longer programs are more difficult to understand than shorter ones. 

  12. True or false: You can substitute parentheses for braces if you feel that the parentheses are more readable. 

  13. True or false: Comments are not Visual C++ commands. 

  14. True or false: You can nest one C++ comment inside another. 

  15. Match the special character on the left with that special character's description on the right. 

    Special CharacterDescription
    [Backslash
    <Left bracket
    }Right-angled bracket
    |Right parenthesis
    \Forward slash (or just slash)
    ]Left-angled bracket
    {Left parenthesis
    )Right brace
    (Vertical line
    >Left brace
    /Right bracket


    There is no What's the Output? section in this unit. 


    Find the Bug


  16. Here is a comment and a C++ command (the return statement). Where is the problem? 


    // Go back to the IDE     return;

  17. The following program contains three comment bugs. See whether you can determine what is wrong. 

    // This program computes taxes  #include   void main()  {    The next few lines calculate payroll taxes    // Computes the gross pay   float gross = 40 * 5.25;    float taxes = gross * .40;   / Just computed the taxes    cout "The taxes are " <<>

    Write Code That. . .


  18. Tim Peterson wants to put his name at the top of his program using a comment. Write a comment that contains Tim's name using both the C++-style and the C-style approach. 

  19. Here is the same program you saw earlier, with one difference: The programmer forgot to precede the comments with double slashes. After trying to compile the program, the programmer looked at the 20 or so error messages and realized what was left out. See if you can help the programmer correct the program by inserting the proper commenting symbols everywhere they go. 

    Filename: 1STLONG.CPP  Longer C++ program that demonstrates comments,  variables, constants, and simple input/output  #include   void main()    {      int i, j;       These three lines declare four variables      char c;      float x;      i = 4;          i is assigned an integer literal      j = i + 7;      j is assigned the result of a computation      c = 'A';        Enclose all character literals                      in single quotation marks      x = 9.087;      x is a floating-point value      x = x * 12.3;   Overwrites what was in x with something else     Sends the values of the four variables to the screen      cout <<>

  20. Hint: Count the number of double slashes you put in this program. If you did not add 18 double slashes (or if you added more than 18), try again. 

    Extra Credit


  21. Of the following five lines, which contain useful comments and which contain redundant ones? 

      clog << '\n';                  // Sends an end-of-line to the error log  radius3 = radius1 + radius2;   // Calculates radius3                                 // The following code contains a C++ program                                 // The following code tracks your investments  clog << '\n';                  // Sends '\n' to clog

No comments: