CS1004 Homework #3
Due on Tuesday, March 8, 2005 at 11:00am
There are two parts to this homework: a written component worth 19 points, and programming
component worth 6 points. Submission instructions are available
here.
Written questions
As described in the homework submission instructions, you
may submit this as a hardcopy, or as a file along with your programming
problems in one of four formats (Word, PDF, HTML, or plaintext). Note that problems assigned from Schneider/Gersting or Lewis/Loftus are
the exercise problems at the end of each chapter, not the practice
problems or self-review questions.
- (3 points) Prove the following logical equivalences (a truth
table is sufficient). These logical equivalences are often used in
simplifying Boolean expressions for both hardware and software
applications. Note that "+" represents boolean OR, "*" represents
Boolean AND, "~" represents Boolean NOT, and "=" represents equality
(i.e., the two halves of each equivalence should produce the same
Boolean results for the inputs).
- (1 point) Prove that Boolean addition and multiplication are associative,
i.e., show that:
- a+(b+c) = (a+b)+c
- a*(b*c) = (a*b)*c
- (1 point) Prove the Distributive Laws for Boolean algebra:
- a*(b+c) = (a*b)+(a*c)
- a+(b*c) = (a+b)*(a+c)
- (1 point) Prove DeMorgan's Theorems (these are very useful!):
- ~(a+b) = ~a * ~b
- ~(a*b) = ~a + ~b
(4 points) A Boolean operator is universal if any logic
function can be built from it.
- (2 points) Show that the NOR operator is universal (Hint: Show how to build AND, OR and NOT functions using
one or more two-input NOR gates.)
- (2 points) Show that the NAND operator is universal (Hint: Yes, show how to build AND, OR and NOT functions using
one or more two-input NAND gates.)
(3 points) Consider a logic function with 3 inputs (A,B,C) and three outputs (D,E,F) where:
- D is true if at least one input is true.
- E is true if exactly two inputs are true.
- F is true if only all three inputs are true.
- (2 points) Give a truth table showing D, E, and F.
- (1 point) Write out the logic equations for D, E, and F.
(2 points) Prove the following: ((A * B) + (A * C) + (B * C)) * (~(A * B * C)) = (A * B * ~C) + (A * C * ~B) + (B * C * ~A).
(2 points) Schneider/Gersting exercise 5.16c.
(5 points) While Schneider/Gersting's assembly language (page 217)
supports add, increment, subtract, and decrement, it doesn't support
multiply. In this exercise, you're going to write assembly code to perform
multiply, even though this ALU doesn't directly support it, by using the
fact that x * y is equivalent to adding the value of x to the result y
times. Assume the variables x and y are nonnegative
and are already stored at memory locations 200 and 201, that your code
starts at memory location 100, and that the result is to be stored in
memory location 202. You may also find it helpful to keep one
temporary counter variable at memory location 203. In other
words, as long as the counter variable is less than one of the operands,
keep on adding the other to the result field. Finally, you can
assume both 202 and 203 are initially zero.
Programming problems
Submit a README and these two .java files. Make sure your code
compiles; at this point in the course, it's generally better to submit code
that compiles that doesn't do everything as opposed to noncompiling code
(which may be penalized for a point).
- (3 points) Lewis/Loftus programming exercise 3.4. Store the
program in the file
RandomPhoneNumber.java
.
- (3 points) Modify the calculator (
BeanCounter.java
) you
wrote in HW#2 by adding the following three items. (If you don't
like your solution, we will post a solution by 2/25/05, and you can work
off of it.)
- (1 point) Change the code so that it reads four
double
s, named var1, var2, var3, and var4, from the user
using Scanner. (The existing operations can continue to use
only var1 and var2.)
- (1 point) Compute and print out the value of var1var2.
- (1 point) Compute and print out the linear distance
of (var1,var2) to (var3,var4). In case you don't remember your
algebra, this is equivalent to