среда, 24 декабря 2014 г.

5 лабораторная код 1

Option Strict On
Option Explicit On
Imports System.Math
Public Class Form1

    Sub f_reg(ByVal n1 As Integer, ByVal x1 As Single, ByVal h1 As Single)
        'локальные переменные процедуры
        Dim i As Integer

        Dim y As Single
        Dim sum As Single
        Dim z1 As String = " N | "
        Dim z2 As String = " X | "
        Dim z3 As String = " Y | "
        Dim z As String = " "
        Dim z4 As String = "_____________"

        sum = 0

        For i = 1 To n1
            y = CSng((Cos(8 * x1)) / (Sqrt(1 + 10 * x1)))

            z1 = z1 + Format(i, "000") + Space(6) + "|" + Space(2)
            z2 = z2 + Format(x1, "0.000") + Space(3) + "|" + Space(2)
            z3 = z3 + Format(y, "0.000") + Space(3) + "|" + Space(2)
            x1 = x1 + h1
            z4 = z4 + "____________"
            sum = sum + y

        Next i

        'Вывод в ListBox

        ListBox1.Items.Add(z)

        ListBox1.Items.Add(z4)
        ListBox1.Items.Add(z1)
        ListBox1.Items.Add(z4)

        ListBox1.Items.Add(z)
        ListBox1.Items.Add(z2)
        ListBox1.Items.Add(z4)

        ListBox1.Items.Add(z)
        ListBox1.Items.Add(z3)
        ListBox1.Items.Add(z4)

        ListBox1.Items.Add(z)

        vivod(sum, TextBox4)

    End Sub

    'кол-во итераций цикла
    Function f_zikl(ByVal a As Single, ByVal b As Single, ByVal h As Single) As Integer
        Return CInt(Fix((b - a) / h) + 1)
    End Function

    'процедура ввода
    Sub vivod(ByVal W As Single, ByRef T As TextBox)
        T.Text = CStr(W)
    End Sub

    'процедура вывода
    Function vvod(ByVal T As TextBox) As Single
        Return CSng(Val(T.Text))
    End Function

    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click

        Dim a As Single
        Dim b As Single
        Dim h As Single

        Dim x As Single

        Dim n As Integer

        a = vvod(TextBox1)
        b = vvod(TextBox2)
        h = vvod(TextBox3)

        n = f_zikl(a, b, h)

        x = a

        f_reg(n, x, h)

    End Sub


    Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click
        Application.Exit()
    End Sub



    Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
        TextBox1.Clear()
        TextBox2.Clear()
        TextBox3.Clear()
        TextBox4.Clear()

        ListBox1.Items.Clear()
    End Sub

End Class

Комментариев нет:

Отправить комментарий