Sei sulla pagina 1di 16

EJERCICIOS BSICOS

1. Realizar un pseudocdigo que solicite el nombre y el ao de nacimiento y calcule la edad del VARIABLES usuario. ANLISIS: n=nombre an=ao de nacimiento. e= edad ac= ao actual FORMULA EJEMPLO:

E =2010-an

e=2010-1991 e=19

ENTRADA n an

PROCESO

SALIDA

e = 2010-an

DISEO:

Implementacin MVC en ASP.NET MVC

VISTA
Home/Index.cshtml
@{ ViewBag.Title = "Index"; Layout = "~/Views/Shared/_Layout.cshtml"; } <h4>PAGINA PRINCIPAL DE HOME</h4>

<br/> <h2>PracticaEdad</h2> <br/> @Html.ActionLink("Calcular mi edad","PracticaEdad") <br/> @Html.ActionLink("Calcular sueldo quincenal","SQ") <br/> @Html.ActionLink("Ir a la vista de nuevo", "Index", "Nuevo") <br/> @Html.ActionLink("Ir a la vista de prueba", "Index", "Prueba")

Home/PracticaEdad.cshtml
@{ ViewBag.Title = "PracticaEdad"; Layout = "~/Views/Shared/_Layout.cshtml"; } <h2>CALCULAR EDAD</h2> <br/> <br/> <formmethod="post"> Nombre : <inputtype="text"name="txtn"value="@ViewBag.n"/> <br/> Ao de nacimiento: <inputtype="text"name="txtan"value="@ViewBag.an"/> <br/> <h1>Ao actual: 2012</h1> <br/> Edad: <inputtype="text"name="txte"value="@ViewBag.e"readonly="readonly"/> <br/> <inputtype="submit"value="calcular"/> </form> @Html.ActionLink("Volver al menu principal","Index")

CONTROLADOR
using System; usingSystem.Collections.Generic; usingSystem.Linq; usingSystem.Web; usingSystem.Web.Mvc; namespaceMvcCalcularEdad.Controllers { publicclassHomeController : Controller { // // GET: /HomeController/ publicActionResult Index() { return View(); } publicActionResultPracticaEdad() { return View();

} [HttpPost] publicActionResultPracticaEdad(stringtxtn, inttxtan) { Int edad = 2012 - txtan; ViewBag.n = txtn; ViewBag.an = txtan; ViewBag.e = edad; return View(); } } } 1. Realizar un pseudocdigo

que calcule la media de FORMULA ANLI tres nmeros. SIS r= (n1+n2+n3)/3

Ejemplo:

r = (4+5+4)/3 r = (9+4)3 r =(13)/3

VARIABLES

n1= primer numero ENTRADA n1 n2= segundo numero n2 n3= tercer n3 numero r= resultado

PROCESO

r =4.333 SALIDA

r = (n1+n2+n3)/3

DISEO:

Implementacin MVC en ASP.NET MVC

VISTA Home/Index.cshtml
@{ ViewBag.Title = "Index"; }

<h2>Menu Practicas</h2> <br /> <table border="1"> <tr> <td align="right">1: </td> <td>@Html.ActionLink("Calcular edad", "Edad")</td> </tr> <tr> <td align="right">2: </td><td>@Html.ActionLink("Media 3 Numeros","Media")</td> </tr> <tr> <td align="right">3: </td><td>@Html.ActionLink("Operaciones basicas", "OperBasicas")</td> </tr> <tr> <td align="right">4: </td><td>@Html.ActionLink("Convercion al sistema metrico","Convercion")</td> </tr> <tr> <td align="right">5: </td><td> @Html.ActionLink("Costo de automovil","CostoAutomovil")</td> </tr> <tr> <td align="right">6: </td><td>@Html.ActionLink("Datos estadisticos de asignatura","EstadisticaAsignatura")</td> </tr> <tr> <td align="right">7: </td><td>@Html.ActionLink("Porcentaje de descuento en compra", "DescuentoCompra") </td> </tr> </table>

Home/Media.cshtml
@{ ViewBag.Title = "Media"; Layout = "~/Views/Shared/_Layout.cshtml"; } <h2>Media de tres numeros</h2> <form method="post"> Numero 1: <input type="text" name="txtn1" value="@ViewBag.n1"/> <br /> Numero 2:<input type="text" name="txtn2" value="@ViewBag.n2"/> <br /> Numero 3:<input type="text" name="txtn3" value="@ViewBag.n3 "/> <br /> MEDIA <input type ="text" name="txtr" value="@ViewBag.r" readonly="readonly" /> <br /> <input type="submit" value="Calcular" /> </form> @Html.ActionLink("Ir a menu principal","Index");

