Assignment 2, due Jan 25Solutions
Part of
the homework for CS:2820, Spring 2019
|
Background: Consider these two Java declarations:
int x = 1; char y = (char)('b' + x); String z = (String)("b" + y);
(Why the type casting (the (char) and (string))? The Java wants one of them, the other was included to make the code more symmetrical.)
a) What operation does the + operator do in computing the value of y. (0.3 points)
Integer addition, or in excessive detail, it adds 1, (the value of the integer variable x) to the ASCII (or UNICODE) value of the character 'b'.
b) What is the resulting value of y? (0.2 points)
'c'
c) What operation does the + operator do in computing the value of z. (0.3 points)
String concatenation, or in excessive detail, it concatenates the string "b" with the string "c" (the result of converting the value of the character variable y to a string).
d) What is the resulting value of z? (0.2 points)
"bc"
(Why the type casting (the (char) and (string))? The rules in Java for 'b'+x give an Integer result, and if you just write char y='b'+x; without casting the result to a character, the compiler will give a warning message. The casting of "b"+y to a string is completely unnecessary and was included only to make the code more symmetrical.)
a) Give the truth table for the 2-input function called b or not a. (0.3 points)
a | b | a | b+a |
---|---|---|---|
0 | 0 | 1 | 1 |
0 | 1 | 1 | 1 |
1 | 0 | 0 | 0 |
1 | 1 | 0 | 1 |
b) What is the above function's number in the table of 16 functions. (0.2 points)
11012 = 1310
c) Give the truth table for the 2-input function called b and not a. (0.3 points)
a | b | a | b×a |
---|---|---|---|
0 | 0 | 1 | 0 |
0 | 1 | 1 | 1 |
1 | 0 | 0 | 0 |
1 | 1 | 0 | 0 |
d) What is the above function's number in the table of 16 functions. (0.2 points)
01002 = 410
Consider the problem of modeling the city block bounded by Iowa Avenue, Dubuque, Washington and Clinton streets (east across the street from the Pentacrest). with these streets if we ignore the complexity of the bus interchange:
Do not include any streets (or alleys) in your answer that lead away from the block in question, but do include the intersections to which they connect and do include the alley that leads to the interior of the block. Note that every vehicle that enters this alley must eventually come back out, but that it may stay inside the block for a long time if it parks behind one of the businesses on the block.
A problem: Draw a diagram, with points for every intersection and arrows connecting the points for "road" to show how this road network would be modeled. The arrow head on each "road" indicates the direction of travel on that road.
Legibility matters. Lay out your diagram with north on the top and try to keep the topology the same as the real road network. Exact scale does not matter, but You might start by using a blow-up of a map as a layout guide (there are plenty of on-line map services). If your drawing skills are horrible, you may have to redraw a few times to get legible results.
In effect, the assignment above asked for a directed graph representation for the road network, not a map. The faint arrows in the following diagram are the parts that you were explicitly told not to include in your answer.
Technically, a graph would be a correct representation of the road network even if it were drawn with all the dots in a row, so long as the right dots were connected by arrows. This assignment, however, asked you to keep the result legible and to arrange things with some attention to the actual map.
Note that there are several ways to deal with the alley into the interior of the block. You could, for example, put an intersection inside the block, with a single inward leading arrow to that intersection and a single outgoing arrow back to the street. There's nothing wrong with doing this, but it doesn't really clarify much either.