Jump to content
oliveira1991

Formulas matemáticas

Recommended Posts

oliveira1991

:thumbsup: Boas Pessoal, preciso de uma ajuda vossa, terei que fazer umas formulas em vb.net, e queria confirmar com vocês se por acaso estou num bom caminho!

Public Function areaqquadrado(ByVal lado As Integer) As Double
	areaqquadrado = lado ^ 2
End Function

Public Function arearecatugulo(ByVal altura As Integer, ByVal base As Integer) As Integer
	arearecatugulo = base * altura
End Function

Public Function triangulo(ByVal base As Integer, ByVal altura As Integer) As Double
	triangulo = (base * altura) / 2
End Function

Public Function trapezio(ByVal basemaior As Integer, ByVal basemenor As Integer, ByVal altura As Integer) As Double
	trapezio = ((basemaior + basemenor) * altura) / 2
End Function

Public Function circulo(ByVal raio As Integer) As Double
	circulo = 3.14 * raio ^ 2
End Function

Public Function losango(ByVal diagonalmaior As Integer, ByVal diagonalmenor As Integer) As Double
	losango = (diagonalmaior * diagonalmenor) / 2
End Function

Quem poder ajudar agradecia, Obrigado!

Edited by oliveira1991

Live for ever

Share this post


Link to post
Share on other sites
ribeiro55

Ajudar em que?

Uns pequenos ajustes:

Public Function areaqquadrado(ByVal lado As Integer) As Double
       Return Math.Pow(lado, 2)
   End Function

   Public Function arearectangulo(ByVal base As Integer, ByVal altura As Integer) As Integer
       Return base * altura
   End Function

   Public Function triangulo(ByVal base As Integer, ByVal altura As Integer) As Double
       Return (base * altura) / 2
   End Function

   Public Function trapezio(ByVal basemaior As Integer, ByVal basemenor As Integer, ByVal altura As Integer) As Double
       Return ((basemaior + basemenor) * altura) / 2
   End Function

   Public Function circulo(ByVal raio As Integer) As Double
       Return Math.PI * Math.Pow(raio, 2)
   End Function

   Public Function losango(ByVal diagonalmaior As Integer, ByVal diagonalmenor As Integer) As Double
       Return (diagonalmaior * diagonalmenor) / 2
   End Function


Sérgio Ribeiro


"Great coders aren't born. They're compiled and released"
"Expert coders do not need a keyboard. They just throw magnets at the RAM chips"

Share this post


Link to post
Share on other sites
FreiNando

Uma advertência:

Em geometria deve sempre utilizar variáveis de virgula flutuante tipo Double, tanto para os parametros de entrada como para o retorno.

Deixo-te ainda mais uma variante para o calculo da area do triangulo:

Public Function AreaTringulo(Lado1 As Double, Lado2 As Double, Lado3 As Double) As Double
 'Teorema de Heron ou do Meio-perimetro
 Dim P As Double = (Lado1 + Lado2 + Lado3) / 2
 Dim A As Double = P * (P - Lado1) * (P - Lado2) * (P - Lado3)
 If A >= 0 Then
	 Return Math.Sqrt(A)
 Else
	 'erro.  Não é possível calcular raiz quadrada de um numero negativo.
	 'acontece se  algum dos lados for maior que os outros dois
	 Return -1
 End If
End Function


O caminho mais curto para conseguir fazer muitas coisas é fazer uma de cada vez. Samuel Smiles

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...

Important Information

By using this site you accept our Terms of Use and Privacy Policy. We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.