CONTROLADOR
HomeController.cs
using using using using using System; System.Collections.Generic; System.Linq; System.Web; System.Web.Mvc;

namespace MvcPracticaTarea.Controllers { public class HomeController : Controller { // // GET: /Home/

public ActionResult Index() { return View(); } public ActionResult Media() { return View(); } [HttpPost] public ActionResult Media(int txtn1, int txtn2,int txtn3) { int med=(txtn1+txtn2+txtn3)/3; ViewBag.n1 = txtn1; ViewBag.n2 = txtn2; ViewBag.n3 = txtn3; ViewBag.r = med; return View(); } } }

1. Realizar un pseudocdigo que lea dos valores reales y nos muestre

los resultados de sumar, restar, FORMULAS dividir y multiplicar.


s=5+5 ANLI SIS VARIABLES s=n1+n2 s=10

n1=primer numero n2=segundo numero s= suma ENTRADA n1 resta r= n2 d= dividir s m= multiplicar r d m


s=n1+n2 r=n1-n2 d=n1/n2 m=n1*n2 m=n1*n2 r=n1-n2 r=5-5 r=0

PROCESO
d=n1/n2

SALIDA s

d=5/5 d=1

r d

m=5*5

m=25

DISEO:

Implementacin MVC en ASP.NET MVC

VISTA
Home/OperacionesBasicas.cshtml
@{ } <h2>OperBasicas</h2> <form method="post"> Numero 1: <input type="text" name="txtn1" value="@ViewBag.n1"/> <br /> Numero 2:<input type="text" name="txtn2" value="@ViewBag.n2"/> <br /> <hr /> <p>RESULADO</p> <hr /> SUMA: <input type ="text" name="txts" value="@ViewBag.s" readonly="readonly" /> RESTA: <input type ="text" name="txtr" value="@ViewBag.r" readonly="readonly" /> MULTIPLICACION: <input type ="text" name="txtm" value="@ViewBag.m" readonly="readonly" /> DIVICION: <input type ="text" name="txtd" value="@ViewBag.d" readonly="readonly" /> <br /> <input type="submit" value="Calcular" /> </form> ViewBag.Title = "OperBasicas"; Layout = "~/Views/Shared/_Layout.cshtml";

CONTROLADOR
HomeController.cs
using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.Mvc; namespace MvcPracticaTarea.Controllers

