Информатика_2 / Описание / 4-5
.docxТаблица описания объектов
Объект |
Имя объекта |
Свойство |
Значение свойства |
Форма |
Form4_5 |
Text |
4.5 Построить таблицу и найти наибольшее значение функции |
Кнопка |
Button1 |
Text |
Назад |
Кнопка |
Button2 |
Text |
Выполнить |
Кнопка |
Button3 |
Text |
Очистить |
Текстовое |
PictureBox1 |
Size |
(622, 64) |
Метка |
Label1 |
Text |
Отрезок [ |
Метка |
Label2 |
Text |
; |
Метка |
Label3 |
Text |
Шаг расчетов: |
Метка |
Label4 |
Text |
] |
Метка |
Label5 |
Text |
Наибольшее значение X: |
Текстовое |
TextBox1 |
Name |
TextBox1 |
Текстовое |
TextBox2 |
Name |
TextBox2 |
Текстовое |
TextBox3 |
Name |
TextBox3 |
Текстовое |
TextBox4 |
Name |
TextBox4 |
Список |
ListBox1 |
Name |
ListBox1 |
ForeColor |
Window Text |
||
Font |
Microsoft Sans Serif; 8,25pt |
Программный код
Option Strict On
Option Explicit On
Imports System.Math
Public Class Form4_5
'Назначаем переменные
Dim x_max As Single
Dim f_step As Single
Dim rstart As Single
Dim rstop As Single
Dim step_int As Integer
'Расчет количества шагов цикла
Function steps(ByVal f_start As Single, ByVal f_end As Single, ByVal f_step As Single) As Integer
Return CInt(Fix((f_end - f_start) / f_step) + 1)
End Function
'Функция ввода исходных данных из TextBox
Function vvod(ByVal T As TextBox) As Single
Return CSng(Val(T.Text))
End Function
'Процедура форматированного вывода результата в TextBox
Sub vivod(ByVal Z As Double, ByVal T As TextBox)
T.Text = Format(Z, "0.0000")
End Sub
'Функция расчета формулы задания
Function formula(ByVal x As Double) As Single
Return CSng(x * Exp(x * (-1)))
End Function
Function spase_incert(x As Single) As String
Dim text As String = " "
If x > 0 And x < 10 Then text = text + " "
If x > 10 And x < 100 Then text = text
Return text
End Function
Sub reshenie(ByVal step_int As Integer,ByVal start As Single,ByVal steps As Single,ByRef max As Single)
'локальные переменные процедуры
Dim i As Integer
Dim x As Single
Dim y As Single
Dim z1 As String = "N|"
Dim z2 As String = "X|"
Dim z3 As String = "Y|"
Dim z4 As String = "__"
For i = 1 To step_int
x = steps * i
y = CSng(formula(x))
If max < y Then max = y
z1 = z1 + Space(2) + spase_incert(i) + Format(i, "0") + Space(3) + "|"
z2 = z2 + spase_incert(x) + Format(x, "0.00") + Space(2) + "|"
z3 = z3 + spase_incert(y) + Format(y, "0.00") + Space(2) + "|"
z4 = z4 + "_________"
Next i
ListBox1.Items.Add(z1)
ListBox1.Items.Add(z4)
ListBox1.Items.Add(z2)
ListBox1.Items.Add(z4)
ListBox1.Items.Add(z3)
ListBox1.Items.Add(z4)
vivod(Max, TextBox4)
End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Form1.Show()
Me.Close()
End Sub
Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click
TextBox1.Clear()
TextBox2.Clear()
TextBox3.Clear()
TextBox4.Clear()
End Sub
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
f_step = vvod(TextBox1)
rstart = vvod(TextBox2)
rstop = vvod(TextBox3)
step_int = steps(rstart, rstop, f_step)
reshenie(step_int, rstart, f_step, x_max)
vivod(x_max, TextBox4)
End Sub
End Class