1 / 32

Chapter five selected exercises with solutions

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

Download Presentation

Chapter five selected exercises with solutions

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Chapter five selected exercises with solutions

  2. Exercises 5.1

  3. Exercises 5.1

  4. 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

  5. Exercises 5.1

  6. 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

  7. 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)

  8. Exercises 5.2

  9. Exercises 5.2

  10. Exercises 5.2

  11. Exercises 5.2

  12. Exercises 5.2

  13. 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

  14. 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

  15. 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

  16. 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."

  17. Exercises 5.3

  18. Exercises 5.3

  19. 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.

  20. Exercises 5.3

  21. Exercises 5.3

  22. Exercises 5.3

  23. Exercises 5.3

  24. 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"

  25. Exercises 5.3

  26. Exercises 5.3

  27. 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

  28. Exercises 5.3

  29. Exercises 5.3

  30. Exercises 5.3

  31. 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

  32. 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

More Related