Introduction to Programming (22C:16, 22C:106)

Homework 6: Due Thursday, 3/20/97

Problem: [20 points]

There are 10 C++ expressions given below; some of these expressions have errors in them. Evaluate each error-free expression and write down the value it evaluates to. Also show the order in which operators are evaluated in each correct expression. For each expression with an error, give a brief explanation of all the errors in the expression. Assume that sum is an int variable with value equal to 1000, ch is a char variable with value equal to '3', and name is a string object with value equal to "Turing". Further assume that the expressions are independent, that is, what happens in one expression does not affect any subsequent expression. Also assume that all the relevent header files are included and therefore no error is caused by a missing header file.

  1. !(sum - 10 < sum < sum + 10)
  2. (sum % 10 == 0 && sum % 100 == 0)
  3. !ch == '3'
  4. (ch = '4' && ch != 4)
  5. (ch != '03') || (ch == 'A')
  6. name < "Turning" && name > "True"
  7. ((name > "turning") && (sum / (sum - 1000) == 0))
  8. (log10(sum) == name.length() - 3)
  9. ch != ' ' || ch != 10 || ch != '3'
  10. name + ch > name + "?"



Sriram Pemmaraju
Thu Mar 13 09:28:43 CST 1997