Veredito sobre a media final de um grupo de alunos (considerando REC) - versao 2
1. Construa uma função (Func) que recebe como parâmetros quatro notas, respectivamente de P1, P2, T1 e T2 e devolve a média correspondente a essas notas.
2. Construa um procedimento (Sub) que recebe como parâmetro o número de uma linha da planilha, captura a média do aluno da coluna apropriada DAQUELA LINHA e insere na coluna apropriada o veredito final sobre o aluno.
3. Construa um procedimento (Sub), SEM PARÂMETROS, que captura da planilha a quantidade de alunos de uma turma e, para cada aluno, utiliza a função e o procedimento anteriores para calcular as médias e os vereditos para todos os alunos.
Function calcmedia(linha As Integer) As Double
Dim p1, p2, t1, t2, media As Double
p1 = Cells(linha, 1)
p2 = Cells(linha, 2)
t1 = Cells(linha, 3)
t2 = Cells(linha, 4)
media = (Sqr(p1 * t1) + Sqr(p2 * t2)) / 2
calcmedia = media
End Function
Sub veredito(linha As Integer)
Dim media As Double
media = Cells(linha, 5)
If media >= 5 Then
Cells(linha, 6) = "passou"
ElseIf media >= 3 Then
Cells(linha, 6) = "REC"
Else
Cells(linha, 6) = "reprovado"
End If
End Sub
Sub calculaTodos()
Dim i As Integer
Dim quant As Integer
quant = Cells(1, 6)
i = 2
Do While i <= quant + 1
Cells(i, 5) = calcmedia(i)
veredito (i)
i = i + 1
Loop
End Sub
Dim p1, p2, t1, t2, media As Double
p1 = Cells(linha, 1)
p2 = Cells(linha, 2)
t1 = Cells(linha, 3)
t2 = Cells(linha, 4)
media = (Sqr(p1 * t1) + Sqr(p2 * t2)) / 2
calcmedia = media
End Function
Sub veredito(linha As Integer)
Dim media As Double
media = Cells(linha, 5)
If media >= 5 Then
Cells(linha, 6) = "passou"
ElseIf media >= 3 Then
Cells(linha, 6) = "REC"
Else
Cells(linha, 6) = "reprovado"
End If
End Sub
Sub calculaTodos()
Dim i As Integer
Dim quant As Integer
quant = Cells(1, 6)
i = 2
Do While i <= quant + 1
Cells(i, 5) = calcmedia(i)
veredito (i)
i = i + 1
Loop
End Sub