Assignment 9, due Oct 27
Part of
the homework for CS:2820, Fall 2017
|
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!
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)
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)