Assignment 8, due Mar 24

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

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!

  1. Background: In the simulation framework (class Simulation) in the code distributed on March 10, there is an inner class Event that is declared to be static. This code compiles correctly, but if the attribute static is deleted from the declaration of Event, you get an error.

    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)

  2. Background: The posted solution to Machine Problem 3 does not contain any sanity checking code. The obvious sanity check is to compare the number of wires going into a gate with the declared count of inputs. Obviously, we can add code analogous to the RoadNetwork.checkNewtork() code distributed on March 10. This would call g.check() for every gate g. We also need each wire to call addIncoming() for the gate to which it connects.

    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.

  3. Background: Consider the problem of writing a ternary logic simulator using the simulation framework distributed on March 10. The ternary values are 0-false, 1-unknown, and 2-true. Each wire and gate object has two new methods, inputChange(t,o,n) and outputChange(t,o,n). The parameters are: usually be deleted without causing any problems. Note the word usually. There are exceptions that occur when there is a class hierarchy and the parent class contains a private final method.

    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)