You are on page 1of 15

UNIVERSIDAD NACIONAL ABIERTA Y A DISTANCIA ESCUELA DE CIENCIAS BSICAS, TECNOLOGA E INGENIERA ACT.

6 TRABAJO COLABORATIVO 1 PROGRAMACIN DE SISTIOS WEB

ACT. 6 TRABAJO COLABORATIVO I Vctor Julio Martnez Barrios C.C. 1 067 093 036

PROGRAMACIN DE SITIOS WEB TUTOR YHON JERSON ROBLES PUENTES

Universidad Nacional Abierta y a Distancia

Escuela de ciencias bsicas, tecnologa e ingeniera

Programacin de sitios web 2014

Vctor Julio Martnez Barrios C.C. 1 067 093 306

UNIVERSIDAD NACIONAL ABIERTA Y A DISTANCIA ESCUELA DE CIENCIAS BSICAS, TECNOLOGA E INGENIERA ACT. 6 TRABAJO COLABORATIVO 1 PROGRAMACIN DE SISTIOS WEB

INTRODUCCIN Este trabajo se presenta como evidencia de la apropiacin de los conceptos tericos y prcticos abordados durante el desarrollo de la primera unidad del curso programacin de sitios web PHP de la universidad nacional abierta y a distancia (UNAD) en el periodo 2014-I. En el mismo se estarn abarcando temas como configuracin del ambiente necesario para el desarrollo en php, construccin de scripts php y ejecucin de los mismos desde el servidor. Estos temas son tratados como parte del desarrollo de 3 ejercicios prcticos en los que se muestra la apropiacin de los conceptos estudiados, en el primer ejercicio se construye un script que perite el clculo del factorial de un nmero, en el segundo ejercicio se construye un script capaz de identificar si un nmero de tres cifras ingresado por el usuario es o no un nmero capica (Se lee igual de adelante hacia atrs y de atrs hacia adelante) por ultimo en el tercer ejercicio se desarrolla un script que debe permitir, a partir del ingreso de tres parmetros bsicos, la simulacin de un crdito bancario.

Vctor Julio Martnez Barrios C.C. 1 067 093 306

UNIVERSIDAD NACIONAL ABIERTA Y A DISTANCIA ESCUELA DE CIENCIAS BSICAS, TECNOLOGA E INGENIERA ACT. 6 TRABAJO COLABORATIVO 1 PROGRAMACIN DE SISTIOS WEB

OBJETIVOS

General Usar los conceptos estudiados durante el desarrollo de la primera unidad del curso programacin de sitios web PHP, para realizar la construccin de scripts que den solucin a problemas de aplicacin.

Especficos Aplicar lo visto en la primera unidad del curso programacin de sitios web PHP para realizar la instalacin y preparacin de un ambiente que permita el desarrollo de los ejercicios prcticos. Construir un script aplicando los conceptos vistos en la primera unidad del curso programacin de sitios web PHP, que permita el clculo de la factorial de un nmero. Construir un script aplicando los conceptos vistos en la primera unidad del curso programacin de sitios web PHP, que permita verificar si un nmero es o no capica Construir un script aplicando los conceptos vistos en la primera unidad del curso programacin de sitios web PHP, que permita simular el comportamiento de un crdito bancario.

Vctor Julio Martnez Barrios C.C. 1 067 093 306

UNIVERSIDAD NACIONAL ABIERTA Y A DISTANCIA ESCUELA DE CIENCIAS BSICAS, TECNOLOGA E INGENIERA ACT. 6 TRABAJO COLABORATIVO 1 PROGRAMACIN DE SISTIOS WEB

DESARROLLO

