Pages

viernes, 25 de enero de 2013

Calcular el promedio de notas aprobadas y desaprobadas Codigo Fuente en Visual Basic

Problema
Hacer un programa o algoritmo que dado  N notas calcular el promedio de las notas aprobadas y el promedio de las notas desaprobadas.

Codigo Fuente en Visual Basic
Public Class Form1
    Dim N() As Integer
    Dim c As Integer = 0
    Dim t, nota, lon As Integer
    Dim ap As Integer = 0
    Dim de As Integer = 0
    Dim sumap As Double = 0
    Dim sumde As Double = 0
    Public Sub inicializar(ByVal tam As Integer)
        ReDim N(tam - 1)
        For i As Integer = 0 To (tam - 1)
            N(i) = 0
        Next i
    End Sub
    Private Sub Button1_Click(ByVal sender As System.Object,
    ByVal e As System.EventArgs) Handles Button1.Click
        lon = TextBox1.Text
        nota = TextBox2.Text
        If (lon <> c) Then
            If (nota >= 11) Then
                sumap = sumap + nota
                ap = ap + 1
            Else
                sumde = sumde + nota
                de = de + 1
            End If
            c = c + 1
        Else
            TextBox3.Text = "Promedio de Notas aprobadas : " +
            Trim(sumap / ap) + "  Promedio  de Notas desaprobadas : " +
            Trim(sumde / de)
        End If
    End Sub
    Private Sub TextBox1_TextChanged(ByVal sender As System.Object,
    ByVal e As System.EventArgs) Handles TextBox1.TextChanged
        t = TextBox1.Text
        inicializar(t)
    End Sub
End Class

0 comentarios:

Publicar un comentario en la entrada