Assignment 5, due Sept 25

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

On every assignment, write your name legibly as it appears on your University ID card! Homework is due on paper at the start of class on the day indicated (usually Friday). Exceptions will be made only by advance arrangement (excepting "acts of God"). Late work must be turned in to the TA's mailbox (ask the CS receptionist in 14 MLH for help). Never push homework under someone's door!

  1. Background: Given that w is an instance of the Wire class, there are several alternatives for how you could output a line representing a wire to solve MP1. Consider the following:

    a) Add a method to class Wire called printMe(), so you would print the wire by calling w.printMe();. Give code for the printMe() method, assuming it fits in the class definiton given in the posted solution to Homework 3, problem 3. Note that none of the fields are declared private or protected in that code. (0.5 points)

    b) Add a method to class wire called toString(), so you would print the wire by calling System.out.println( w );. Give code for this method, under the same assumptions as above. (0.5 points)

    c) Which of these seems the better alternative? Consider issues such as information hiding and ease of retargeting the output to other files. (0.5 points)

  2. Background: Consider the problem of processing this line of input from a circuit description:
    wire a b in1
    

    Processing this requires that you check that gate b indeed has an input called in1 and that this input has not yet been connected by any other wire. There are three smaller problems embedded in this big problem:

    a) First, gate b must know what inputs are permitted, for example, with a list of strings. Suggest where this list goes and how it is initialized. (0.5 points)

    b) Second, once a wire is connected to one of the inputs of a gate (for example, input in1 of gate b), no further connections are permitted to that input. You could do this by deleting the input from the list (delete in1 from the input list of gate b), or you could do this by keeping an auxiliary boolean variable for each input used to indicate whether it is connected or not. Assuming that you will never need the input names again, which alternative appears to lead to a simpler initializer. (0.5 points)

    c) Third, where does the logic for preventing duplicate connections go? There seem to be several places it could go, for example, the code for the wire initializer could direclty manipulate the gate data structures, or the code for the wire initializer could call a special input check method of the gate, or perhaps there is another alternative. Explain how you intend to do this. (0.5 points)