Skip to main content

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. 
  • Comments

    Popular posts from this blog

    MFC - Microsoft Foundation Classes Design Patterns

    1 Introduction This paper describes the use of object-oriented software design patterns, as presented in Design Patterns: Elements of Reusable Object-Oriented Software by Gamma et al., within the Microsoft Foundation Class Library (MFC). MFC is used for implementing applications for Microsoft Windows operating systems. Because of the size of the MFC library, a complete analysis would have been beyond the scope of this assignment. Instead, we identified various possible locations for design patterns, using the class hierachy diagram of MFC, and studied the source carefully at these locations. When we did not find a pattern where we expected one, we have documented it anyway, with examples of how the particular problem could have been solved differently, perhaps more elegantly, using design patterns. We have included a brief introduction to MFC in Section 2 , as background information. The analysis has been split into three parts, with one section for each major design pattern ca...

    Explain Polymorphism and Flavors of Polymorphism...

    Polymorphism is the ability of different objects to react in an individual manner to the same message. This notion was imported from natural languages. For example, the verb "to close" means different things when applied to different objects. Closing a door, closing a bank account, or closing a program's window are all different actions; their exact meaning is determined by the object on which the action is performed. Most object-oriented languages implement polymorphism only in the form of virtual functions. But C++ has two more mechanisms of static (meaning: compile-time) polymorphism: Operator overloading. Applying the += operator to integers or string objects, for example, is interpreted by each of these objects in an individual manner. Obviously, the underlying implementation of += differs in every type. Yet, intuitively, we can predict what results are. Templates. A vector of integers, for example, reacts differently from a vector of string objects when it receives ...

    • Why might you need exception handling be used in the constructor when memory allocation is involved?

    Your first reaction should be: "Never use memory allocation in the constructor." Create a separate initialization function to do the job. You cannot return from the constructor and this is the reason you may have to use exception handling mechanism to process the memory allocation errors. You should clean up whatever objects and memory allocations you have made prior to throwing the exception, but throwing an exception from constructor may be tricky, because memory has already been allocated and there is no simple way to clean up the memory within the constructor.