CPSC 100, Fall 1995, Test #2

This is the second of two in-class tests from CPSC 100: Principles of Computer Science, Fall 1995. The answers given would receive full credit, but in many cases, there are variations or even completely different answers that would also receive full credit. The "Notes" are meant to clarify the answer or to provide some interesting extra information.


Question 1: Discuss the concept of an operating system. What is its purpose? Why is it necessary? List some of the major components of an operating system, and describe their functions.

Answer: The operating system consists of the basic software necessary to run a computer. It allows the CPU and other hardware devices in a computer system to communicate with each other and with the user. An operating system includes device drivers, which are used by the CPU to communicate with and control other hardware devices in the system. It also includes an API (applications programming interface) that provides common subroutines to be used by applications programs, and a user interface that accepts commands from the user and carries them out.


Question 2: Define the terms subroutine, dummy parameter, and actual parameter, and give examples.

Answer: A subroutine is a list of instructions chunked together into a "black box" and given a name. Once a subroutine has been defined, it can be called just by giving its name and specifying any necessary parameters. Parameters are used for communication between the subroutine and the rest of the program. When a subroutine is called, actual parameters are provided in the subroutine call statement. For example, the 5 in the command "forward(5)" and the "x" in the command "square(x)" are actual parameters. Dummy parameters are used in subroutine definitions as stand-ins for the actual parameters that will be provided when the subroutine is called. For example, in the following subroutine definition, "length" and "degrees" are dummy parameters:

                  SUB angle(length, degrees)
                     forward(length)
                     turn(degrees)
                     forward(length)
                  END SUB

Note: The most common error on the test was to say that a variable used in a subroutine call statement (such as the "x" in "forward(x)") is a dummy parameter. It's not; it's an actual parameter. The variable has some actual value that is being passed as a parameter to the subroutine. Dummy parameters are found only in subroutine definitions.


Question 3: Explain what is meant by software engineering, briefly discuss some of the techniques used in software engineering, and explain how it differs from hacking as an approach to writing programs.

Answer: Software engineering refers to the careful, systematic development of computer programs. It used standard methodologies such as top-down design (solving a problem by breaking it down into sub-problems) and bottom-up design (putting together software tools to create more complex tools, until a tool that can solve the problem is developed). This is very different from hacking, which refers to a trial-and-error, seat-of-the-pants type of programming that is OK for individuals writing small programs but not for large teams of programmers solving complex problems.


Question 4: Draw the picture that would be produced by the following xTurtle program. (You can get partial credit for an incorrect answer if you explain your reasoning.)

               SUB Hat
                  forward(5) turn(45)
                  forward(2) turn(90)
                  forward(2) turn(45)
                  forward(5) turn(180)
               END SUB
               
               DECLARE ct
               ct := 0
               LOOP
                  Hat
                  turn(45)
                  ct := ct + 1
                  EXIT IF ct = 8
               END LOOP

Answer:


Question 5: Write an xTurtle program that will draw the following picture. Use a loop. (There are 11 lines. Each line is 10 units long, and the lines are separated by gaps of width 1 unit.)

Answer: There are many possible answers. Here are two:

      DECLARE ct                     SUB Line
      ct := 0                           forward(10)
      LOOP                              back(10)
         forward(10)                    turn(90)
         back(10)                       PenUp
         ct := ct + 1                   forward(1)
         EXIT IF ct = 11                PenDown
         PenUp                          turn(-90)
         Move(0,-1)                  END SUB
         PenDown                     DECLARE count
      END LOOP                       count := 0
                                     LOOP
                                        Line
                                        count := count + 1
                                        EXIT IF count = 11
                                     END LOOP

Question 6: By the end of the 1940s, the first general-purpose, electronic, stored-program computers had been created. Explain the meaning of each of the following adjectives, as used here:
(a) general-purpose
(b) electronic
(c) stored-program

