2005 FINAL EXAM ANSWERS Part A. 1. c 2. b 3. a 4. d 5. a 6. c 7. c 8. b 9. c 10. c Part B. 1. Variable Trace: Main Main G G G G x y s a b Return Value -----+-----+-----+-----+-----+------------- 100 150 1 0 2 1 4 2 8 3 16 4 32 5 64 6 128 7 8 256 8 8 Output: 11 2. Public Sub IsAllVowels(s As String) As Boolean Dim i As Integer For i = 0 To s.Length - 1 If IndexOfAny(s.SubString(i, 1), "AEIOUaeiou") = 0 Then Return False End If Next Return True End sub Public Sub Main( ) WriteLine(IsAllVowels("Mississippi")) WriteLine(IsAllVowels("ioua") WriteLine(IsAllVowels("a") End Sub 3. Use Method 3: Private c As New OleDbConnection Private sc As OleDbCommand Private da As New OleDbDataAdapter Private ds As New Dataset Public Sub Form1_Load(...) Handles MyBase.Load c.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;" & _ "Data Source=c:\students.mdb" c.Open() sc = c.CreateCommand() sc.CommandType = CommandType.Text da.SelectCommand = sc End Sub Public Sub btnSubmit_Load(...) Handles btnSubmit.Load sc.CommandText = "SELECT Gpa, Major FROM StudentData " & _ "WHERE Name = '" & txtName.Text & "'" ds.Clear( ) Dim n As Integer = da.Fill(ds, "StudentData") If n > 0 Then txtGpa.Text = ds.Tables(0).Rows(0).Item(0) txtGpa.Text = ds.Tables(0).Rows(0).Item(1) End If End Sub 4. Public Sub picDisplay_Paint(...) As picDisplay.Paint Dim line, fields( ) As String Dim x, y, r As Single Dim sr As New StreamReader("c:\circles.csv") Dim g As Graphics = e.Graphics Dim b As New SolidBrush(Color.Black) While sr.Peek( ) > -1 line = sr.ReadLine( ) fields = Split(line, ",") x = fields(0) y = fields(1) r = fields(2) g.FillEllipse(b, x - r, y - r, 2 * r, 2 * r) Next End Sub