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

    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

    Explain using static class member ..

    A class member declared static is a single instance of that member shared by all instances of this class (that's why it is sometimes termed a class variable, as opposed to object variable). This feature has many uses: for instance, in order to create a file lock, one can use a static bool class member. An object trying to access this file has to check first whether the static (i.e., shared) flag is false. If it is, the object turns the flag on and processes the file safely, since other objects will now find that the flag is now on, and hence -- they cannot access the file. When the object processing the file is done, it has to turn off the flag, enabling another object to access it. How is a static member created? class fileProc { FILE *p; static bool isLocked; //only a declaration; see definition below... public: bool isLocked () const {return isLocked; } }; //somewhere outside the class definition: bool fileProc::isLocked; //definition; initialized to 'false' by defau

    the Differences Between static_cast and reinterpret_cast

    The operators static_cast and reinterpret_cast are similar: they both convert an object to an object of a different type. However, they aren't interchangeable. Static_cast uses the type information available at compile time to perform the conversion, making the necessary adjustments between the source and target types. Thus, its operation is relatively safe. On the other hand, reinterpret_cast simply reinterprets the bit pattern of a given object without changing its binary representation. To show the difference between the two, let's look at the following example: int n = 9; double d = static_cast < double > (n); In this example, we convert an int to a double. The binary representation of these types is very different. In order to convert the int 9 to a double, static_cast needs to properly pad the additional bytes of d. As expected, the result of the conversion is 9.0. Now let's see how reinterpret_cast behaves in this context: int n = 9; double d = reinterp