1. Calculo de la diferencial de un nmero ingresado por el usuario o determinar si el mismo es o no un nmero capica. Se tom la decisin de usar un solo script que realizara los dos ejercicios a escogencia del usuario, por tener mayor practicidad y eficiencia. 1.1. Cdigo fuente Script PHP <html> <head> <title> Trabajo colaborativo I: Programacion de sitios web PHP </title> <link rel="stylesheet" type="text/css" href="../css/styles.css" media="all"/> <script src="../js/exercises.js" type="text/javascript"></script> </head> <body> <form name="formcol1" method="post" action="exercises.php"> <input type="hidden" id="formAction" name="formAction"/> <table style="width:100%;"> <thead> <th colspan = "2">Registro de datos</th> </thead> <tbody> <tr> <td width="10%"> <label>Digite un numero: </td> </td> <td width="90%"> <input type="text" maxlength="3" id="txiNumber" name="txiNumber"/> </td> </tr> </tbody> </table> <div class="buttonContainer"> <ul> <li onclick="calcularFactorial();">Calcular factorial</li>

Vctor Julio Martnez Barrios C.C. 1 067 093 306

UNIVERSIDAD NACIONAL ABIERTA Y A DISTANCIA ESCUELA DE CIENCIAS BSICAS, TECNOLOGA E INGENIERA ACT. 6 TRABAJO COLABORATIVO 1 PROGRAMACIN DE SISTIOS WEB

<li onclick="comprobarCapicua();">Comprobar si es tapicua</li> <ul> </div> <?php if (isset($_POST["formAction"])){ $action=$_POST['formAction']; $numero=$_POST['txiNumber']; if( !is_int( intval($numero) ) ){ $mensaje="No has ingresado un numero valido! <br>"; }else{ $numero=intval($numero); if( $action=="F" ) factorial( $numero ); if( $action=="C" ) capicua( $numero ); } }else { showResult( "" ); } function factorial( $numero ) { $factorial=1; for($i=1; $i<=$numero; $i++) { $factorial*=$i; } $mensaje="El factorial es: ".$factorial; showResult( $mensaje ); } function capicua( $numero ) { $strnum=(string)$numero; $res=""; for($i=strlen($strnum)-1;$i>=0;$i--) { $res.=$strnum[$i]; } if( $res == $strnum )

Vctor Julio Martnez Barrios C.C. 1 067 093 306

UNIVERSIDAD NACIONAL ABIERTA Y A DISTANCIA ESCUELA DE CIENCIAS BSICAS, TECNOLOGA E INGENIERA ACT. 6 TRABAJO COLABORATIVO 1 PROGRAMACIN DE SISTIOS WEB

$mensaje=$numero." es un numero capicua"; else $mensaje=$numero." no es un numero capicua"; showResult( $mensaje ); } function showResult( $mensaje ) { echo "<div id=\"div_mensaje\">".$mensaje."</div>"; } ?> </form> </body> </html> JavaScript function sendForm() { try{ document.formcol1.submit(); }catch(e) { alert( "Error enviando los datos: "+e.message ); } }

function calcularFactorial() { try{ document.getElementById("formAction").value = "F"; sendForm(); }catch(e) { alert( "Error calculando factorial: "+e.message ); } } function comprobarCapicua() { try{
Vctor Julio Martnez Barrios C.C. 1 067 093 306

UNIVERSIDAD NACIONAL ABIERTA Y A DISTANCIA ESCUELA DE CIENCIAS BSICAS, TECNOLOGA E INGENIERA ACT. 6 TRABAJO COLABORATIVO 1 PROGRAMACIN DE SISTIOS WEB

document.getElementById("formAction").value = "C"; sendForm(); }catch(e) { alert( "Error comprobando capicua: "+e.message ); } }

1.2. Capturas de pantalla

Vctor Julio Martnez Barrios C.C. 1 067 093 306

UNIVERSIDAD NACIONAL ABIERTA Y A DISTANCIA ESCUELA DE CIENCIAS BSICAS, TECNOLOGA E INGENIERA ACT. 6 TRABAJO COLABORATIVO 1 PROGRAMACIN DE SISTIOS WEB

