Difference between revisions of "Desenvolvimento de Ambiente Web (FAZAG 2008.2): Correção da Prova II"
From AdonaiMedrado.Pro.Br
(New page: == Questão única == === Resposta em PHP === <code lang="html"> <html> <head> <title>Prova</title> </head> <body> <form action="index.php" method="POST"> <input type="text" name=...) |
(→Resposta em JSP) |
||
(3 intermediate revisions by the same user not shown) | |||
Line 1: | Line 1: | ||
+ | A prova está disponível para download no seguinte endereço: http://www.adonaimedrado.pro.br/wiki/documentos/professor/FAZAG_2008_2_DEV_WEB_PROVA_2.pdf. | ||
+ | |||
== Questão única == | == Questão única == | ||
+ | Esta questão podia ser desenvolvida em Java (JSP), PHP ou C# (ASP.NET). Como nenhum aluno tentou responder em ASP.NET, seguem somente as soluções em PHP e JSP. | ||
+ | |||
=== Resposta em PHP === | === Resposta em PHP === | ||
+ | O código abaixo atende perfeitamente ao solicitado, respostas que não utilizavam funções também eram possíveis e aceitas. | ||
+ | |||
<code lang="html"> | <code lang="html"> | ||
<html> | <html> | ||
Line 48: | Line 54: | ||
?> | ?> | ||
</body> | </body> | ||
+ | </html> | ||
+ | </code> | ||
+ | |||
+ | === Resposta em JSP === | ||
+ | |||
+ | A resposta apresentada abaixo é adaptada da que foi apresentada por um aluno. | ||
+ | |||
+ | <code lang="html"> | ||
+ | <html> | ||
+ | <head> | ||
+ | <title>Prova</title> | ||
+ | </head> | ||
+ | <body> | ||
+ | <% | ||
+ | String valor = "valor inválido"; | ||
+ | String resultado = null; | ||
+ | int intvalor = 0; | ||
+ | int valor_resultado = 0; | ||
+ | float valor_resto = 0; | ||
+ | if (request.getParameter("valor")!=null) | ||
+ | { | ||
+ | valor = request.getParameter("valor"); | ||
+ | if (valor.equals("um")) | ||
+ | intvalor=1; | ||
+ | if (valor.equals("dois")) | ||
+ | intvalor=2; | ||
+ | if (valor.equals("três")) | ||
+ | intvalor=3; | ||
+ | if (valor.equals("quatro")) | ||
+ | intvalor=4; | ||
+ | if (valor.equals("cinco")) | ||
+ | intvalor=5; | ||
+ | if (valor.equals("seis")) | ||
+ | intvalor=6; | ||
+ | if (valor.equals("sete")) | ||
+ | intvalor=7; | ||
+ | if (valor.equals("oito")) | ||
+ | intvalor=8; | ||
+ | if (valor.equals("nove")) | ||
+ | intvalor=9; | ||
+ | if (valor.equals("dez")) | ||
+ | intvalor=10; | ||
+ | |||
+ | valor_resultado = intvalor; | ||
+ | for (int i = 2; i<intvalor; i++) | ||
+ | valor_resultado *= i; | ||
+ | valor_resto = valor_resultado % 21; | ||
+ | } | ||
+ | %> | ||
+ | <form action = "index.jsp" name="frmFatorial" method="post"> | ||
+ | <input type="text" name="valor" value="<% if (request.getParameter("valor")!=null) out.print(valor); %>">(1-10 por extenso)<input type="submit" value="Executar Cálculo" name="btCalcular"> | ||
+ | <input type="text" value="<% if (request.getParameter("valor")!=null) out.print(valor_resto); %>"> | ||
+ | <% if (request.getParameter("valor")!=null) out.print("Fatorial: " + valor_resultado); %> | ||
+ | </form> | ||
+ | </body> | ||
</html> | </html> | ||
</code> | </code> |
Latest revision as of 15:18, 8 December 2008
A prova está disponível para download no seguinte endereço: http://www.adonaimedrado.pro.br/wiki/documentos/professor/FAZAG_2008_2_DEV_WEB_PROVA_2.pdf.
Questão única
Esta questão podia ser desenvolvida em Java (JSP), PHP ou C# (ASP.NET). Como nenhum aluno tentou responder em ASP.NET, seguem somente as soluções em PHP e JSP.
Resposta em PHP
O código abaixo atende perfeitamente ao solicitado, respostas que não utilizavam funções também eram possíveis e aceitas.
<html> <head> <title>Prova</title> </head> <body> <form action="index.php" method="POST"> <input type="text" name="txtEntrada" value="<?php if (count($_POST) != 0) echo $_POST["txtEntrada"]; ?>"/> <input type="submit" name="btExecutar" value="Executar Cálculo" /> <input type="text" name="txtSaida" value="<?php if (count($_POST) != 0) echo CalcularResto(); ?>"/> <?php if (count($_POST) != 0) echo "Fatorial: ".CalcularFatorial(); ?> </form> <?php function ConverterParaInteiro($str) { switch($str) { case "um": return 1; case "dois": return 2; case "três": return 3; case "quatro": return 4; case "cinco": return 5; case "seis": return 6; case "sete": return 7; case "oito": return 8; case "nove": return 9; case "dez": return 10; } } function Fatorial($num) { if ($num!=1) return $num * Fatorial($num-1); else return 1; } function CalcularFatorial() { return Fatorial(ConverterParaInteiro(strtolower($_POST["txtEntrada"]))); } function CalcularResto() { return CalcularFatorial()%21; } ?> </body> </html>
Resposta em JSP
A resposta apresentada abaixo é adaptada da que foi apresentada por um aluno.
<html> <head> <title>Prova</title> </head> <body> <% String valor = "valor inválido"; String resultado = null; int intvalor = 0; int valor_resultado = 0; float valor_resto = 0; if (request.getParameter("valor")!=null) { valor = request.getParameter("valor"); if (valor.equals("um")) intvalor=1; if (valor.equals("dois")) intvalor=2; if (valor.equals("três")) intvalor=3; if (valor.equals("quatro")) intvalor=4; if (valor.equals("cinco")) intvalor=5; if (valor.equals("seis")) intvalor=6; if (valor.equals("sete")) intvalor=7; if (valor.equals("oito")) intvalor=8; if (valor.equals("nove")) intvalor=9; if (valor.equals("dez")) intvalor=10; valor_resultado = intvalor; for (int i = 2; i<intvalor; i++) valor_resultado *= i; valor_resto = valor_resultado % 21; } %> <form action = "index.jsp" name="frmFatorial" method="post"> <input type="text" name="valor" value="<% if (request.getParameter("valor")!=null) out.print(valor); %>">(1-10 por extenso)<input type="submit" value="Executar Cálculo" name="btCalcular"> <input type="text" value="<% if (request.getParameter("valor")!=null) out.print(valor_resto); %>"> <% if (request.getParameter("valor")!=null) out.print("Fatorial: " + valor_resultado); %> </form> </body> </html>