Computer Science 3675
Practice questions for quiz 5

  1. Write a clearly legible T to the left of each of the following that is true, and a clearly legible F to the left of each that is false.

    1. Programs written in an object-oriented style tend to be organized significantly differently from programs written in a functional or procedural style.

    2. Suppose that programs A and B do the same thing, but A is written in a procedural style, and B is written in an object-oriented style. Changes to program A that would require making modifications to existing functions might well be possible in B almost entirely without modifying existing function definitions.

    3. In Java, a concrete class can have virtual functions in it.

    4. In Java, an interface can only contain virtual (or abstract) functions, and cannot contain any instance variables.

    5. In a single inheritance language, each class can have at most one base class.

    6. In object-oriented programming, an object's private variables are only directly accessible to that one object.

    7. In object-oriented programming, a protected data field can only be used inside the definition of one class.

    8. In Java, a class can implement more than one interface.

    9. When unification binds a variable, it always binds that variable to some constant.

    10. Unification is symmetric. Unifying A and B has exactly the same effect as unifying B and A .

    11. When a variable occurs in a logic programming goal, the interpreter is being asked whether that goal holds for all values of the variable.

    12. In logic programming, a variable in an axiom might be used as an input variable sometimes, and as an output variable at other times, when computation uses that axiom.

    13. Cuts are used to reduce memory requirements and to speed up computation.

  2. Backtracking

    1. is supported by almost all programming languages.

    2. is not supported directly by any programming languages, but must be simulated using recursion.

    3. is supported by some programming languages, but is rarely used in languages that support it.

    4. is a control structure that involves trying more than one answer to an expression or statement.

  3. When an exception happens during execution of a program, the exception manager must begin forcing functions to return, and removing their frames from the run-time stack. How does the exception manager know when to stop removing frames?

  4. In a logic programming style, write axioms for computing predicate allsame(X), which is true just when all members of list X are the same. For example, allsame([5,5,5]) is true, as is allsame([a,a]), but allsame([2,4,4]) is false. Note that allsame([]) is true, and allsame([b]) is true.

  5. Show the logic programming search tree for goal (member(X,[3,4,5]), member(X,[4])), up to the point where a success is found. The definition of the member predicate is as follows.
          member(M, M::X)
          member(M, T) => member(M, X::T)