Parcial2 PHP:
1. Realice un progama en php, manejando por lo menos una funcion propiaque pida los datos de 10 Alumnos (Nombre, Sexo, Codigo, Nota1, Nota2, Nota3)
y que permita calcular la definitiva de cada alumno. cada nota tiene un %,
nota1 el 25%, nota2 el 35% y nota3 el 40%. use arreglos para almacenar la informacion.
Los nombres deben ser guardados en mayuscula (use una funcion de php para esto)
y debe mostrar la planilla de notas en pantalla.
SOLUCION
---------------------------------------------------------------------------------
<HTML>
<HEAD>
</HEAD>
<BODY>
<form action="notas.php" method="GET">
<?php
$x=1;
while($x<=10){
echo "Codigo". $x."<INPUT NAME='codigo".$x."' size='10'>Nombre". $x."<INPUT NAME='nombre".$x."' size='30'>Nota 1<INPUT NAME='prnota".$x."' size='2'>Nota 2<INPUT NAME='segnota".$x."' size='2'>Nota 3<INPUT NAME='ternota".$x."' size='2'><br>";
$x++;
}
?>
<input type="submit" name="boton" value="Calcular">
</FORM>
<?php
$nota_definitiva=array();
$nombres=array();
$nota1=array();
$nota2=array();
$nota3=array();
$codigos=array();
if($_GET["boton"]=="Calcular"){
$x=0;
while($x<10){
$y=$x+1;
$nombres[$x]=strtoupper($_GET["nombre$y"]);
$codigos[$x]=$_GET["codigo$y"];
$nota1[$x]=$_GET["prnota$y"];
$nota2[$x]=$_GET["segnota$y"];
$nota3[$x]=$_GET["ternota$y"];
$nota_definitiva[$x]=calcular_definitiva($nota1[$x],$nota2[$x],$nota3[$x]);
$x=$x+1;
}
echo "<table border=1><tr><TD>CODIGO</TD><TD>NOMBRE</TD><TD>NOTA1</TD><TD>NOTA2</TD><TD>NOTA3</TD><TD>DEFINITIVA</TD></TR>";
$x=0;
while($x<10){
$row="<tr><td>".$codigos[$x]."</td><td>".$nombres[$x]."</td><td>".$nota1[$x]."</td><td>".$nota2[$x]."</td><td>".$nota3[$x]."</td><td>".$nota_definitiva[$x]."</td></tr>";
echo $row;
$x++;
}
echo "</table>";
}
function calcular_definitiva($nota1,$nota2,$nota3){
$valor1 = ($nota1*25)/100;
$valor2 = ($nota2*35)/100;
$valor3 = ($nota3*40)/100;
$definitiva=$valor1+$valor2+$valor3;
//echo $valor1 ." ". $valor2." ". $valor3;
return $definitiva;
}
?>
</BODY>
</HTML>
No hay comentarios:
Publicar un comentario