Answers to Self-Test Exercises

  1. 1. The five main components of a computer are the input device(s), the output device(s), the processor (CPU), the main memory, and the secondary memory.

  2. 2. The two numbers to be added.

  3. 3. The grades for each student on each test and each assignment.

  4. 4. A machine-language program is a low-level language consisting of 0s and 1s that the computer can directly execute. A high-level language is written in a more English-like format and is translated by a compiler into a machine-language program that the computer can directly understand and execute.

  5. 5. A compiler translates a high-level language program into a machine-language program.

  6. 6. The high-level language program that is input to a compiler is called the source program. The translated machine-language program that is output by the compiler is called the object program.

  7. 7. An operating system is a program, or several cooperating programs, but is best thought of as the user’s chief servant.

  8. 8. An operating system’s purpose is to allocate the computer’s resources to different tasks the computer must accomplish.

  9. 9. Among the possibilities are the Macintosh operating system Mac OS, Windows, VMS, Solaris, SunOS, UNIX (or perhaps one of the UNIX-like operating systems such as Linux). There are many others.

  10. 10. The object code for your C++ program must be combined with the object code for routines (such as input and output routines) that your program uses. This process of combining object code is called linking. For simple programs, this linking may be done for you automatically.

  11. 11. The answer varies, depending on the compiler you use. Most UNIX and UNIX-like compilers link automatically, as do the compilers in most integrated development environments for Windows and Macintosh operating systems.

  12. 12. The following instructions are too vague for use in an algorithm:

    Add vanilla extract to taste.
    Beat until smooth.
    Pour into a pretty glass.
    Sprinkle with nutmeg.

    The notions of “to taste,” “smooth,” and “pretty” are not precise. The instruction “sprinkle” is too vague, since it does not specify how much nutmeg to sprinkle. The other instructions are reasonable to use in an algorithm.

  13. 13. The first step you should take when creating a program is to be certain that the task to be accomplished by the program is completely and precisely specified.

  14. 14. The problem-solving phase and the implementation phase.

  15. 15. Experience has shown that the two-phase process produces a correctly working program faster.

  16. 16. C++ is easy to understand.

  17. 17. The symbols \n tell the computer to start a new line in the output so that the next item output will be on the next line.

  18. 18. This statement tells the computer to read the next number that is typed in at the keyboard and to send that number to the variable named peasPerPod.

  19. 19. This statement says to multiply the two numbers in the variables numberOfPods and peasPerPod, and to place the result in the variable named totalPeas.

  20. 20. The #include <iostream> directive tells the compiler to fetch the file iostream. This file contains declarations of cin, cout, the insertion (<<) and extraction (>>) operators for I/O (input and output). This enables correct linking of the object code from the iostream library with the I/O statements in the program.

  21. 21.

    1. The extra space after the iostream file name causes a file-not-found error message.

    2. The extra space before the iostream file name causes a file-not-found error message.

    3. This one is correct.

  22. 22. The three main kinds of program errors are syntax errors, run-time errors, and logic errors.

  23. 23. The compiler detects syntax errors. There are other errors that are not technically syntax errors that we are lumping with syntax errors. You will learn about these later.

  24. 24. A syntax error.

  25. 25. A syntax error.

  26. 26. The text states that you should take warnings as if they had been reported as errors. You should ask your instructor for the local rules on how to handle warnings.

  27. 27. A logic error.