320 likes | 335 Views
Chapter five selected exercises with solutions. Exercises 5.1. Exercises 5.1. Exercises 5.1. 1. True 2. False 3. True 4. False 5. True 6. False 7. True 8. True 9. False 10. False 11. False 12. True. 13. True 14. True 15. True 16. True 17. False 18. True
E N D
Exercises 5.1 • 1. True • 2. False • 3. True • 4. False • 5. True • 6. False • 7. True • 8. True • 9. False • 10. False • 11. False • 12. True 13. True 14. True 15. True 16. True 17. False 18. True 19. False 20. True 21. False 22. False 23. True 24. True
Exercises 5.1 • 25. Equivalent • 26. Not Equivalent • 27. Not Equivalent • 28. Equivalent • 29. Equivalent • 30. Not Equivalent • 31. Not Equivalent • 32. Not equivalent • 33. Equivalent • 34. 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 • 1. Less than ten • 2. Student • 3. 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.2 • 11. positive • 12. You are eligible to vote in 2 years • 13. Incorrect condition. Should be If (1 < num) And (num < 3) Then • 14. The variable num is missing from the second part of the condition.. Should be • If (num > 5) And (num < 9) Then • 15. no Then in second line • 16. Incorrect condition. Should be • If (major = "Business") Or (major = "Computer Science") Then • Also, the variable major was never assigned a value. • 17. Comparing numeric and string data • 18. 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) Then • 20. Missing End If for outermost If block
Exercises 5.2 • 21. a = 5 • 22. If (answer = "y") Or (answer = "Y") Then • picOutput.Print "YES" • End If • 'or • If UCase(answer) = "Y" Then • picOutput.Print "YES" • End If • 23. If j = 7 Then • b = 1 • Else • b = 2 • End If • 24. If (a < b) And (b < c) Then • picOutput.Print b; "is between"; a; "and"; c • End If
Exercises 5.2 • 25. 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 If • 26. 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 • 1. The price is $3.75 • The price is $3.75 • 2. case 2 • case 1 • case 3 • 3. 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 • 6. 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 • Hi • 9. 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 • 12. 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 30000 • 17. Valid • 18. Valid • 19. Invalid • 20. Invalid • 21. Valid • 22. Invalid
Exercises 5.3 • 23. Select Case a • Case 1 • picOutput.Print "one" • Case Is > 5 • picOutput.Print "two" • End Select • 24. 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.3 • 25. Select Case a • Case 2 • picOutput.Print "yes" • Case Is < 5 • picOutput.Print "no" • End Select • 26. Select Case a • Case 1, 3 • a = 2 • Case 2 • a = 3 • End Select