Part 1 Written Assignment

2. How does a decimal value waste memory space?

14. Write a short discussion of what was lost and what was gained in Javas designers decision to not include the pointers of C++.

9. Assume the following rules of associativity and precedence for expressions: see image.

Show the order of evaluation of the following expressions by parenthesizing all subexpressions and placing a superscript on the right parenthesis to indicate order. For example, for the expression

a + b * c + d
  • a * b - 1 + c
  • a * (b - 1) / c mod d
  • (a - b) / c & (d * e / a - 3)
  • -a or c = d and e
  • a > b xor c or d <= 17
  • -a + b

13. Let the function fun be defined as

int fun(int *k) {
*k += 4;
return 3 * (*k) - 1;
}

Suppose fun is used in a program as follows:

void main() {
int i = 10, j = 10, sum1, sum2;
sum1 = (i / 2) + fun(&i);
sum2 = fun(&j) + (j / 2);
}

What are the values of sum1 and sum2

  • if the operands in the expressions are evaluated left to right?
  • if the operands in the expressions are evaluated right to left?

9. What are the arguments both for and against the exclusive use of Boolean expressions in the control statements in Java (as opposed to also allowing arithmetic expressions, as in C++)?

4. Consider the following C program segment. Rewrite it using no gotos or breaks .

j = -3;
for (i = 0; i < 3; i++) {
switch (j + 2) {
case 3:
case 2: j--; break;
case 0: j += 2; break;
default: j = 0;
}
if (j > 0) break;
j = 3 - i
}

7. What is the difference between functional programming languages and imperative languages?

8. What is the scope of a "typical" Scheme variable?

9. Is operator associativity or precedence a factor in Scheme? Why or why not?

10. What does the following Scheme function do? Write comments for each line.

Part 2 Programming Assignment

1. Write a Scheme function that sums the numbers in a list. For example, your function is called listsum, then (listsum '(1 2 3 4 5 4 3 2 1)) should return 25

2. Write a Scheme function that takes a list and a number, n, and returns the nth element of the list. For example, your function is called getelement, then (getelement '(1 2 3 4 5) 3) will return 3.

Academic Honesty!
It is not our intention to break the school's academic policy. Posted solutions are meant to be used as a reference and should not be submitted as is. We are not held liable for any misuse of the solutions. Please see the frequently asked questions page for further questions and inquiries.
Kindly complete the form. Please provide a valid email address and we will get back to you within 24 hours. Payment is through PayPal, Buy me a Coffee or Cryptocurrency. We are a nonprofit organization however we need funds to keep this organization operating and to be able to complete our research and development projects.