EJERCICIOS BÁSICOS MVC- MARTES

17
EJERCICIOS BÁSICOS 1. Realizar un pseudocódigo que solicite el nombre y el año de nacimiento y calcule la edad del usuario. ANÁLISIS: ENT RAD A PROCESO SALI DA n an e = 2010- an e DISEÑO: Implementación 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> VARIABLES n=nombre an=año de nacimiento. e= edad ac= año actual FORMULA EJEMPLO: E =2010-an e=2010-1991 e=19

Transcript of EJERCICIOS BÁSICOS MVC- MARTES

Page 1: EJERCICIOS BÁSICOS MVC- MARTES

EJERCICIOS BÁSICOS1. Realizar un pseudocódigo que solicite el nombre y el año de nacimiento y calcule la

edad del usuario.ANÁLISIS:

DISEÑO:

Implementación MVC en ASP.NET MVC

VISTAHome/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

@{

VARIABLESn=nombrean=año de nacimiento.e= edadac= año actual

FORMULA EJEMPLO:

E =2010-an e=2010-1991e=19

ENTRADA PROCESO SALIDAnan e = 2010-an e

Page 2: EJERCICIOS BÁSICOS MVC- MARTES

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/>Año de nacimiento: <inputtype="text"name="txtan"value="@ViewBag.an"/><br/><h1>Año 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")

CONTROLADORusing 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(); } }}

2. Realizar un pseudocódigo que calcule la media de tres números.

ANÁLISIS

Page 3: EJERCICIOS BÁSICOS MVC- MARTES

ENTRADA

PROCESO SALIDA

n1n2n3

r = (n1+n2+n3)/3

r

DISEÑO:

Implementación MVC en ASP.NET MVC

VISTAHome/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>

FORMULA Ejemplo:

r = (n1+n2+n3)/3 r = (4+5+4)/3 r = (9+4)3 r =(13)/3 r =4.333

VARIABLES

n1= primer numeron2= segundo numeron3= tercer numeror= resultado

Page 4: EJERCICIOS BÁSICOS MVC- MARTES

</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");

CONTROLADORHomeController.csusing 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 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(); } }}

3. Realizar un pseudocódigo que lea dos valores reales y nos muestre los resultados de sumar, restar, dividir y multiplicar.

Page 5: EJERCICIOS BÁSICOS MVC- MARTES

ENTRADA PROCESO SALIDAn1n2srdm

s=n1+n2

r=n1-n2

d=n1/n2

m=n1*n2

s

r

d

m

DISEÑO:

Implementación MVC en ASP.NET MVC

VISTAHome/OperacionesBasicas.cshtml@{ ViewBag.Title = "OperBasicas"; Layout = "~/Views/Shared/_Layout.cshtml";}

ANÁLISIS FORMULAS

s=n1+n2s=5+5s=10

r=n1-n2 r=5-5r=0

d=n1/n2 d=5/5d=1

m=n1*n2 m=5*5m=25

VARIABLESn1=primer numeron2=segundo numeros= suma r= restad= dividirm= multiplicar

Page 6: EJERCICIOS BÁSICOS MVC- MARTES

<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>

CONTROLADORHomeController.csusing 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(); } }}

4. Un departamento de climatología ha realizado recientemente su conversión del sistema métrico. Realizar un algoritmo o pseudocódigo de las siguientes conversiones.

Page 7: EJERCICIOS BÁSICOS MVC- MARTES

Leer la temperatura dada en la escala de Celsius y escribir en su equivalente Fahrenheit (la fórmula es). F =9/5 °C +32).

Leer la cantidad de agua en pulgadas y escribir su equivalente en milímetros. (25.5mm =1 pulgada).

°C a °F

Multiplica por 9, divide entre 5, después suma 32

ENTRADA PROCESO SALIDAce

fa

mili

pul

fa =9/5*c+32

mili =p*25.5

fa

mili

DISEÑO:

Implementación MVC en ASP.NET MVC

VISTAHome/Convercion.cshtml@{ ViewBag.Title = "Convercion"; Layout = "~/Views/Shared/_Layout.cshtml";}

