CS1003/1004 Homework #1
Due by Thursday, February 12, at 5:00pm

There are two parts to this homework assignment: a theory portion, worth 10 points, and a programming portion, worth 15 points. Please be sure to review the submission instructions in advance.

Theory questions

  1. (2 points) Name one advantage and one disadvantage of assembly languages.
  2. (4 points) You're given the following code snippet:
    int i = 5;
    int j = 1;
    
    while(i > 0) {
      j = j * i;
      i = i - 1;
    }
    Explain, in one or two sentences of English, what mathematical operation is being done to the initial value of i to produce the final result of j (i.e., j = {some operation on i}). State the final results of i and j after the while loop finishes.
  3. (4 points) You're given the following if clause:
    if(i || (j && !k))
    1. (2 points) Draw the logic diagram for this boolean condition, similar to the examples in Brookshear 1.1, but with three inputs and one output.
    2. (2 points) Assume i is false (zero), j is true (one) and k is true (one). Will this if clause execute, and (one-two sentences max) why or why not?
  4. (0 points; this subproblem cancelled) You're given the following number in binary form: 11011011.
    1. (1 point) Assuming you're not using two's complement, give the decimal (base 10) form of this number. Use standard binary-to-decimal conversion.
    2. (2 points) Assuming you are using two's complement, give the decimal form of this number.
    3. (2 points) What's the positive equivalent in two's complement (i.e., if we were to multiply the decimal equivalent by -1)?

Programming assignment

Write a program, Calculator.java (for Java students) or calculator.c (for C students), that takes two non-zero integer command line parameters, a and b, performs the following calculations, and prints out the result of each operation. The operations which you need to implement are:

Please return the results in the above order and clearly label each result. See below for a sample output.

Hints:

Sample Output for java Calculator 2 4 and ./a.out 2 4:

The sum of 2 and 4 is 6
The product of 2 and 4 is 8
2 divided by 4 is .5
2 % 4 is 2
I computed (((2-1)*(4-1))+(4+1)+(4+2) to equal 14