Assignment 8, due Mar 24
Part of
the homework for CS:2820, Spring 2017
|
On every assignment, write your name and section number. Write your name as it appears on your university ID card! Use the section number as it appears in your current registration! We will not do detective work to figure out who did what. Homework is due on paper at the start of your discussion section. Exceptions will be made only by advance arrangement with your TA (excepting "acts of God"). Never push homework under someone's door!
a) The error message says that some variable cannot be accessed when calling the constructor new Event(). What variable? (0.4 points)
b) The variable in question is passed as an implicit parameter to the constructor. In this case, the parameter is never needed. There are three reasons for this, any one of which is sufficient. Give them. (Hint: All of them are negative reasons -- that is, thing that are not present or that the program never does and each can be expressed in a short sentence.) (0.6 points -- 0.2 for each reason)
a) Write the code for the addIncoming() method in class Gate, along with any new fields of class Gate that this requires. Do not write comments, but please indent your answer properly. (0.5 points)
b) Write the code for the check() method in class Gate that works with your code above plus the existing code of the class. Do not write comments, but please indent your answer properly. (0.5 points)
Why no comments above? Because these answers are so short that comments will just slow us down when we read them. In the context of a whole program, they probably do need, at the bare minimum, header comments.
Assume that class Gate is augmented with the following new fields:
a) Write the code for Wire.inputChange(). This is fairly simple, since all it does is schedule a corresponding output change after the wire's delay. (0.5 points)
b) Write the code for MinGate.inputChange(). This is harder because it has to determine whether the output should change. Suggestion: Update inputCounts after each input by decrementing the array entry for the old value and incrementing the entry for the new value. Then compute the new output value as the minimum array index for which the array entry is nonzero. Finally, if the new output value differs from Output, schedule an output change and update the value of Output. (0.5 points)