Answer: The computers produced in the 1940s and after were general-purpose in the sense that they could do any computation. That is, they were compuationally universal. They were electronic in that they were based on vacuum tubes (and later transistors) instead of things like gears or relays. They were stored-program computers in the sense that they had a memory in which programs could be stored while they were being executed and then easily replaced when a different program was needed, simply by storing the new program into memory.

Note: The second most common error on the test was to confuse "electonic" with "electric." To say something is electric simply means that it is powered by electricty. Relays are electric, but they have moving parts: small metal bars that are moved in order to open and close an electric circuit. In an electronic computer, there are no moving parts (except for the electrons themselves). Because electrons can be moved very quickly, electronic computers are thousands of times faster than merely electric computers.


Question 7: One of the most basic, but most important, elements of programming is the variable. Discuss what is meant by the term "variable," and discuss how variables are used in programs. Give an example.

Answer: Variables allow a programmer to use meaningful names to refer to the data used and manipulated by a program. A variable is just a named memory location. When the programmer declares a variable, as in the statement "DECLARE x", the computer sets aside a memory location for the variable and associates that location with the specified variable name. A value can be stored in that location using an assignment statement, such as x := 17. And the value of the variale can be used simply by giving its name, as in the commands "turn(x)" and "forward(sqrt(x)+5)".


Question 8: Explain what is meant by the software life cycle and list some of the major phases in the software life cycle.

Answer: Most serious programs have a life cycle that extends over many years, starting from an idea or a problem to be solved, followed by the development and testing of the program, and then by a period of use during which the program is updated to meet new requirements or to fix newly discovered bugs. The phases in the software life cycle include specification, analysis, design, coding, testing, debugging, and maintenance.


Question 9: Some people claim that we are now entering what they call an information age which will mean a fundamental transformations in most people's lives. Discuss the concept of an information age (why it might occur, whether it would be good or bad, what changes it might bring, and whether you think fundamental change is likely.)

(Note: This question has no right or wrong answer. It was meant as a thought question and was graded on the basis of the knowledge and insight that you displayed. Here is one possible answer.)

Answer: In an information age, information will be both valuable and easily available. It will become the main commodity, surplanting the industrial goods that have been the foundation of our economy for the last century and a half (since the Industrial Revolution). Furthermore, most people will earn their living working with information rather than traditional goods and services. Computers, as information-processing machines, will play the major role in this information age. Indeed, it is the widespread availability of powerful, networked computers that will make the information age possible. There is little doubt that the changes that will occur--that are already occuring in fact--will be fundamental.

Undoubtably, there will be both good and bad aspects to the information age. There might be problems with unemployment and deskilling. Personal privacy might be invaded by governtments and corporation that collect information on all aspects of people's lives. But there could be positive aspects as well: incresed leisure time, a growing sense of community among people all over the world, better-informed citizens with more opportunity to participate in the democratic process. Of course, they said all this about television too! In the end, the real choice will be up to people, not to machines.


Question 10: Consider the follwing recursive xTurtle subroutine:

                 SUB Guess(length, complexity)
                    DECLARE ct
                    IF complexity > 0 THEN
                       ct := 0
                       LOOP
                          forward(length)
                          turn(45)
                          Guess(length / 3, complexity - 1)
                          turn(-45)
                          back(length)
                          turn(90)
                          ct := ct + 1
                          EXIT if ct = 4
                       END LOOP
                    END IF
                 END SUB         

(Note that the subroutine Guess does not produce any drawing at all if the value of complexity is zero.) Draw the picture that will be produced by each of the following subroutine call statements: (a) Guess(5,1); (b) Guess(5,2); (c) Guess(5,3); and (d) Guess(5,4).

Answer:

Note: Pictures (b), (c) and (d) can each be obtained from the previous picture as follows: Draw a line of length 5; attach a copy of the previous picture, scaled down by a factor of 3 and rotated through 45 degrees; return to to the starting point; turn through 90 degrees; and repeat this process four times. This is exactly what the subroutine defnition says.


[by David Eck]