Оборудование, инструменты и приборы
ПЭВМ, программное обеспечение Microsoft Office (Excel 2007).
Варианты заданий
Найти ошибки и выполнить отладку программы, выданной преподавателем, согласно варианту заданий, приведенных в таблице 3.7.
Таблица 3.7
Варианты заданий
№ варианта | Задание |
Синтакситеческие ошибки | |
Private Sub Анализ(ByVal x As Integer, ByVal y As Integer, _ ByRef r As Integer) If x > y Then r = x Else If x < y Then 'Вложенный оператор r = y Else MsqBox "Числа равные" 'Блок из 2-х операторов r = x End If End If End Sub Private Sub CmdРешение_Click() Dim a As Integer, b As Integer, maximum2 As Integer a = CInt(Text1.Text) b = CInt(Text2.Text) Анализ a, b, maximum2 Text3.Text = maximum2 End Sub |
Продолжение таблицы 3.7
Private Sub Анализ(ByVal x As Integer, ByVal y As Integer, _ ByRef r As Integer) If x > y Then r = x Else If x < y Then 'Вложенный оператор r = y Else MsgBox "Числа равные" 'Блок из 2-х операторов r = x End If End If End Sub Private Sub CmdРешение_Click() Dim a As Integer, b As Integer, maximum2 As Integer a = CInt(Text1.Text) b = CInt(Text2.Text) Analiz a, b, maximum2 Text3.Text = maximum2 End Sub |
Продолжение таблицы 3.7
Private Sub Анализ(ByVal x As Integer, ByVal y As Integer, _ ByRef r As Integer) If x > y Then r = x Elze If x < y Then 'Вложенный оператор r = y Elze MsgBox "Числа равные" 'Блок из 2-х операторов r = x End If End If End Sub Private Sub CmdРешение_Click() Dim a As Integer, b As Integer, maximum2 As Integer a = CInt(Text1.Text) b = CInt(Text2.Text) Анализ a, b, maximum2 Text3.Text = maximum2 End Sub |
Продолжение таблицы 3.7
Private Sub Анализ(ByVal x As Integer, ByVal y As Integer, _ ByRef r As Integer) If x > y Tnen r = x Else If x < y Tnen 'Вложенный оператор r = y Else MsgBox "Числа равные" 'Блок из 2-х операторов r = x End If End If End Sub Private Sub CmdРешение_Click() Dim a As Integer, b As Integer, maximum2 As Integer a = CInt(Text1.Text) b = CInt(Text2.Text) Анализ a, b, maximum2 Text3.Text = maximum2 End Sub |
Продолжение табл. 3.7
Private Sub Анализ(BiVal x As Integer, BiVal y As Integer, _ BiRef r As Integer) If x > y Then r = x Else If x < y Then 'Вложенный оператор r = y Else MsgBox "Числа равные" 'Блок из 2-х операторов r = x End If End If End Sub Private Sub CmdРешение_Click() Dim a As Integer, b As Integer, maximum2 As Integer a = CInt(Text1.Text) b = CInt(Text2.Text) Анализ a, b, maximum2 Text3.Text = maximum2 End Sub |
Продолжение табл. 3.7
Privat Sub Анализ(ByVal x As Integer, ByVal y As Integer, _ ByRef r As Integer) If x > y Then r = x Else If x < y Then 'Вложенный оператор r = y Else MsgBox "Числа равные" 'Блок из 2-х операторов r = x End If End If End Sub Private Sub CmdРешение_Click() Dim a As Integer, b As Integer, maximum2 As Integer a = CInt(Text1.Text) b = CInt(Text2.Text) Анализ a, b, maximum2 Text3.Text = maximum2 End Sub |
Продолжение табл. 3.7
Private Sab Анализ(ByVal x As Integer, ByVal y As Integer, _ ByRef r As Integer) If x > y Then r = x Else If x < y Then 'Вложенный оператор r = y Else MsgBox "Числа равные" 'Блок из 2-х операторов r = x End If End If End Sab Private Sub CmdРешение_Click() Dim a As Integer, b As Integer, maximum2 As Integer a = CInt(Text1.Text) b = CInt(Text2.Text) Анализ a, b, maximum2 Text3.Text = maximum2 End Sub |
Продолжение табл. 3.7
Private Sub Анализ(ByVal x As Inteqer, ByVal y As Inteqer, _ ByRef r As Inteqer) If x > y Then r = x Else If x < y Then 'Вложенный оператор r = y Else MsgBox "Числа равные" 'Блок из 2-х операторов r = x End If End If End Sub Private Sub CmdРешение_Click() Dim a As Inteqer, b As Inteqer, maximum2 As Inteqer a = CInt(Text1.Text) b = CInt(Text2.Text) Анализ a, b, maximum2 Text3.Text = maximum2 End Sub |
Продолжение табл. 3.7
Private Sub Анализ(ByVal x As Integer, ByVal y As Integer, ByRef r As Integer) If x > y Then r = x Else If x < y Then 'Вложенный оператор r = y Else MsgBox "Числа равные" 'Блок из 2-х операторов r = x End If End If End Sub Private Sub CmdРешение_Click() Dim a As Integer, b As Integer, maximum2 As Integer a = CInt(Text1.Text) b = CInt(Text2.Text) Анализ a, b, maximum2 Text3.Text = maximum2 End Sub |
Продолжение табл. 3.7
Private Sub Analiz(ByVal x As Integer, ByVal y As Integer, _ ByRef r As Integer) If x > y Then r = x Else If x < y Then 'Вложенный оператор r = y Else MsgBox "Числа равные" 'Блок из 2-х операторов r = x End If End If End Sub Private Sub CmdРешение_Click() Dim a As Integer, b As Integer, maximum2 As Integer a = CInt(Text1.Text) b = CInt(Text2.Text) Анализ a, b, maximum2 Text3.Text = maximum2 End Sub |
Продолжение табл. 3.7
Private Sub Анализ(ByVal x As Integer, ByVal y As Integer, _ ByRef r As Integer) If x > y Then r = x Else If x < y Then 'Вложенный оператор r = y Else MsgBox "Числа равные" 'Блок из 2-х операторов r = x End If End If End Sub Private Sub CmdРешение_Click() Dim a As Integer, b As Integer, maximum2 As Integer a = CIht(Text1.Text) b = CIht(Text2.Text) Анализ a, b, maximum2 Text3.Text = maximum2 End Sub |
Продолжение табл. 3.7
Private Sub Реш_квадр_ур_Click() Dim a As Integer, b As Integer, c As Integer, _ d As Single, x1 As Single, x2 As Single a = CInt(TextBox1.Text): b = CInt(TextBox2.Text): c = CInt(TextBox3.Text) d = b ^ 2 - 4 * a * c If d < 0 Then MsgBox "Нет веществ-х корней" Else If d = 0 Then x1 = -b / (2 * a): x2 = x1 TextBox4.Text = x1: TextBox5.Text = x2 Else x1 = (-b - Sqr(d)) / (2 * a): x2 = (-b + Sqr(d)) / (2 * a) TextBox4.Text = x1: TextBox5.Text = x2 End Sub |
Продолжение табл. 3.7
Ошибки при вводе - выводе данных | |
Private Sub Анализ(ByVal x As Integer, ByVal y As Integer, _ ByRef r As Integer) If x > y Then r = x Else If x < y Then 'Вложенный оператор r = y Else MsgBox "Числа равные" 'Блок из 2-х операторов r = x End If End If End Sub Private Sub CmdРешение_Click() Dim a As Integer, b As Integer, maximum2 As Integer a = CInt(TextBox1.Text) b = CInt(TextBox2.Text) Анализ a, b, maximum2 TextBox3.Text = maximum2 End Sub |
Продолжение табл. 3.7
Private Sub Анализ(ByVal x As Integer, ByVal y As Integer, _ ByRef r As Integer) If x > y Then r = x Else If x < y Then 'Вложенный оператор r = y Else MsgBox "Числа равные" 'Блок из 2-х операторов r = x End If End If End Sub Private Sub CmdРешение_Click() Dim a As Integer, b As Integer, maximum2 As Integer a = CInt(Text1.Text) b = CInt(Text2.Text) Анализ a, b, maximum2 Text3.Text = maximum2 End Sub |
Продолжение табл. 3.7
Private Sub Анализ(ByVal x As Integer, ByVal y As Integer, _ ByRef r As Integer) If x > y Then r = x Else If x < y Then 'Вложенный оператор r = y Else MsgBox "Числа равные" 'Блок из 2-х операторов r = x End If End If End Sub Private Sub CmdРешение_Click() Dim a As Integer, b As Integer, maximum2 As Integer a = CInt(Text1.Text) b = CInt(Text2.Text) Анализ a, b, maximum2 Text3.Text = maximum2 End Sub |
Продолжение табл. 3.7
Function F(ByVal x As Single) As Single F = (x - 1) * (x - 1) - 1 End Function Private Sub Расчет(ByVal xn As Single, ByVal xk As Single, _ ByVal e As Single, ByRef x As Variant) Dim N As Integer, c As Single 'Объявление локальных переменных Dim mas() 'Обьявление динамического массива If F(xn) * F(xk) > 0 Then x = "?" MsgBox "На данном интервале корня нет или четное количество корней." _ + Chr(13) & _ "Задайте интервал, содержащий один корень." Exit Sub End If N = 0 c = (xn + xk) / 2 Do While xk - xn > e And Abs(F(c)) > e c = (xn + xk) / 2 N = N + 1 ReDim Preserve mas(1 To N) mas(N) = c If F(xn) * F(c) > 0 Then xn = c Else xk = c Loop x = c |
Продолжение табл. 3.7
If N = 0 Then ReDim Preserve mas(1 To 1) mas(1) = x End If List1.List = mas End Sub Private Sub CmdРешение_Click() Dim a As Single, b As Single, eps As Single, _ корень As Variant a = CSng(Text1.Text) b = CSng(Text2.Text) eps = CSng(Text3.Text) Расчет a, b, eps, корень Text4.Text = корень End Sub Private Sub List1_Click() Text5.Text = F(CSng(List1)) End Sub |
Продолжение табл. 3.7
Private Sub Поиск_мин_элем( _ ByRef b() As Single, _ ByVal jn As Integer, ByVal jk As Integer, _ ByRef jmin As Integer) Dim j As Integer jmin = jn For j = jn + 1 To jk If b(j) < b(jmin) Then jmin = j Next End Sub Private Sub Перестановка(ByRef x As Single, _ ByRef y As Single) Dim z As Single z = x x = y y = z End Sub Private Sub CmdРешение_Click() Dim n As Integer, imin As Integer, _ k As Integer, a() As Single n = CInt(Text1.Text) Randomize |
Продолжение табл. 3.7
For k = 1 To n ReDim Preserve a(1 To k) a(k) = Int(100 * Rnd) Next List1.List = a For k = 1 To n - 1 Поиск_мин_элем a, k, n, imin Перестановка a(k), a(imin) Next List2.List = a End Sub |
Продолжение табл. 3.7
Ошибки при выполнении программы | |
Private Sub Анализ(ByVal x As Integer, ByVal y As Integer, _ ByRef r As Integer) If x > y Then r = x Else If x < y Then 'Вложенный оператор r = y Else MsgBox "Числа равные" 'Блок из 2-х операторов r = x End If End If End Sub Private Sub CmdРешение_Click() Dim a As Integer, b As Integer, maximum2 As Integer a = CInt(Text1.Text) b = CInt(Text2.Text) Анализ а, б, maximum2 Text3.Text = maximum2 End Sub |
Продолжение табл. 3.7
Private Sub Реш_квадр_ур_Click() Dim a As Integer, b As Integer, c As Integer, _ d As Single, x1 As Single, x2 As Single a = CInt(TextBox1.Text): b = CInt(TextBox2.Text): c = CInt(TextBox3.Text) d = b ^ 2 - 4 * a * c If d < 0 Then MsgBox "Нет веществ-х корней" Else If d = 0 Then x1 = -b / 2 * a: x2 = x1 TextBox4.Text = x1: TextBox5.Text = x2 Else x1 = (-b - Sqr(d)) / 2 * a: x2 = (-b + Sqr(d)) / 2 * a TextBox4.Text = x1: TextBox5.Text = x2 End If End If End Sub |
Продолжение табл. 3.7
Private Sub Реш_квадр_ур_Click() Dim a As Integer, b As Integer, c As Integer, _ d As Single, x1 As Single, x2 As Single a = CInt(TextBox1.Text): b = CInt(TextBox2.Text): c = CInt(TextBox3.Text) d =Sqr( b ^ 2 - 4 * a * c) If d < 0 Then MsgBox "Нет веществ-х корней" Else If d = 0 Then x1 = -b /(2 * a): x2 = x1 TextBox4.Text = x1: TextBox5.Text = x2 Else x1 = (-b - Sqr(d)) / (2 * a): x2 = (-b + Sqr(d)) /( 2 * a) TextBox4.Text = x1: TextBox5.Text = x2 End If End If End Sub |
Продолжение табл. 3.7
Private Sub Реш_квадр_ур_Click() Dim a As Integer, b As Integer, c As Integer, _ d As Single, x1 As Single, x2 As Single a = CInt(TextBox1.Text): b = CInt(TextBox2.Text): c = CInt(TextBox3.Text) d =Sqr( b - 4 * a * c) If d < 0 Then MsgBox "Нет веществ-х корней" Else If d = 0 Then x1 = -b / (2 * a): x2 = x1 TextBox4.Text = x1: TextBox5.Text = x2 Else x1 = (-b - Sqr(d)) /(2 * a): x2 = (-b + Sqr(d)) / (2 * a) TextBox4.Text = x1: TextBox5.Text = x2 End If End If End Sub |
Продолжение табл. 3.7
Private Sub Реш_квадр_ур_Click() Dim a As Integer, b As Integer, c As Integer, _ d As Single, x1 As Single, x2 As Single a = CInt(TextBox1.Text): b = CInt(TextBox2.Text): c = CInt(TextBox3.Text) d = b - 4 * a * c If d < 0 Then MsgBox "Нет веществ-х корней" Else If d = 0 Then x1 = -b / (2 * a): x2 = x1 TextBox4.Text = x1: TextBox5.Text = x2 Else x1 = (-b - Sqr(d)) / (2 * a): x2 = (-b + Sqr(d)) / (2 * a) TextBox4.Text = x1: TextBox5.Text = x2 End If End If End Sub |
Продолжение табл. 3.7
Private Sub Реш_квадр_ур_Click() Dim a As Integer, b As Integer, c As Integer, _ d As Single, x1 As Single, x2 As Single a = CInt(TextBox1.Text): b = CInt(TextBox2.Text): c = CInt(TextBox3.Text) If d < 0 Then MsgBox "Нет веществ-х корней" Else If d = 0 Then x1 = -b / (2 * a): x2 = x1 TextBox4.Text = x1: TextBox5.Text = x2 Else x1 = (-b - Sqr(d)) / (2 * a): x2 = (-b + Sqr(d)) / (2 * a) TextBox4.Text = x1: TextBox5.Text = x2 End If End If End Sub |
Продолжение табл. 3.7
Private Sub Реш_квадр_ур_Click() Dim a As Integer, b As Integer, c As Integer, _ d As Single, x1 As Single, x2 As Single a = CInt(TextBox1.Text): b = CInt(TextBox2.Text): c = CInt(TextBox3.Text) d = b ^ 2 - 4 * a * c If d < 0 Then MsgBox "Нет веществ-х корней" Else If d = 0 Then x1 = -b / (2 * a): x2 = x1 Else x1 = (-b - Sqr(d)) / (2 * a): x2 = (-b + Sqr(d)) / (2 * a) End If End If End Sub |
Продолжение табл. 3.7
Private Sub Реш_квадр_ур_Click() Dim a As Integer, b As Integer, c As Integer, _ d As Single, x1 As Single, x2 As Single a = CInt(TextBox1.Text): b = CInt(TextBox2.Text): c = CInt(TextBox3.Text) d =Sqr( b ^ 2 - 4 * a * c) If d < 0 Then MsgBox "Нет веществ-х корней" Else If d = 0 Then x1 = -b / 2 * a: x2 = x1 TextBox4.Text = x1: TextBox5.Text = x2 Else x1 = (-b - Sqr(d)) / 2 * a: x2 = (-b + Sqr(d)) / 2 * a TextBox4.Text = x1: TextBox5.Text = x2 End If End If End Sub |
Продолжение табл. 3.7
Private Sub Реш_квадр_ур_Click() Dim a As Integer, b As Integer, c As Integer, _ d As Single, x1 As Single, x2 As Single a = CInt(TextBox1.Text): b = CInt(TextBox2.Text): c = CInt(TextBox3.Text) d = b - 4 * a * c If d < 0 Then MsgBox "Нет веществ-х корней" Else If d = 0 Then x1 = -b / 2 * a: x2 = x1 TextBox4.Text = x1: TextBox5.Text = x2 Else x1 = (-b - Sqr(d)) / 2 * a: x2 = (-b + Sqr(d)) / 2 * a TextBox4.Text = x1: TextBox5.Text = x2 End If End If End Sub |
Продолжение табл. 3.7
Private Sub Реш_квадр_ур_Click() Dim a As Integer, b As Integer, c As Integer, _ d As Single, x1 As Single, x2 As Single a = CInt(TextBox1.Text): b = CInt(TextBox2.Text): c = CInt(TextBox3.Text) If d < 0 Then MsgBox "Нет веществ-х корней" Else If d = 0 Then x1 = -b / 2 * a: x2 = x1 TextBox4.Text = x1: TextBox5.Text = x2 Else x1 = (-b - Sqr(d)) / 2 * a: x2 = (-b + Sqr(d)) / 2 * a TextBox4.Text = x1: TextBox5.Text = x2 End If End If End Sub |
Продолжение табл. 3.7
Private Sub Реш_квадр_ур_Click() Dim a As Integer, b As Integer, c As Integer, _ d As Single, x1 As Single, x2 As Single a = CInt(TextBox1.Text): b = CInt(TextBox2.Text): c = CInt(TextBox3.Text) d = b ^ 2 - 4 * a * c If d < 0 Then MsgBox "Нет веществ-х корней" Else If d = 0 Then x1 = -b / 2 * a: x2 = x1 Else x1 = (-b - Sqr(d)) / 2 * a: x2 = (-b + Sqr(d)) / 2 * a End If End If End Sub |
Продолжение табл. 3.7
Private Sub Реш_квадр_ур_Click() Dim a As Integer, b As Integer, c As Integer, _ d As Single, x1 As Single, x2 As Single a = CInt(TextBox1.Text): b = CInt(TextBox2.Text): c = CInt(TextBox3.Text) d = Sqr(b ^ 2 - 4 * a * c) If d < 0 Then MsgBox "Нет веществ-х корней" Else If d = 0 Then x1 = -b / (2 * a): x2 = x1 Else x1 = (-b - Sqr(d)) / (2 * a): x2 = (-b + Sqr(d)) / (2 * a) End If End If End Sub |
Продолжение табл. 3.7
Private Sub Реш_квадр_ур_Click() Dim a As Integer, b As Integer, c As Integer, _ d As Single, x1 As Single, x2 As Single a = CInt(TextBox1.Text): b = CInt(TextBox2.Text): c = CInt(TextBox3.Text) d = b - 4 * a * c If d < 0 Then MsgBox "Нет веществ-х корней" Else If d = 0 Then x1 = -b / (2 * a): x2 = x1 Else x1 = (-b - Sqr(d)) / (2 * a): x2 = (-b + Sqr(d)) / (2 * a) End If End If End Sub |
Дата добавления: 2021-01-11; просмотров: 341;