Introduction to Computing

6 Weeks Exam: Fall 1995

1. Like Babbage's engines, early implementations of von Neumann machines would read programs from punched cards. a) How did von Neumann's design then treat programs differently, and why?

b) How was von Neumann's design also an improvement on the Universal Turing Machine? (Give a general answer and then cite some specifics to support it.) (15)

2. a) What is a "nested if"? b) How do the conditional-instruction rules in Knobby's language allow for the construction of a nested if? (10)

3. What goes in a software library--a) source code or object code? Discuss why, b) in terms of efficiency, and c) in terms of supporting abstraction. d) What is the relationship between a C++ header file and a library? (15)

4. Write a C++ definition for pi. What does this example illustrate about invariants? (10)

5. Imagine yourself standing very sleepily before your bathroom mirror one morning very early, needing to brush your teeth. Write an algorithm (of at most 8-10 primitive instructions--you get to decide what counts as a "primitive" for your "machine"--in each case) that will brush your teeth, using the following two general approaches: (a) a goals-to given forward chaining approach; (b) a top-down decomposition approach. (Use other side.) (20)

6. Write a program for Knobby which enables him to move to the corner of 1st Street and 1st Avenue, no matter where he is and what direction he is facing. (Hint: Think about the tests Knobby can perform that affect what he does.) (Use other side.) (15)

7. What would the following lines in a C++ program do? Show partial results, for example: (15)

1 + 3 - 2

    4

        2

(a) 3 / sqrt(4) * 3 + 2 (b) 5 + -2.0 * 4 % 3 (c) sqrt(pow(3,2)) / -2