Question: Convert the pseudocode into Visual Basic code. 1 Module main() 2 // Constant for the array size. 3 Constant Integer SIZE = 4 4 5

Convert the pseudocode into Visual Basic code.
1 Module main()
2 // Constant for the array size.
3 Constant Integer SIZE = 4
4
5 // Array to hold test scores.
6 Declare Real testScores[SIZE]
7
8 // Variable to hold the total of scores.
9 Declare Real total
10
11 // Variable to hold the lowest score.
12 Declare Real lowestScore
13
14 // Variable to hold the average score.
15 Declare Real average
16
17 // Get the test scores from the user.
18 Call getTestScores(testScores, SIZE)
19
20 // Get the total of the test scores.
21 Set total = getTotal(testScores, SIZE)
22
23 // Get the lowest test score.
24 Set lowestScore = getLowest(testScores, SIZE)
25
26 // Subtract the lowest score from the total.
27 Set total = total - lowestScore
28
29 // Calculate the average. Divide by 3
30 // because the lowest score was dropped.
31 Set average = total / (SIZE 1)
32
33 // Display the average.
34 Display "The average with the lowest score"
35 Display "dropped is ", average
36 End Module
37
38 // The getTestScores module accepts an array (by reference)
39 // and its size as arguments. It prompts the user to enter
40 // test scores, which are stored in the array.
41 Module getTestScores(Real Ref scores[], Integer arraySize)
42 // Loop counter
43 Declare Integer index
44
45 // Get each test score.
46 For index = 0 To arraySize - 1
47 Display "Enter test score number ", index + 1
48 Input scores[index]
49 End For
50 End Module
51
52 // The getTotal function accepts a Real array and its
53 // size as arguments. It returns the total of the
54 // array elements.
55 Function Real getTotal(Real array[], Integer arraySize)
56 // Loop counter
57 Declare Integer index
58
59 // Accumulator, initialized to 0
60 Declare Real total = 0
61
62 // Calculate the total of the array elements.
63 For index = 0 To arraySize - 1
64 Set total = total + array[index]
65 End For
66
67 // Return the total.
68 Return total
69 End Function
70
71 // The getLowest function accepts a Real array and its
72 // size as arguments and returns the lowest value in
73 // the array.
74 Function Real getLowest(Real array[], Integer arraySize)
75 // Variable to hold the lowest value.
76 Declare Real lowest
77
78 // Loop counter
79 Declare Integer index
80
81 // Get the first element of the array.
82 Set lowest = array[0]
83
84 // Step through the rest of the array. When a value
85 // less than lowest is found, assign it to lowest.
86 For index = 1 To arraySize - 1
87 If array[index] < lowest Then
88 Set lowest = array[index]
89 End If
90 End For
91
92 // Return the lowest value.
93 Return lowest
94 End Function
Programs output should be:
Enter test score number 1
92 [Enter]
Enter test score number 2
67 [Enter]
Enter test score number 3
75 [Enter]
Enter test score number 4
88 [Enter]
The average with the lowest score
dropped is 85

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!