2. Script para la simulacin de un crdito. En este script el usuario podr registrar datos bsicos de un crdito como lo son el monto del crdito, tipo de crdito y tiempo en meses para el crdito, con esta informacin se genera un simulador detallado de las cuotas del crdito. 2.1. Cdigo fuente Script PHP <html> <head> <title>Trabajo colaborativo I: Programacion de sitios web PHP</title> <link rel="stylesheet" type="text/css" href="../css/styles.css" media="all"/> <script src="../js/creditos.js" type="text/javascript"></script> </head> <body> <form name="formcol1" method="post" action="creditos.php"> <table style="width:100%;"> <thead> <th colspan = "2">Simule su crdito</th> </thead> <tbody> <tr> <td width="10%"> <label>Monto del credito:</label> </td> <td width="90%"> <input type="text" maxlength="9" id="txiAmount" name="txiAmount"/> </td> </tr> <tr> <td width="10%"> <label>Tipo de credito:</label> </td> <td width="90%"> <input type="radio" id="rbtVivienda" name="rbtTipocredito" value="V" checked="true"/><label>Vivienda(1.0%)</label><br> <input type="radio" id="rbtVehiculo" name="rbtTipocredito" value="C"/><label>Vehiculo(1.3%)</label><br> <input type="radio" id="rbtLibreInv" name="rbtTipocredito" value="L"/><label>Libre inversin(2.3%)</label><br>
Vctor Julio Martnez Barrios C.C. 1 067 093 306

UNIVERSIDAD NACIONAL ABIERTA Y A DISTANCIA ESCUELA DE CIENCIAS BSICAS, TECNOLOGA E INGENIERA ACT. 6 TRABAJO COLABORATIVO 1 PROGRAMACIN DE SISTIOS WEB

</td> </tr> <tr> <td width="10%"> <label>Tiempo meses:</label> </td> <td width="90%"> <input maxlength="2" id="txiMonthTime" name="txiMonthTime"/> </td> </tr> </tbody> </table> en

type="text"

<div class="buttonContainer"> <ul> <li onclick="ejecutarSimulador();">Ejecutar simulador</li> <ul> </div> <?php if (isset($_POST["txiAmount"])){ $amount=$_POST["txiAmount"]; $creditType=$_POST["rbtTipocredito"]; $monthTime=$_POST["txiMonthTime"]; $taxrate=0; $porcentualTax=0; $interest=0; $balance=$amount; switch ($creditType) { case "V": $taxrate=1; break; case "C": $taxrate=1.3; break; case "L": $taxrate=2.3; break; } $porcentualTax = $taxrate/100;

Vctor Julio Martnez Barrios C.C. 1 067 093 306

UNIVERSIDAD NACIONAL ABIERTA Y A DISTANCIA ESCUELA DE CIENCIAS BSICAS, TECNOLOGA E INGENIERA ACT. 6 TRABAJO COLABORATIVO 1 PROGRAMACIN DE SISTIOS WEB

echo"<table style=\"width:100%;\">". "<thead>". "<tr>". "<th colspan = \"3\">Resultados</th>". "</tr>". "</thead>". "<tbody>". "<tr>". "<td>Monto del crdito: ".$amount."<td>". "</tr>". "<tr>". "<td>Tasa de interes: ".$taxrate."<td>". "</tr>". "<tr>". "<td>Tiempo en meses: ".$monthTime."<td>". "</tr>". "</tbody>". "</table>"; // Armando el detalle de las cuotas echo"<table style=\"width:100%;\">". "<thead>". "<tr>". "<th colspan = \"5\">Detalle de cuotas del credito</th>". "</tr>". "<tr>". "<th width=\"8%\">No. cuota</th>". "<th width=\"23%\">Pago mensual</th>". "<th width=\"23%\">Interes</th>". "<th width=\"23%\">Abono a capital</th>". "<th width=\"23%\">Saldo</th>". "</tr>". "</thead>". "<tbody>";

Vctor Julio Martnez Barrios C.C. 1 067 093 306

UNIVERSIDAD NACIONAL ABIERTA Y A DISTANCIA ESCUELA DE CIENCIAS BSICAS, TECNOLOGA E INGENIERA ACT. 6 TRABAJO COLABORATIVO 1 PROGRAMACIN DE SISTIOS WEB

$div = pow(1+$porcentualTax,$monthTime*-1 ) ) )/$porcentualTax; $monthPayment $amount/$div;

