viernes, 4 de noviembre de 2016

Ejercicio media de N calificaciones (Máximo 100)

Código:
Public Class Form1
    Dim VecCal() As Integer
    Dim fila As Integer = 0
    Dim S As Double
    Dim N As Integer
    Dim P As Double
    Dim C As Integer

    Private Sub GUARDAR()
        If N <= 100 Then
            N = TextBoxCant.Text
            ReDim VecCal(N - 1)
        End If
        If TextBox1.Text >= 0 And TextBox1.Text <= 10 Then
            If fila < N Then
                VecCal(fila) = CInt(TextBox1.Text)
                fila = fila + 1 'pasa a la siguiente posicion
                MsgBox("Se ha guardado tu calificacion", MsgBoxStyle.Information, MsgBoxStyle.OkOnly)
                TextBox1.Text = ""
                TextBox1.Focus()
            Else
                MsgBox("Base de datos llena")
            End If
        Else
            MsgBox("Calificacion no valida")
        End If

    End Sub

    Private Sub MEDIA()
        S = 0
        For I = 0 To 9
            S = S + VecCal(I)
        Next
        P = S / 10
        LabelPromedio.Text = P

    End Sub

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

    End Sub

    Private Sub ButtonGuardar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonGuardar.Click
        GUARDAR()


    End Sub

    Private Sub ButtonPromedio_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonPromedio.Click
        MEDIA()

    End Sub

    Private Sub ButtonLista_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonLista.Click
        For I = 0 To N - 1
            C = VecCal(I)
            ListBox1.Items.Add(C)
        Next
    End Sub

    Private Sub ButtonMenor_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonMenor.Click
        Array.Sort(VecCal)
        LabelMenor.Text = VecCal(0).ToString


    End Sub

    Private Sub ButtonMayor_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonMayor.Click
        Array.Sort(VecCal)
        LabelMayor.Text = VecCal(9).ToString

    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Me.Close()

    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click

    End Sub
End Class

Imagen Mostrando la Ejecucion




No hay comentarios:

Publicar un comentario