Chapter seven review Monther Aldwairi. What is the output of: Private Sub cmdButton_Click() Dim i As...

48
Chapter seven review Monther Aldwairi
  • date post

    20-Dec-2015
  • Category

    Documents

  • view

    214
  • download

    1

Transcript of Chapter seven review Monther Aldwairi. What is the output of: Private Sub cmdButton_Click() Dim i As...

Page 1: Chapter seven review Monther Aldwairi. What is the output of: Private Sub cmdButton_Click() Dim i As Integer, a(1 To 4) As integer Open "DATA.TXT" For.

Chapter seven review

Monther Aldwairi

Page 2: Chapter seven review Monther Aldwairi. What is the output of: Private Sub cmdButton_Click() Dim i As Integer, a(1 To 4) As integer Open "DATA.TXT" For.

• What is the output of:• Private Sub cmdButton_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 • picBox.Print a(i); • Next i • End Sub• Contents of DATA.TXT: • 1,3,5,7

Page 3: Chapter seven review Monther Aldwairi. What is the output of: Private Sub cmdButton_Click() Dim i As Integer, a(1 To 4) As integer Open "DATA.TXT" For.

• Output:

• 7 3

Page 4: Chapter seven review Monther Aldwairi. What is the output of: Private Sub cmdButton_Click() Dim i As Integer, a(1 To 4) As integer Open "DATA.TXT" For.

• 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 • picBox.Print sum

Page 5: Chapter seven review Monther Aldwairi. What is the output of: Private Sub cmdButton_Click() Dim i As Integer, a(1 To 4) As integer Open "DATA.TXT" For.

• Output:

• 11100

Page 6: Chapter seven review Monther Aldwairi. What is the output of: Private Sub cmdButton_Click() Dim i As Integer, a(1 To 4) As integer Open "DATA.TXT" For.

• 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• picBox.Cls • picBox.Print a(0); a(2)• Contents of DATA.TXT: 0, 1, 5, 2, 0

Page 7: Chapter seven review Monther Aldwairi. What is the output of: Private Sub cmdButton_Click() Dim i As Integer, a(1 To 4) As integer Open "DATA.TXT" For.

• Output:

• 6 3

Page 8: Chapter seven review Monther Aldwairi. What is the output of: Private Sub cmdButton_Click() Dim i As Integer, a(1 To 4) As integer Open "DATA.TXT" For.

• 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• picBox.Print b• Contents of DATA.TXT: 2, 1, 0, -1, 3, 3

Page 9: Chapter seven review Monther Aldwairi. What is the output of: Private Sub cmdButton_Click() Dim i As Integer, a(1 To 4) As integer Open "DATA.TXT" For.

• Output:

• 4

Page 10: Chapter seven review Monther Aldwairi. What is the output of: Private Sub cmdButton_Click() Dim i As Integer, a(1 To 4) As integer Open "DATA.TXT" For.

• 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

Page 11: Chapter seven review Monther Aldwairi. What is the output of: Private Sub cmdButton_Click() Dim i As Integer, a(1 To 4) As integer Open "DATA.TXT" For.

• 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?

Page 12: Chapter seven review Monther Aldwairi. What is the output of: Private Sub cmdButton_Click() Dim i As Integer, a(1 To 4) As integer Open "DATA.TXT" For.

• How many elements are in the array declared by• Dim myArray(1 To 5, 1 To 5) As Single

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

Page 13: Chapter seven review Monther Aldwairi. What is the output of: Private Sub cmdButton_Click() Dim i As Integer, a(1 To 4) As integer Open "DATA.TXT" For.

7.1

Page 14: Chapter seven review Monther Aldwairi. What is the output of: Private Sub cmdButton_Click() Dim i As Integer, a(1 To 4) As integer Open "DATA.TXT" For.

3. Stuhldreher

Crowley

Page 15: Chapter seven review Monther Aldwairi. What is the output of: Private Sub cmdButton_Click() Dim i As Integer, a(1 To 4) As integer Open "DATA.TXT" For.
Page 16: Chapter seven review Monther Aldwairi. What is the output of: Private Sub cmdButton_Click() Dim i As Integer, a(1 To 4) As integer Open "DATA.TXT" For.

4. 11

Page 17: Chapter seven review Monther Aldwairi. What is the output of: Private Sub cmdButton_Click() Dim i As Integer, a(1 To 4) As integer Open "DATA.TXT" For.
Page 18: Chapter seven review Monther Aldwairi. What is the output of: Private Sub cmdButton_Click() Dim i As Integer, a(1 To 4) As integer Open "DATA.TXT" For.

5. 6 2 9 11 3 4

Page 19: Chapter seven review Monther Aldwairi. What is the output of: Private Sub cmdButton_Click() Dim i As Integer, a(1 To 4) As integer Open "DATA.TXT" For.
Page 20: Chapter seven review Monther Aldwairi. What is the output of: Private Sub cmdButton_Click() Dim i As Integer, a(1 To 4) As integer Open "DATA.TXT" For.

6. 10 12 3 14

Page 21: Chapter seven review Monther Aldwairi. What is the output of: Private Sub cmdButton_Click() Dim i As Integer, a(1 To 4) As integer Open "DATA.TXT" For.
Page 22: Chapter seven review Monther Aldwairi. What is the output of: Private Sub cmdButton_Click() Dim i As Integer, a(1 To 4) As integer Open "DATA.TXT" For.

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

Page 23: Chapter seven review Monther Aldwairi. What is the output of: Private Sub cmdButton_Click() Dim i As Integer, a(1 To 4) As integer Open "DATA.TXT" For.
Page 24: Chapter seven review Monther Aldwairi. What is the output of: Private Sub cmdButton_Click() Dim i As Integer, a(1 To 4) As integer Open "DATA.TXT" For.

