Assignment 5, due Sep 22

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: Here's a small shell script that compares two files:
    #!/bin/sh # compare f1 f2 # script to compare and comment on differences between 2 files echo comparing $1 with $2 if diff $1 $2; then echo true else echo false fi

    If you store this script in a file called compare and make that file executable with chmod +x compare, you can run it with ./compare f1 f2 for any 2 files f1 and f2. (Try it with small files.) Note, in the script, $1 is a reference to the first command line argument, and $2 is a reference to the second. This is really bad language design, but it works, so we live with it.

    a) Does the diff command return an idication of success or failure? If so, when does it indicate success and when does it indicate failure. The above script lets you test this empirically. (0.5 points)

    b) In the notes for Lecture 8, the test file was threatening to get very long by the end. Suggest a script that could be used in the test script in order to allow each test to be coded on one line, assuming that there were existing files holding the input, the expected output, and the expected error messages for each test, stored in the testfiles directory. (0.5 points)

  2. Background: An input file for MP2 contained in a file named f is given as an example at the start of the assignment for MP2. Make reasonable assumptions about the print routine you include in your code for MP2.

    A problem: What output would you expect from your solution to MP2 when given this input? (1.0 points)

  3. Background: There are two sensible options that a constructor or factory method could use to report failure. It could throw an exception, or in the case of a factory method, it could return null. Look at the code distributed with the Sept. 14 lecture notes, in the readNetwork method. This code contains the line:
    inters.add( new Intersection( sc ) );

    What we want, with either solution, is to not-only not create a new intersection, but not add anything to the list inters.

    a) Rewrite this line so that it handles the Intersection.ConstructorFailure exception thrown by the constructor. (0.5 points)

    b) Rewrite this line so that it handles a return value of null from a call to a factory method that replaces new Intersection(). (0.5 points)