{ public class HomeController : Controller { // // GET: /Home/ public ActionResult Index() { return View(); } public ActionResult OperBasicas() { return View(); } [HttpPost] public ActionResult OperBasicas(double txtn1, double txtn2) { ViewBag.s = txtn1 + txtn2; ViewBag.r = txtn1 - txtn2; ViewBag.m = txtn1 * txtn2; ViewBag.d = txtn1 / txtn2; ViewBag.n1 = txtn1; ViewBag.n2 = txtn2; return View(); } } }

1. Un departamento de climatologa ha realizado recientemente su conversin del sistema mtrico. Realizar un algoritmo o pseudocdigo de las siguientes conversiones. Leer la temperatura dada en la escala de Celsius y escribir en su equivalente Fahrenheit (la frmula es). F =9/5 C +32). Leer la cantidad de agua en pulgadas y escribir su equivalente en milmetros. (25.5mm =1 pulgada). ANLISI S VARIABLES ce =Celsius fa =Fahrenheit mili=milmetros pul = pulgadas mili=p*25.5 FORMULAS fa= 9/5*25+32 fa=9/5*txtce+32 fa= 1.8*26+32 fa=46.8+32 fa=78.8 mili=15*25.5 mili=382.5

C a F ENTRADA ce fa mili pul

Multiplica por 9, divide entre 5, despus suma 32 PROCESO SALIDA

fa =9/5*c+32 mili =p*25.5

fa mili

DISEO:

Implementacin MVC en ASP.NET MVC

VISTA
Home/Convercion.cshtml
@{ ViewBag.Title = "Convercion"; Layout = "~/Views/Shared/_Layout.cshtml"; } <h2>Convercion</h2> <table> <tr> <td> <h3>Celcius a Fahrenheit</h3> <form method="post"> CELCIUS: <input type="text" name="txtce" value="@ViewBag.ce"/> <br /> <input type="submit" value="Convertir" /> <br /> FAHRENHEIT:<input type="text" name="txtfa" value="@ViewBag.fa " readonly="readonly" /> </form> </td> </tr> <tr> <td> <h3>Pulgadas a Milimetros</h3> <form method="post">

PULGADAS: <input type="text" name="txtpul" value="@ViewBag.pul"/> <br /> <input type="submit" value="Convertir" /> <br /> MILIMETROS:<input type="text" name="txtmili" value="@ViewBag.mili" readonly="readonly" /> </form> </td> </tr> </table> @Html.ActionLink("Ir a menu principal","Index");

CONTROLADOR
HomeController.cs
using using using using using System; System.Collections.Generic; System.Linq; System.Web; System.Web.Mvc;

namespace MvcPracticaTarea.Controllers { public class HomeController : Controller { // // GET: /Home/ public ActionResult Index() { return View(); } public ActionResult Convercion() { return View(); } [HttpPost] public ActionResult Convercion(int txtce,int txtpul) { if (txtce > 0) { txtce = 0; ViewBag.fa = (txtce * 9) / 5 + 32; ViewBag.ce = txtce; } else { ViewBag.mili = txtpul * 25.5; ViewBag.pul = txtpul; } return View(); } } }

1. El costo de un automvil nuevo para un comprador es la suma total del costo del vehculo, del porcentaje de la ganancia del vendedor y de los impuestos locales o estatales aplicables (sobre el precio de venta). Suponer una ganancia del vendedor del 12%

ANLISI S

en todas las unidades y un impuesto del 6% y disear un pseudocdigo para leer el costo total del automvil y mostrar el costo para el consumidor. VARIABLES FORMULA ctv= costo total gb= vendedor ENTRADA ganancia gb=cv*12/100 PROCESO gb=cv*12/100 delim =cv*6/100 im =cv*6/100 ctv=cv+gb+gb gv=10000*12/100 gv=120000/100 gv=1200 SALIDA im= 10000*6/100 im= 60000/100 ctv im= 600 ctv=10000+1200+6 00 ctv=cv+gb+gb ctv=11200+600 ctv=11800

im= impuestos ctv cv= costo gb vehculo im cv

DISEO:

Implementacin MVC en ASP.NET MVC

VISTA
Home/CostoAutomovil.cshtml
@{ ViewBag.Title = "CostoAutomovil"; Layout = "~/Views/Shared/_Layout.cshtml"; } <h2>CostoAutomovil</h2> <table> <tr> <td> <form method="post"> COSTO AUTOMOVIL: <input type="text" name="txtcv" value="@ViewBag.cv"/> <br />

COSTO TOTAL AUTOMOVIL: <input type="text" name="txtctv" value="@ViewBag.ctv" readonly="readonly"/> <input type="submit" value="Calcular" /> <br /> </form> </td> </tr> </table> @Html.ActionLink("Ir a menu principal","Index");

CONTROLADOR
HomeController.cs
using using using using using System; System.Collections.Generic; System.Linq; System.Web; System.Web.Mvc;

namespace MvcPracticaTarea.Controllers { public class HomeController : Controller { // // GET: /Home/ public ActionResult Index() { return View(); } public ActionResult CostoAutomovil() { return View(); } [HttpPost] public ActionResult CostoAutomovil(int txtcv) { int gb=txtcv*12/100; int im=txtcv*6/100; ViewBag.ctv=txtcv+gb+im; ViewBag.cv=txtcv; return View(); } } }

1. Queremos conocer los datos estadsticos de una asignatura, por lo tanto, necesitamos un pseudocdigo que lea el nmero de suspensos, aprobados, notables y sobresalientes de una asignatura, y nos devuelva : a) El tanto por ciento de alumnos que han superado la asignatura. b) El tanto por ciento de suspensos, aprobados, notables y sobresalientes de la asignatura. ANLISI S VARIABLES

nsus=numero de suspensos na=numero aprobados nn=numero notables nso= numero sobresalientes psup=porcentaje supero asignatura psus=porcentaje suspensos pa=porcentaje aprobados pn=porcentaje notables psob=porcentaje sobresalientes ta=total alumnos.

FORMULAS

ta=ns+nt+sob+na psus=nsus*100/ta pn=nn*100/ta psob=nso*100/ta pa=na*100/ta psup=(pn+pso+pa)*100/ta

ENTRADA Ns Na Nt Sob

PROCESO ta=ns+nt+sob+na psus=nsus*100/ta pn=nn*100/ta psob=nso*100/ta pa=na*100/ta psup=(pn+pso+pa)*100/ta

SALIDA Psus Pn Psob Pa psup

DISEO

Implementacin MVC en ASP.NET MVC

VISTA
Home/EstadisticaAsignatura.cshtml
@{ ViewBag.Title = "EstadisticaAsignatura"; Layout = "~/Views/Shared/_Layout.cshtml"; } <h2>EstadisticaAsignatura</h2> <table> <tr> <td> <form method="post"> NUMERO DE SUSPENSOS: <input type="text" name="txtnsus" value="@ViewBag.nsus"/> <br /> NUMERO DE APROBADOS: <input type="text" name="txtna" value="@ViewBag.na"/> <br /> NUMERO DE NOTABLES: <input type="text" name="txtnn" value="@ViewBag.nn"/> <br />

NUMERO DE SOBRESALIENTES: <input type="text" name="txtnso" value="@ViewBag.nso"/> <hr style="background-color" /> % ALUMNOS QUE SUPERARON LA ASIGNATURA: <input type="text" name="txtpsup" value="@ViewBag.psup" readonly="readonly"/> <br /> % SUSPENSOS: <input type="text" name="txtpsus" value="@ViewBag.psus" readonly="readonly"/> <br /> % APROBADOS: <input type="text" name="txtpa" value="@ViewBag.pa" readonly="readonly"/> <br /> % NOTABLES: <input type="text" name="txtpn" value="@ViewBag.pn" readonly="readonly"/> <br /> % SOBRESALIENTES: <input type="text" name="txtpsob" value="@ViewBag.psob" readonly="readonly"/> <br /> <input type="submit" value="Calcular" /> <br /> </form> </td> </tr> </table> @Html.ActionLink("Ir al menu principal","Index")

CONTROLADOR
HomeController.cs
using using using using using System; System.Collections.Generic; System.Linq; System.Web; System.Web.Mvc;

namespace MvcPracticaTarea.Controllers { public class HomeController : Controller { // // GET: /Home/ public ActionResult Index() { return View(); } public ActionResult EstadisticaAsignatura() { return View(); } [HttpPost] public ActionResult EstadisticaAsignatura(int txtnsus,int txtna,int txtnn,int txtnso) { int ta = txtnsus + txtnn + txtnso + txtna; int psus=(txtnsus * 100) / ta; int pn=(txtnn * 100 )/ ta; int psob = (txtnso * 100 )/ ta; int pa = (txtna * 100 )/ ta; //-----------------------------------------------ViewBag.psus = psus; ViewBag.pn = pn; ViewBag.psob = psob; ViewBag.pa =pa;

ViewBag.psup=((txtnn+txtnso+txtna)*100)/ta; //----------------------------------------------ViewBag.nsus = txtnsus; ViewBag.na = txtna; ViewBag.nn = txtnn; ViewBag.nso = txtnso; return View(); } } }

Realizar un pseudocdigo que muestre el porcentaje descontado en una compra, introduciendo el precio de VARIABLES la tarifa y el precio pagado. ANLI Pd=porcentaje de descuento SIS T=tarifa P=pago ENTRADA Pd t p Pd=(t-p)/t*100 Pd=(t-p)/t*100 PROCESO FORMULA SALIDA Pd=(20-15)/20*100 Pd=5/20*100 Pd=25*100 Pd=25 pd

DISEO:

Implementacin MVC en ASP.NET MVC

VISTA
Home/DescuentoCompra.cshtml
@{ ViewBag.Title = "DescuentoCompra"; Layout = "~/Views/Shared/_Layout.cshtml"; } <h2>DescuentoCompra</h2> <table> <tr> <td> <form method="post">

TARIFA PRODUCTO: <input type="text" name="txtt" value="@ViewBag.t"/> <br /> TOTAL PAGADO: <input type="text" name="txtp" value="@ViewBag.p"/> <br /> <input type="submit" value="Calcular" /> <br /> EL PORCENTAJE DESCONTADO ES: <input type="text" name="txtpd" value="@ViewBag.pd" readonly="readonly"/> % <br /> </form> </td> </tr> </table> @Html.ActionLink("Ir al menu principal","Index")

CONTROLADOR
HomeController.cs
using using using using using System; System.Collections.Generic; System.Linq; System.Web; System.Web.Mvc;

namespace MvcPracticaTarea.Controllers { public class HomeController : Controller { // // GET: /Home/ public ActionResult Index() { return View(); } public ActionResult DescuentoCompra() { return View(); } [HttpPost] public ActionResult DescuentoCompra(double txtt, double txtp) { ViewBag.pd =(txtt - txtp) / txtt * 100; ViewBag.t = txtt; ViewBag.p = txtp; return View(); } } }

Potrebbero piacerti anche