Martin
PT1420
Practice Activity 2:Assignment 1: Homework
Algorithm Workbench Review Questions 6-10, Starting on page 159
6. Rewrite the following If- Then- Else If statement as a Select Case statement. If selection == 1 Then Display " You selected A." Else If selection == 2 Then Display " You selected 2." Else If selection == 3 Then Display " You selected 3." Else If selection == 4 Then Display " You selected 4." Else Display " Not good with numbers, eh?" End If
Dim Selection as Integer 1
Select Case Selection
Case 1 display "you selected A"
Case 2 display "you selected 2"
Case 3 display "you selected 3"
Case 4 display "you selected 4"
Case Else display " Not good with numbers, eh?”
End Select
7. Design an If- Then- Else statement ( or a flowchart with a dual alternative deci-sion structure) that displays “ Speed is normal” if the speed variable is within the range of 24 to 56. If speed holds a value outside this range, display “ Speed is abnormal.”
Main
Declare Integer Speed Display “Enter Speed;” If speed>=24 AND speed <= 56 Then
Else
Display “Speed is normal”
Else
Display “Speed is abnormal”
END If
End
8. Design an If- Then- Else statement ( or a flowchart with a dual alternative decision structure) that determines whether the points variable is outside the range of 9 to 51. If the variable holds a value outside this range it should display “ Invalid points.” Otherwise, it should display “ Valid points.”
9. Design a case structure that tests the month variable and does the following: . If the month variable is set to 1, it displays “ January has 31 days.” . If the month variable is set to 2, it displays “ February has 28 days.” . If the month variable is set to 3, it displays “ March has 31 days.” . If the month variable is set to anything else, it displays “ Invalid selection.”
10. Write an If- Then statement that sets the variable hours to 10 when the flag variable minimum is set.
Programming Exercises 5 and 8, Starting on page 160
5.