(1-( =

for( $i=1; $i<=$monthTime; $i++ ) { $class=""; if($i%2==0) $class="even"; else $class="odd"; $interest $balance*$porcentualTax; $abonocapital $monthPayment - $interest; $balance =$abonocapital; if($balance<0) $balance = 0; echo"<tr>". "<td class='".$class."' width=\"8%\">".$i."</td>". "<td class='".$class."' width=\"23%\">".round($monthPayment,2)."</td>". "<td class='".$class."' width=\"23%\">".round($interest,2)."</th>". "<td class='".$class."' width=\"23%\">".round($abonocapital,2)."</td>". "<td class='".$class."' width=\"23%\">".round($balance,2)."</td>". "</tr>"; } echo "</tbody></table>"; //$interest = ($amount*$taxrate)100; } ?> </form> = =

Vctor Julio Martnez Barrios C.C. 1 067 093 306

UNIVERSIDAD NACIONAL ABIERTA Y A DISTANCIA ESCUELA DE CIENCIAS BSICAS, TECNOLOGA E INGENIERA ACT. 6 TRABAJO COLABORATIVO 1 PROGRAMACIN DE SISTIOS WEB

</body> </html> JavaScript function ejecutarSimulador() { try{ if(validateForm()) document.formcol1.submit(); }catch(e) { alert( "Error ejecuntando el simulador: "+e.message ); } } function validateForm() { if( document.getElementById("txiAmount").value == "" ) { alert("Debe especificar un monto para el credito"); return false; }else{ if( isNaN( parseInt( document.getElementById("txiAmount").value ) ) ) { alert("El monto debe ser un valor numrico"); return false; } } if( document.getElementById("txiMonthTime").value == "" ) { alert("Debe especificar un tiempo en meses para el credito"); return false; }else{ if( isNaN( parseInt( document.getElementById("txiMonthTime").value ) ) ) {

Vctor Julio Martnez Barrios C.C. 1 067 093 306

UNIVERSIDAD NACIONAL ABIERTA Y A DISTANCIA ESCUELA DE CIENCIAS BSICAS, TECNOLOGA E INGENIERA ACT. 6 TRABAJO COLABORATIVO 1 PROGRAMACIN DE SISTIOS WEB

alert("El tiempo en meses debe ser un valor numrico"); return false; } } return true; } 2.2. Capturas de pantalla

Vctor Julio Martnez Barrios C.C. 1 067 093 306

UNIVERSIDAD NACIONAL ABIERTA Y A DISTANCIA ESCUELA DE CIENCIAS BSICAS, TECNOLOGA E INGENIERA ACT. 6 TRABAJO COLABORATIVO 1 PROGRAMACIN DE SISTIOS WEB

CONCLUSIONES Se pudo comprobar la facilidad del desarrollo en php y las grandes prestaciones que brinda. Pudo observarse la importancia de los ciclos en el desarrollo de scripts que permitan dar solucin a problemas de aplicacin Se profundizaron los conceptos estudiados en la unidad uno del mdulo del curso programacin de sitios web PHP.

Vctor Julio Martnez Barrios C.C. 1 067 093 306

UNIVERSIDAD NACIONAL ABIERTA Y A DISTANCIA ESCUELA DE CIENCIAS BSICAS, TECNOLOGA E INGENIERA ACT. 6 TRABAJO COLABORATIVO 1 PROGRAMACIN DE SISTIOS WEB

REFERENCIAS

Salazar, J. Puentes, O. Programacin de sitios web PHP: Mdulo del curso. Universidad Nacional Abierta y a Distancia, Facultad de ciencias bsicas e ingeniera. Manual de PHP (2014). Artculo de internet, recuperado el da 02 de abril de 2014 desde http://www.php.net/manual/es/.

Vctor Julio Martnez Barrios C.C. 1 067 093 306

You might also like