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

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

Option Strict On
Option Explicit On
Imports System.Math

Public Class Form1

    Function vvod(ByVal T As TextBox) As Double
        Return CDbl(Val(T.Text))
    End Function

    Sub vivod(ByVal z As Double, ByVal T As TextBox)
        T.Text = CStr(Format(z, "0.0000"))
    End Sub

    Sub vivodInt(ByVal Z As Integer, ByVal T As TextBox)
        T.Text = CStr(Z)
    End Sub

    Function z_fun(ByVal x As Double, ByVal y As Double) As Double
        Return x + y - x / y
    End Function

    Public Sub Cikl(ByVal a As Double, ByVal b As Double, ByVal h1 As Double, ByVal c As Double, ByVal d As Double, ByVal h2 As Double)

        Dim i1, i2, n1, n2 As Integer
        Dim x, y, z As Double
        Dim col As Integer = 0
        Dim sum As Double = 0

        Dim zz As String = "  "
        Dim zzz As String = "_______________"

        Dim coll As String = "coll | " + Space(3)
        Dim z1 As String = " n | " + Space(3)
        Dim z2 As String = " x | " + Space(3)
        Dim z3 As String = " y | " + Space(3)

        Dim z6 As String = " z | " + Space(3)

        n1 = CInt((Fix(b - a) / h1) + 1)
        n2 = CInt((Fix(d - c) / h2) + 1)

        x = a



        For i1 = 0 To n1

            y = c

            For i2 = 0 To n2

                col = col + 1
                z = z_fun(x, y)

                sum = sum + z

                coll = coll + Format(col, "000") + Space(2) + "|" + Space(2)
                z1 = z1 + Format(i1, "000") + Space(2) + "|" + Space(2)
                z2 = z2 + Format(x, "0.000") + Space(2) + "|" + Space(2)
                z3 = z3 + Format(y, "0.000") + Space(2) + "|" + Space(2)
                z6 = z6 + Format(z, "0.000") + Space(2) + "|" + Space(2)

                y = y + h2

            Next i2

            x = x + h1
            zzz = zzz + "________________________"

        Next i1


        ListBox1.Items.Add(zz)
        ListBox1.Items.Add(coll) 'coll общее кол-во точек
        ListBox1.Items.Add(zzz)

        ListBox1.Items.Add(zz)
        ListBox1.Items.Add(z1)  ' i - кол-во точек по первому циклу
        ListBox1.Items.Add(zzz)

        ListBox1.Items.Add(zz)
        ListBox1.Items.Add(z2)  ' x
        ListBox1.Items.Add(zzz)

        ListBox1.Items.Add(zz)
        ListBox1.Items.Add(z3)  ' y
        ListBox1.Items.Add(zzz)

        ListBox1.Items.Add(zz)
        ListBox1.Items.Add(z6)  ' z
        ListBox1.Items.Add(zzz)

        vivod(sum, TextBox7)
        vivodInt(col, TextBox8)


    End Sub


    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        Dim a, b, h1, c, d, h2 As Double
        ListBox1.Items.Clear()

        a = vvod(TextBox1)
        b = vvod(TextBox2)
        h1 = vvod(TextBox5)
        c = vvod(TextBox3)
        d = vvod(TextBox4)
        h2 = vvod(TextBox6)

        Cikl(a, b, h1, c, d, h2)

    End Sub



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

        TextBox7.Clear()
        TextBox8.Clear()

        ListBox1.Items.Clear()
    End Sub

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

End Class

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

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