5/24/09

VC++ Questions

  1. What preprocessor directive do C++ programmers almost always use to include header files? 

  2. What are the characters that enclose a Visual C++ block? 

  3. What kind of data must be enclosed in single quotation marks? 

  4. What kind of data must be enclosed in double quotation marks? 

  5. What sends output to the screen in Visual C++? 

  6. What kind of numeric data contains no decimal points? 

  7. What kind of numeric data contains decimal points? 

  8. Write the four arithmetic symbols. 

  9. Is return ever optional? If so, why is it a good idea to learn to always use return? 

  10. What are the literals in Listing 4.1? Hint: There are eight if you count the ones embedded in the cout statement. 

  11. Which of the following are variables and which are literals? Hint: A variable name cannot have quotation marks around it. If it did, Visual C++ would think it was a character literal (if single quotations were used) or a string literal (if double quotation marks were used). 

      '1.2'  Payroll  4543.23  name  47  "Diane"

  • True or false: cout is a Visual C++ command. 

  • True or false: All lines in a Visual C++ program must end with semicolons. 

  • True or false: A left brace is always eventually followed later in the program with a right brace. 


    Find the Bug


    1. What is missing from this short program? Add the missing line of code. 

        // Program to calculate swimming pool floor area  main()  {    int width, length, area;    width = 16;    length = 32;    area = width * length;    cout << "The area is " <<>

  • Fred just entered his first C++ program, but the compiler gave him fits. See if you can tell Fred what's wrong with this simple program: 

        /* My first program     /* At least I'm trying! */     This program will print a simple message */  #include   void Main()  {    Cout << "A simple program";    Return;  }

    Write Code That. . .


  • Glance through Listing 4.1 again. See whether you can figure out where main() ends. In other words, if there were more functions in this program, where would the next one go? 

  • Write a preprocessor directive that includes the header file named STRING.H. 

  • Write a comment that includes your name and date. Use C's style of comments. On the next line, use a C++ comment to do the very same thing. 


    Extra Credit


  • Write the statement that stores the result of a sales variable multiplied by a profit variable into a third variable named netsales. 

  • Write the statement that outputs your name to the screen. Hint: Because your name is a string of more than one character, enclose it in double quotation marks. 

  • Enter the corrected code from question number 17 in your Visual C++ compiler, Compile the program using Project | Build (Shift+F8) and run it with Project | Execute (Ctrl+F5). View the results in the QuickWin output window. 
  • No comments:

    ITUCU