14. cat(1) cat(2) cat(3) cat(4)

Felix Garfield Morris Socks

Page 25: Chapter seven review Monther Aldwairi. What is the output of: Private Sub cmdButton_Click() Dim i As Integer, a(1 To 4) As integer Open "DATA.TXT" For.

7.2

Page 26: Chapter seven review Monther Aldwairi. What is the output of: Private Sub cmdButton_Click() Dim i As Integer, a(1 To 4) As integer Open "DATA.TXT" For.

3. Michigan

Page 27: Chapter seven review Monther Aldwairi. What is the output of: Private Sub cmdButton_Click() Dim i As Integer, a(1 To 4) As integer Open "DATA.TXT" For.
Page 28: Chapter seven review Monther Aldwairi. What is the output of: Private Sub cmdButton_Click() Dim i As Integer, a(1 To 4) As integer Open "DATA.TXT" For.

4. The sum of the first 4 elements is 30

Page 29: Chapter seven review Monther Aldwairi. What is the output of: Private Sub cmdButton_Click() Dim i As Integer, a(1 To 4) As integer Open "DATA.TXT" For.
Page 30: Chapter seven review Monther Aldwairi. What is the output of: Private Sub cmdButton_Click() Dim i As Integer, a(1 To 4) As integer Open "DATA.TXT" For.

6. South Pacific

Page 31: Chapter seven review Monther Aldwairi. What is the output of: Private Sub cmdButton_Click() Dim i As Integer, a(1 To 4) As integer Open "DATA.TXT" For.
Page 32: Chapter seven review Monther Aldwairi. What is the output of: Private Sub cmdButton_Click() Dim i As Integer, a(1 To 4) As integer Open "DATA.TXT" For.

7. The total rainfall for the first quarter is 10

Page 33: Chapter seven review Monther Aldwairi. What is the output of: Private Sub cmdButton_Click() Dim i As Integer, a(1 To 4) As integer Open "DATA.TXT" For.
Page 34: Chapter seven review Monther Aldwairi. What is the output of: Private Sub cmdButton_Click() Dim i As Integer, a(1 To 4) As integer Open "DATA.TXT" For.

12. hue will be unknown in the Sub procedure.

Also, in the Print statement in the Sub procedure, tone needs a subscript.

Page 35: Chapter seven review Monther Aldwairi. What is the output of: Private Sub cmdButton_Click() Dim i As Integer, a(1 To 4) As integer Open "DATA.TXT" For.

7.3

Page 36: Chapter seven review Monther Aldwairi. What is the output of: Private Sub cmdButton_Click() Dim i As Integer, a(1 To 4) As integer Open "DATA.TXT" For.

1. 200 100

Page 37: Chapter seven review Monther Aldwairi. What is the output of: Private Sub cmdButton_Click() Dim i As Integer, a(1 To 4) As integer Open "DATA.TXT" For.
Page 38: Chapter seven review Monther Aldwairi. What is the output of: Private Sub cmdButton_Click() Dim i As Integer, a(1 To 4) As integer Open "DATA.TXT" For.

2. Oliver Stan

Page 39: Chapter seven review Monther Aldwairi. What is the output of: Private Sub cmdButton_Click() Dim i As Integer, a(1 To 4) As integer Open "DATA.TXT" For.
Page 40: Chapter seven review Monther Aldwairi. What is the output of: Private Sub cmdButton_Click() Dim i As Integer, a(1 To 4) As integer Open "DATA.TXT" For.

3. 11 7 Numbers interchanged.

Page 41: Chapter seven review Monther Aldwairi. What is the output of: Private Sub cmdButton_Click() Dim i As Integer, a(1 To 4) As integer Open "DATA.TXT" For.

10. 15 comparisons

11. (n - 1) + (n - 2) + ... + 1

A shorter version of this formula is n*(n-1)/2

Page 42: Chapter seven review Monther Aldwairi. What is the output of: Private Sub cmdButton_Click() Dim i As Integer, a(1 To 4) As integer Open "DATA.TXT" For.

7.5

Page 43: Chapter seven review Monther Aldwairi. What is the output of: Private Sub cmdButton_Click() Dim i As Integer, a(1 To 4) As integer Open "DATA.TXT" For.

4. 1.

2. Bogart

Page 44: Chapter seven review Monther Aldwairi. What is the output of: Private Sub cmdButton_Click() Dim i As Integer, a(1 To 4) As integer Open "DATA.TXT" For.
Page 45: Chapter seven review Monther Aldwairi. What is the output of: Private Sub cmdButton_Click() Dim i As Integer, a(1 To 4) As integer Open "DATA.TXT" For.

5. 4 1 6

5 8 2

Page 46: Chapter seven review Monther Aldwairi. What is the output of: Private Sub cmdButton_Click() Dim i As Integer, a(1 To 4) As integer Open "DATA.TXT" For.
Page 47: Chapter seven review Monther Aldwairi. What is the output of: Private Sub cmdButton_Click() Dim i As Integer, a(1 To 4) As integer Open "DATA.TXT" For.

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

Page 48: Chapter seven review Monther Aldwairi. What is the output of: Private Sub cmdButton_Click() Dim i As Integer, a(1 To 4) As integer Open "DATA.TXT" For.

14. Private Sub FindGreatestValue(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 picOutput.Print "The greatest value is"; greatest picOutput.Print "It occurs at (row, col): " For row = 1 To 3 For col = 1 To 45 If a(row, col) = greatest Then picOutput.Print row, col End If Next col Next row End Sub