32
Chapter five selected exercises with solutions

# Chapter five selected exercises with solutions. Exercises 5.1

Embed Size (px)

Citation preview

Chapter five selected exercises with solutions

Exercises 5.1

Exercises 5.1

Exercises 5.11. True2. False3. True 4. False 5. True 6. False7. True8. True9. False10. False11. False12. True

13. True14. True15. True16. True17. False18. True19. False20. True21. False22. False23. True24. True

Exercises 5.1

Exercises 5.125. Equivalent26. Not Equivalent27. Not Equivalent28. Equivalent29. Equivalent30. Not Equivalent31. Not Equivalent32. Not equivalent33. Equivalent34. Not Equivalent

Exercises 5.1

35. a <= b

36. (a <> b) And (a <> d)

37. (a >= b) Or (c = d)

38. (a = b) Or (a > b)

39. (a = "") Or (a >= b) Or (Len(a) >= 5)

Exercises 5.2

Exercises 5.2

Exercises 5.2

Exercises 5.2

Exercises 5.2

Exercises 5.21. Less than ten 2. Student3. tomorrow is another day. 4. Your change contains 3 dollars.5. 10 6. 7 12 7. Cost of call: \$11.26 8. To be or not to be.9. The number of vowels is 2 10. Hi

Exercises 5.211. positive 12. You are eligible to vote in 2 years13. Incorrect condition. Should be If (1 < num) And (num < 3) Then14. The variable num is missing from the second part of the condition..

Should be If (num > 5) And (num < 9) Then15. no Then in second line16. Incorrect condition. Should be

If (major = "Business") Or (major = "Computer Science") ThenAlso, the variable major was never assigned a value.

17. Comparing numeric and string data18. Faulty logic. If the user enters "off", the switch changes to "on" and

then back to "off".19. Incorrect condition. Should be If (j = 4) Or (k = 4) Then20. Missing End If for outermost If block

Exercises 5.221. a = 522. If (answer = "y") Or (answer = "Y") Then picOutput.Print "YES" End If 'or If UCase(answer) = "Y" Then picOutput.Print "YES" End If23. If j = 7 Then b = 1 Else b = 2 End If24. If (a < b) And (b < c) Then picOutput.Print b; "is between"; a; "and"; c End If

Exercises 5.225. message = "Is Alaska bigger than Texas and California combined?" answer = InputBox(message) If UCase(Left(answer, 1)) = "Y" Then picOutput.Print "Correct" Else picOutput.Print "Wrong" End If26. message = "How tall (in feet) is the Statue of Liberty?" feet = Val(InputBox(message)) If (feet > 141) And (feet < 161) Then picOutput.Print "Close" Else picOutput.Print "Nope" End If picOutput.Print "The Statue of Liberty is 151.08 feet" picOutput.Print "from base to torch."

Exercises 5.3

Exercises 5.3

Exercises 5.31. The price is \$3.75 The price is \$3.75 2. case 2 case 1 case 33. Mesozoic Era Paleozoic Era ? 4. Sorry, 1945. Work on the ENIAC began in June 1943. Correct No, 1945. By then IBM had built a stored-program computer.5. Nope. He worked with the developer, von Neumann, on the ENIAC. Correct.

Exercises 5.3

Exercises 5.3

Exercises 5.3

Exercises 5.3

Exercises 5.36. The equation has no real solutions. The equation has two real solutions. The equation has exactly one solution.7. The less things change, the more they remain the same. Less is more. Time keeps everything from happening at once.8. Hi Hi9. Should have a Case clause.

10. Both Case statements are invalid. The first one should be 3 To 10. The second one should have a comma instead of a semicolon.11. Case a = "Bob" should be Case "Bob"

Exercises 5.3

Exercises 5.3

Exercises 5.312. In Case clause, h should be "h"13. Error in second Case clause.14. First Case is executed every time, no matter what the value of num

is.15. Logical error: >= "Peach" should be >= "PEACH"

Syntax error: "ORANGE TO PEACH" should be "ORANGE" To "PEACH"

16. Invalid second Case. Should be Case 10000 To 3000017. Valid18. Valid19. Invalid20. Invalid21. Valid22. Invalid

Exercises 5.3

Exercises 5.3

Exercises 5.3

Exercises 5.323. Select Case a Case 1 picOutput.Print "one" Case Is > 5 picOutput.Print "two" End Select24. Select Case a Case 1 picOutput.Print "lambs" picOutput.Print "eat“

Case Is <=3 picOutput.Print "eat"

Case 5, Is > 7 picOutput.Print "ivy" End Select

Exercises 5.325. Select Case a Case 2 picOutput.Print "yes" Case Is < 5 picOutput.Print "no" End Select26. Select Case a Case 1, 3 a = 2 Case 2 a = 3 End Select