Assignment 9, due Oct 27

Part of the homework for CS:2820, Fall 2017
by Douglas W. Jones
THE UNIVERSITY OF IOWA Department of Computer Science

Assignments are to be turned in on paper. On every assignment, write your name, course and section number at the top. Write your name as it appears in your university records! Use the section number for which you are registered! We will not do detective work to figure out who did what. Work must be legible. Homework is due on paper in discussion section, usually at the start except when the assignment indicates that time to work on the assignment will be provided in class. Exceptions will be made only by advance arrangement with your TA (excepting "acts of God" outside your control). Never push homework under someone's door!

  1. Background: At the end of the notes for Oct. 24 (Lecture 18), simulation code is presented for intersections protected by a stop light, and a question is posed: Which of the following two alternative traffic laws does this code model:
    1. When the light turns green, all vehicles currently stopped waiting for that light may continue, even if the light turns red before all waiting vehicles have left.
    2. When the light turns red, vehicles may not enter the intersection, without regard to how long they have been waiting.

    a) Which law does the code simulate. (0.4 points)

    b) One line of the given code is the key to the above conclusion. In what method is that code and what line is it? (0.6 points)

  2. Background: Consider using the class hierarchy from the posted solution to homework 8 as part of a logic simulator. (you are welcome to correct the class name TwoOutGate to be TwoInGate.) The logical names for the event-service routines of gates in this context are inputChangeEvent and outputChangeEvent.

    When an input change event occurs, the new value of the input that changed is recorded and then, if the result is a change in the output, an output change event is scheduled one gate delay later.

    When an output change event occurs, the list of wires connected to the corresponding output is traversed to schedule input changes at the far ends of that wire one wire delay later.

    In each part of the question below, you could define a distinct version of the event service routine for each concrete class at the leaf of the class hierarchy, or you could move code up the hierarchy.

    a) Where in the hierarchy would be the best place to define versions of outputChangeEvent? Equivalently, which leaves of the class hierarchy can share the same versions of outputChangeEvent? (0.5 points)

    b) Suppose inputChangeEvent directly computes the new output. Where in the hierarchy would be the best place to define versions of inputChangeEvent? Equivalently, which leaves of the class hierarchy can share the same versions of inputChangeEvent? (0.5 points)

    c) How would your answer to part b change if you added a method NewOutput to each gate, so that inputChangeEvent calls NewOutput to see if a change to the output should be scheduled. (0.5 points)

    d) For each method discussed in parts a–c above, must that method be public, could it be private? could it be protected? (0.5 points)