<h2>Convercion</h2>

ANÁLISIS FORMULAS

fa=9/5*txtce+32fa= 9/5*25+32fa= 1.8*26+32fa=46.8+32fa=78.8

mili=p*25.5mili=15*25.5mili=382.5

VARIABLESce =Celsiusfa =Fahrenheitmili=milímetrospul = pulgadas

Page 8: EJERCICIOS BÁSICOS MVC- MARTES

<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");

CONTROLADORHomeController.csusing 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 Convercion() { return View(); } [HttpPost] public ActionResult Convercion(int txtce,int txtpul) { if (txtce > 0) { txtce = 0; ViewBag.fa = (txtce * 9) / 5 + 32;

Page 9: EJERCICIOS BÁSICOS MVC- MARTES

ViewBag.ce = txtce; } else { ViewBag.mili = txtpul * 25.5; ViewBag.pul = txtpul; } return View(); } }}

5. El costo de un automóvil nuevo para un comprador es la suma total del costo del vehículo, 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% en todas las unidades y un impuesto del 6% y diseñar un pseudocódigo para leer el costo total del automóvil y mostrar el costo para el consumidor.

DISEÑO:

Implementación MVC en ASP.NET MVC

VISTAHome/CostoAutomovil.cshtml@ { ViewBag.Title = "CostoAutomovil"; Layout = "~/Views/Shared/_Layout.cshtml";}

<h2>CostoAutomovil</h2><table><tr>

ANÁLISIS

VARIABLES

ctv= costo totalgb= ganancia vendedorim= impuestoscv= costo del vehículo

FORMULA

gb=cv*12/100

gv=10000*12/100gv=120000/100gv=1200

im =cv*6/100

im= 10000*6/100im= 60000/100im= 600

ctv=cv+gb+gb

ctv=10000+1200+600ctv=11200+600ctv=11800

ENTRADA PROCESO SALIDActv

gb

im

cv

gb=cv*12/100

im =cv*6/100

ctv=cv+gb+gb

ctv

Page 10: EJERCICIOS BÁSICOS MVC- MARTES

<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");

CONTROLADORHomeController.csusing 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 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(); } }}

6. Queremos conocer los datos estadísticos de una asignatura, por lo tanto, necesitamos un pseudocódigo que lea el número 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.

ANÁLISIS

Page 11: EJERCICIOS BÁSICOS MVC- MARTES

VARIABLESnsus=numero de suspensosna=numero aprobados nn=numero notablesnso= numero sobresalientespsup=porcentaje supero asignaturapsus=porcentaje suspensospa=porcentaje aprobadospn=porcentaje notablespsob=porcentaje sobresalientesta=total alumnos.ENTRADA PROCESO SALIDANsNa NtSob

ta=ns+nt+sob+napsus=nsus*100/tapn=nn*100/tapsob=nso*100/tapa=na*100/tapsup=(pn+pso+pa)*100/ta

PsusPnPsobPapsup

DISEÑO

Implementación MVC en ASP.NET MVC

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

FORMULAS

ta=ns+nt+sob+napsus=nsus*100/tapn=nn*100/tapsob=nso*100/tapa=na*100/tapsup=(pn+pso+pa)*100/ta

Page 12: EJERCICIOS BÁSICOS MVC- MARTES

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")

CONTROLADORHomeController.csusing 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 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;

Page 13: EJERCICIOS BÁSICOS MVC- MARTES

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 pseudocódigo que muestre el porcentaje descontado en una compra, introduciendo el precio de la tarifa y el precio pagado.

ENTRADA PROCESO SALIDAPdtp

Pd=(t-p)/t*100 pd

DISEÑO:

Implementación MVC en ASP.NET MVC

VISTAHome/DescuentoCompra.cshtml

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

ANÁLISIS

VARIABLESPd=porcentaje de descuentoT=tarifa P=pago FORMULA

Pd=(t-p)/t*100Pd=(20-15)/20*100Pd=5/20*100Pd=25*100Pd=25

Page 14: EJERCICIOS BÁSICOS MVC- MARTES

<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")

CONTROLADORHomeController.csusing 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 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(); } }}