CS100, Spring 1995: Answers to Quiz 4

This page contains questions and answers for the fourth quiz in CS100: Principles of Computer Science, a course based on the book The Most Comples Machine. The answers given here are sample answers only. There is always some variation in the answers that would receive full credit. The Notes contain any extra comments I happen to have; they are not parts of the answers.


Question 1: Discuss the concept of an operating system. What is its purpose? Why is it necessary? What are some of its major components?

Answer: The operating system of a computer is the basic software--programs, subroutines, and interrupt handlers---that controls the computer. It allows all the hardware devices that are part of the computer system to communicate, and it also handles communication with the user. The operating system includes device drivers that allow the CPU to interact with and control other devices such as disk drives, monitors, and printers; it includes a user interface or "command shell" that accepts commands from the user and carries them out; it includes subroutines that can be called by application programs using an API (Application Programming Interface); and it includes a start-up program that runs automatically when the computer is turned on.

Note: A complete computer system consists of both "hardware" and "software" components. The operating system is part of the software, and does not include things like busses and control wires.


Question 2: Write xTurtle commands that will draw the following picture:

Answer: Assume that the horizontal line is five units long and that the shorter vertical line is two units long. Then the following commands will draw this picture:

               forward(5)
               turn(90)
               forward(1)
               turn(180)
               forward(2)

Note: There are many, many different ways to draw the picture. For example, the last two commands here could be replaced by "back(2)". The solution given assumes that the turtle starts out facing to the right, with the pen down. This is the initial state whenever an xTurtle program is run. However, just to be sure (or if you want code that will work in other starting states), you could add the commands "PenDown Face(0)" to the beginning of this program.


Question 3: Give a specific example of an assignment statment. Explain exactly what your example means. That is, what is accomplished when the computer executes your statement.

Answer: An assignment statement assigns a value to a variable. An example would be

                        X := Y + 17

The effect of this statement when it is executed is to take the current value of Y, add 17 to that value, and then store the result in the variable X.


(by David Eck)