Sams Teach Yourself C++ in 21 Days

(singke) #1
20: int a, b, c;
21: cout << “Enter two numbers: “;
22: cin >> a;
23: cin >> b;
24:
25: cout << “\nCalling Add()\n”;
26: c=Add(a,b);
27: cout << “\nBack in main().\n”;
28: cout << “c was set to “ << c;
29:
30: cout << “\n\nCalling Subtract()\n”;
31: c=Subtract(a,b);
32: cout << “\nBack in main().\n”;
33: cout << “c was set to “ << c;
34:
35: cout << “\nExiting...\n\n”;
36: return 0;
37: }

Day 3....................................................................................................................


Quiz ................................................................................................................


  1. Integer variables are whole numbers; floating-point variables are “reals” and have a
    “floating” decimal point. Floating-point numbers can be represented using a man-
    tissa and exponent.

  2. The keyword unsignedmeans that the integer will hold only positive numbers. On
    most computers with 32-bit processors,shortintegers are two bytes and longinte-
    gers are four. The only guarantee, however, is that a longinteger is at least as big
    or bigger than a regular integer, which is at least as big as a shortinteger.
    Generally, a longinteger is twice as large as a shortinteger.

  3. A symbolic constant explains itself; the name of the constant tells what it is for.
    Also, symbolic constants can be redefined at one location in the source code, rather
    than the programmer having to edit the code everywhere the literal is used.
    4.constvariables are “typed,” and, thus, the compiler can check for errors in how
    they are used. Also, they survive the preprocessor, and, thus, the name is available
    in the debugger. Most importantly, using #defineto declare constants is no longer
    supported by the C++ standard.

  4. A good variable name tells you what the variable is for; a bad variable name has
    no information. myAgeand PeopleOnTheBusare good variable names, but x,xjk,
    and prndlare probably less useful.

  5. BLUE= 102


824 Appendix D

32 0672327112_app_d.qxd 11/19/04 12:30 PM Page 824

Free download pdf