Chapter seven review Monther Aldwairi What is the

  • Slides: 48
Download presentation
Chapter seven review Monther Aldwairi

Chapter seven review Monther Aldwairi

 • • • • What is the output of: Private Sub cmd. Button_Click()

• • • • What is the output of: Private Sub cmd. Button_Click() Dim i As Integer, a(1 To 4) As integer Open "DATA. TXT" For Input As #1 For i = 1 To 4 Input #1, a(i) Next i For i = 4 To 1 Step -2 pic. Box. Print a(i); Next i End Sub Contents of DATA. TXT: 1, 3, 5, 7

 • Output: • 73

• Output: • 73

 • What is the output of: • Dim a(2 To 9) As Integer,

• What is the output of: • Dim a(2 To 9) As Integer, i As Integer, _ k As Integer, sum As Integer • For i = 2 To 9 • a(i) = i • Next i • sum = 0 • For k = 4 To 6 • sum = sum + 10 ^ a(k-2) • Next k • pic. Box. Print sum

 • Output: • 11100

• Output: • 11100

 • What is the output of: • • • Dim a(-1 to 5)

• What is the output of: • • • Dim a(-1 to 5) As Single, x As Single Open "DATA. TXT" For Input As #1 Do While Not EOF(1) Input #1, x a(x) = a(x) + 3 Loop Close #1 pic. Box. Cls pic. Box. Print a(0); a(2) Contents of DATA. TXT: 0, 1, 5, 2, 0

 • Output: • 63

• Output: • 63

 • • • • Dim a(-2 To 5), b As Integer Dim i

• • • • Dim a(-2 To 5), b As Integer Dim i As Integer, j As Integer Open "DATA. TXT" For Input As #1 num = 0 For i = 3 To 5 Input #1, a(i) Next i For j = -1 To 1 Input #1, k b = b + a(k) Next j pic. Box. Print b Contents of DATA. TXT: 2, 1, 0, -1, 3, 3

 • Output: • 4

• Output: • 4

 • How many comparisons will be made in the first pass of a

• How many comparisons will be made in the first pass of a bubble sort of n items? • Answer: n-1 • How many comparisons will be made in the second pass of a bubble sort of n items? • Answer: n-2 • How many comparisons will be made in all the passes of a bubble sort of n items? • Answer: (n-1)+(n-2)+(n-3) + … +2+1 • = n(n-1)/2

 • Given the following array items: • 3, 1, 8, 9, 2, 10

• Given the following array items: • 3, 1, 8, 9, 2, 10 • a) What is the contents of the array after the first pass of using bubble sort? • b) What is the contents of the array after the first comparison in the second pass? • c) How many comparisons will be made to find 2 using sequential search on the original array? • d) How many comparisons will be made to find 2 using sequential search if the array was sorted?

 • How many elements are in the array declared by • Dim my.

• How many elements are in the array declared by • Dim my. Array(1 To 5, 1 To 5) As Single • How many elements are in the array declared by • Dim my. Array(0 To 3, 1 To 3) As Single

7. 1

7. 1

3. Stuhldreher Crowley

3. Stuhldreher Crowley

4. 11

4. 11

5. 6 2 9 11 3 4

5. 6 2 9 11 3 4

6. 10 12 3 14

6. 10 12 3 14

13. river(1) river(2) river(3) river(4) river(5) Thames Ohio Amazon Volga Nile river(1) river(2) river(3)

13. river(1) river(2) river(3) river(4) river(5) Thames Ohio Amazon Volga Nile river(1) river(2) river(3) river(4) river(5) Ohio Amazon Volga Nile Thames

14. cat(1) cat(2) cat(3) Felix Garfield Morris cat(4) Socks

14. cat(1) cat(2) cat(3) Felix Garfield Morris cat(4) Socks

7. 2

7. 2

3. Michigan

3. Michigan

4. The sum of the first 4 elements is 30

4. The sum of the first 4 elements is 30

6. South Pacific

6. South Pacific

7. The total rainfall for the first quarter is 10

7. The total rainfall for the first quarter is 10

12. hue will be unknown in the Sub procedure. Also, in the Print statement

12. hue will be unknown in the Sub procedure. Also, in the Print statement in the Sub procedure, tone needs a subscript.

7. 3

7. 3

1. 200 100

1. 200 100

2. Oliver Stan

2. Oliver Stan

3. 11 7 Numbers interchanged.

3. 11 7 Numbers interchanged.

10. 15 comparisons 11. (n - 1) + (n - 2) +. . .

10. 15 comparisons 11. (n - 1) + (n - 2) +. . . + 1 A shorter version of this formula is n*(n 1)/2

7. 5

7. 5

4. 1. 2. Bogart

4. 1. 2. Bogart

5. 4 1 6 5 8 2

5. 4 1 6 5 8 2

13. Private Sub Exchange(a() As Single) Dim col As Integer, temp As Single 'Interchange

13. Private Sub Exchange(a() As Single) Dim col As Integer, temp As Single 'Interchange values of 2 nd and 3 rd row For col = 1 To 10 temp = a(2, col) = a(3, col) = temp Next col End Sub

14. Private Sub Find. Greatest. Value(a() As Single) Dim row As Integer, col As

14. Private Sub Find. Greatest. Value(a() As Single) Dim row As Integer, col As Integer Dim greatest As Single 'Find greatest value in array and the locations where it occurs greatest = a(1, 1) For row = 1 To 3 For col = 1 To 45 If a(row, col) > greatest Then greatest = a(row, col) End If Next col Next row pic. Output. Print "The greatest value is"; greatest pic. Output. Print "It occurs at (row, col): " For row = 1 To 3 For col = 1 To 45 If a(row, col) = greatest Then pic. Output. Print row, col End If Next col Next row End Sub