Levalgo

Page 1

2015 Metodolog铆a de la Programaci贸n

Luis Eduardo Vallejo UMAD 27/11/2015


Contenido 1-AREAS CON IF ................................................................................................................................... 6 Diagrama ......................................................................................................................................... 6 Rational ........................................................................................................................................... 7 Prueba ............................................................................................................................................. 7 Codigo ............................................................................................................................................. 7 2-Areas con Switch ............................................................................................................................ 11 Diagrama ....................................................................................................................................... 11 Rational ......................................................................................................................................... 13 Prueba ........................................................................................................................................... 14 Codigo ........................................................................................................................................... 14 Corrida ........................................................................................................................................... 14 3-Edades con Switch ......................................................................................................................... 16 Diagrama ....................................................................................................................................... 16 Rational ......................................................................................................................................... 18 Prueba ........................................................................................................................................... 18 Codigo ........................................................................................................................................... 18 Corrida ........................................................................................................................................... 18 4-Llamada telef贸nica usando dos variables ...................................................................................... 21 Diagrama ....................................................................................................................................... 21 Rational ......................................................................................................................................... 22 Prueba ........................................................................................................................................... 22 Codigo ........................................................................................................................................... 22 Corrida ........................................................................................................................................... 22 5- Tablas de multiplicar for ascendente ............................................................................................ 24 Diagrama ....................................................................................................................................... 24 Rational ......................................................................................................................................... 24 Prueba ........................................................................................................................................... 25 Codigo ........................................................................................................................................... 25 Corrida ........................................................................................................................................... 25 6- Tablas de multiplicar descendente ............................................................................................... 27 Diagrama ....................................................................................................................................... 27


Rational ......................................................................................................................................... 27 Prueba ........................................................................................................................................... 28 Codigo ........................................................................................................................................... 28 Corrida ........................................................................................................................................... 30 7-Alumnos con Beca .......................................................................................................................... 30 Diagrama ....................................................................................................................................... 30 Rational ......................................................................................................................................... 31 Prueba ........................................................................................................................................... 31 Codigo ........................................................................................................................................... 31 Corrida ........................................................................................................................................... 36 8- NĂşmeros pares e impares ............................................................................................................. 36 Diagrama ....................................................................................................................................... 36 Rational ......................................................................................................................................... 37 Prueba ........................................................................................................................................... 38 Codigo ........................................................................................................................................... 38 Corrida ........................................................................................................................................... 41 9-Numeros Pares e Impares For........................................................................................................ 42 Diagrama ....................................................................................................................................... 42 Racional ......................................................................................................................................... 43 Prueba ........................................................................................................................................... 43 Codigo ........................................................................................................................................... 43 10-Edades con For ............................................................................................................................. 47 Diagrama ....................................................................................................................................... 47 Prueba ........................................................................................................................................... 48 Codigo ........................................................................................................................................... 48 Corrida ........................................................................................................................................... 51 11- Llamadas minutos segundos Do-while........................................................................................ 52 Diagrama ....................................................................................................................................... 52 Prueba ........................................................................................................................................... 53 Corrida ........................................................................................................................................... 53 Codigo ........................................................................................................................................... 53 Racional ......................................................................................................................................... 56


12- Calificaciones A, B y C.................................................................................................................. 57 Diagrama ....................................................................................................................................... 57 Prueba ........................................................................................................................................... 58 Corrida ........................................................................................................................................... 58 Rational ......................................................................................................................................... 59 13-Areas con do-While ...................................................................................................................... 61 Diagrama ....................................................................................................................................... 61 Prueba ........................................................................................................................................... 62 Corrida ........................................................................................................................................... 62 Codigo ........................................................................................................................................... 62 Racional ......................................................................................................................................... 67 14- Frutas con do-While .................................................................................................................... 67 Diagrama ....................................................................................................................................... 67 Prueba ........................................................................................................................................... 68 Corrida ........................................................................................................................................... 68 Codigo ........................................................................................................................................... 68 Racional ......................................................................................................................................... 72 15-Verificacion con Do-while ............................................................................................................ 73 Prueba ........................................................................................................................................... 74 Corrida ........................................................................................................................................... 74 Codigo ........................................................................................................................................... 74 Racional ......................................................................................................................................... 81 16-Verificacion con For ..................................................................................................................... 82 Prueba ........................................................................................................................................... 83 Corrida ........................................................................................................................................... 84 Codigo ........................................................................................................................................... 84 Racional ......................................................................................................................................... 87 17-Inventario con do-While .............................................................................................................. 88 Prueba ........................................................................................................................................... 88 Codigo ........................................................................................................................................... 88 18- Caseta con for ............................................................................................................................. 94 Prueba ........................................................................................................................................... 97


Corrida ........................................................................................................................................... 97 Codigo ........................................................................................................................................... 97 Raciona ........................................................................................................................................ 102 Caseta con Do-While ....................................................................................................................... 103 Diagrama ..................................................................................................................................... 103 Prueba ......................................................................................................................................... 104 Codigo ......................................................................................................................................... 104 Racional ....................................................................................................................................... 106 20- Caseta con do-While ................................................................................................................ 107 Diagrama ..................................................................................................................................... 107 Prueba ......................................................................................................................................... 108 Corrida ......................................................................................................................................... 108 Codigo ......................................................................................................................................... 108 Racional ....................................................................................................................................... 111 21-Caseta con While ....................................................................................................................... 112 Diagrama ..................................................................................................................................... 112 Prueba ......................................................................................................................................... 112 Corrida ......................................................................................................................................... 113 Codigo ......................................................................................................................................... 113 Racional ....................................................................................................................................... 116 22-Metodo .................................................................................................................................. 116 Diagrama ..................................................................................................................................... 116 Prueba ......................................................................................................................................... 117 Corrida ......................................................................................................................................... 117 Codigo ......................................................................................................................................... 117 Racional ....................................................................................................................................... 122


1-AREAS CON IF Diagrama


Rational

Prueba

Codigo using System; using System.Collections.Generic;


using System.Linq; using System.Text; using System.Threading.Tasks; namespace Areas_con_ifs { class Program { static void Main(string[] args) { //DECLARACION DE VARIABLES

int figura = 0; int lado = 0; int BaseFigura = 0; int altura = 0; string leer; //FIN DE VARIABLES

Console.WriteLine("Elige un número para calcular el área de: \n 1.- Cuadrado \n 2.- Rectángulo \n 3.- Triángulo "); leer = Console.ReadLine(); figura = Convert.ToInt32(leer); if (figura <= 0 || figura > 3) Console.WriteLine("Ingresaste un número inválido"); else if (figura == 1) {//INICIO IF Console.WriteLine("Ingresa la base"); leer = Console.ReadLine(); lado = Convert.ToInt32(leer); if (lado <= 0) Console.WriteLine("Ingresaste un número incorrecto"); else Console.WriteLine("El área de tu cuadrado es: {0}", lado * lado); }//FIN IF FIGURA 1 else if (figura == 2) {//INICIO IF FIGURA 2 Console.WriteLine("Ingresa la base"); leer = Console.ReadLine(); BaseFigura = Convert.ToInt32(leer);

\n


Console.WriteLine("Ingresa la altura"); leer = Console.ReadLine(); altura = Convert.ToInt32(leer); if (BaseFigura <= 0 || altura <= 0) Console.WriteLine("Ingresaste un número inválido"); else

Console.WriteLine("El área de tu rectángulo es: {0}", BaseFigura * altura); }//FIN IF FIGURA 2 else Console.WriteLine("Ingresa la base de tu triángulo."); leer = Console.ReadLine(); BaseFigura = Convert.ToInt32(leer);

Console.WriteLine("Ingresa la altura"); leer = Console.ReadLine(); altura = Convert.ToInt32(leer); if (BaseFigura <= 0 || altura <= 0) Console.WriteLine("Ingresaste un número inválido"); else Console.WriteLine("El área de tu rectángulo es: {0}", (BaseFigura * altura) / 2 ); Console.ReadKey(); } } }


Corrida


2-Areas con Switch Diagrama



Rational


Prueba

Codigo using using using using using

System; System.Collections.Generic; System.Linq; System.Text; System.Threading.Tasks;

namespace Areas_con_switch { class Program { static void Main(string[] args) { //DECLARACION DE VARIABLES

int figura = 0; int lado = 0; int BaseFigura = 0; int altura = 0; string leer; //FIN DE VARIABLES

Console.WriteLine("Elige un número para calcular el área de: \n 1.- Cuadrado \n 2.- Rectángulo \n 3.- Triángulo ");

\n


leer = Console.ReadLine(); figura = Convert.ToInt32(leer);

switch (figura) {//INICIO SWITCH case 1: Console.WriteLine("Ingresa la base"); leer = Console.ReadLine(); lado = Convert.ToInt32(leer); if (lado <= 0) Console.WriteLine("Ingresaste un número incorrecto"); else Console.WriteLine("El área de tu cuadrado es: {0}", lado * lado); break; case 2: Console.WriteLine("Ingresa la base"); leer = Console.ReadLine(); BaseFigura = Convert.ToInt32(leer); Console.WriteLine("Ingresa la altura"); leer = Console.ReadLine(); altura = Convert.ToInt32(leer); if (BaseFigura <= 0 || altura <= 0) Console.WriteLine("Ingresaste un número inválido"); else Console.WriteLine("El área de tu rectángulo es: {0}", BaseFigura * altura); break; case 3: Console.WriteLine("Ingresa la base de tu triángulo."); leer = Console.ReadLine(); BaseFigura = Convert.ToInt32(leer); Console.WriteLine("Ingresa la altura"); leer = Console.ReadLine(); altura = Convert.ToInt32(leer); if (BaseFigura <= 0 || altura <= 0) Console.WriteLine("Ingresaste un número inválido"); else Console.WriteLine("El área de tu rectángulo es: {0}", (BaseFigura * altura) / 2);

break;

}//FIN SWITCH Console.ReadKey(); }


} }

Corrida

3-Edades con Switch Diagrama



Rational

Prueba

Codigo using using using using

System; System.Collections.Generic; System.Linq; System.Text;


using System.Threading.Tasks; namespace Areas_con_ifs { class Program { static void Main(string[] args) { //DECLARACION DE VARIABLES

int figura = 0; int lado = 0; int BaseFigura = 0; int altura = 0; string leer; //FIN DE VARIABLES

Console.WriteLine("Elige un número para calcular el área de: \n 1.- Cuadrado \n 2.- Rectángulo \n 3.- Triángulo "); leer = Console.ReadLine(); figura = Convert.ToInt32(leer); if (figura <= 0 || figura > 3) Console.WriteLine("Ingresaste un número inválido"); else if (figura == 1) {//INICIO IF Console.WriteLine("Ingresa la base"); leer = Console.ReadLine(); lado = Convert.ToInt32(leer); if (lado <= 0) Console.WriteLine("Ingresaste un número incorrecto"); else Console.WriteLine("El área de tu cuadrado es: {0}", lado * lado); }//FIN IF FIGURA 1 else if (figura == 2) {//INICIO IF FIGURA 2 Console.WriteLine("Ingresa la base"); leer = Console.ReadLine(); BaseFigura = Convert.ToInt32(leer); Console.WriteLine("Ingresa la altura");

\n


leer = Console.ReadLine(); altura = Convert.ToInt32(leer); if (BaseFigura <= 0 || altura <= 0) Console.WriteLine("Ingresaste un número inválido"); else

Console.WriteLine("El área de tu rectángulo es: {0}", BaseFigura * altura); }//FIN IF FIGURA 2 else Console.WriteLine("Ingresa la base de tu triángulo."); leer = Console.ReadLine(); BaseFigura = Convert.ToInt32(leer);

Console.WriteLine("Ingresa la altura"); leer = Console.ReadLine(); altura = Convert.ToInt32(leer); if (BaseFigura <= 0 || altura <= 0) Console.WriteLine("Ingresaste un número inválido"); else Console.WriteLine("El área de tu rectángulo es: {0}", (BaseFigura * altura) / 2 ); Console.ReadKey(); } } }


Corrida

4-Llamada telef贸nica usando dos variables Diagrama


Rational

Prueba

Codigo using using using using using

System; System.Collections.Generic; System.Linq; System.Text; System.Threading.Tasks;

namespace Ejemplo { class Program { static void Main(string[] args) { double minutos, segundos; double costo = 0; Console.WriteLine("Ingresa los minutos"); minutos = int.Parse(Console.ReadLine());


Console.WriteLine("Ingresa los segundos"); segundos = int.Parse(Console.ReadLine()); segundos = segundos + (minutos * 60); if(segundos > 3600 || segundos <= 0) { Console.WriteLine("Error"); } else { if(segundos>300) { if (segundos % 60 == 0) { costo = minutos - 2.5; } else { costo = (minutos - 2.5) + 1; } } else { if (segundos % 60 == 0) { costo = minutos * 0.5; } else { costo = (minutos * 0.5) + 0.5; } } } Console.WriteLine("El costo de tu llamada es: {0}",costo); Console.ReadKey(); } } }

Corrida


5- Tablas de multiplicar for ascendente Diagrama

Rational


Prueba

Codigo using using using using using

System; System.Collections.Generic; System.Linq; System.Text; System.Threading.Tasks;

namespace Tabla_de_multiplicacion_ascendente { class Program { static void Main(string[] args) { //DECLARACION DE VARIABLES int i = 0; int numero = 0; string leer; //FIN DE VARIABLES

Console.WriteLine("Ingresa el n煤mero de la tabla de multiplicaci贸n que deseas conocer"); leer = Console.ReadLine(); numero = Convert.ToInt32(leer); for (i = 19; i >= 0; i--) {//INICIO FOR


Console.WriteLine("{0} * {1} = }//FIN FOR Console.ReadKey(); } } }

Corrida

{2}" ,numero ,i ,numero * i);


6- Tablas de multiplicar descendente Diagrama

Rational


Prueba

Codigo using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks;

namespace Tabla_de_multiplicacion_ascendente { class Program { static void Main(string[] args) {

//DECLARACION DE VARIABLES

int i = 0; int numero = 0; string leer;


//FIN DE VARIABLES

Console.WriteLine("Ingresa el n煤mero de la tabla de multiplicaci贸n que deseas conocer"); leer = Console.ReadLine(); numero = Convert.ToInt32(leer);

for (i = 19; i >= 0; i--)

{//INICIO FOR

Console.WriteLine("{0} * {1} = {2}" ,numero ,i ,numero * i);

}//FIN FOR

Console.ReadKey(); } } }


Corrida

7-Alumnos con Beca Diagrama


Rational

Prueba

Codigo using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks;

namespace programa


{ class Program { static void Main(string[] args) {

//DECLARACION DE VARIABLES

int i = 0; int alumnos = 0; int calif = 0; int siNo = 0; int sinBeca = 0; int porcentaje = 0; int suma = 0; int suma1 = 0; int suma2 = 0; int beca50 = 0; int beca100 = 0; string leer;

//FIN DE VARIABLES

Console.WriteLine("Ingresa la cantidad de alumnos\n"); leer = Console.ReadLine();


alumnos = Convert.ToInt32(leer);

for (i = 0; i <= alumnos - 1; i++) {//INICIO FOR

Console.WriteLine("Ingresa la calificaci贸n\n"); leer = Console.ReadLine(); calif = Convert.ToInt32(leer);

if (calif <= 0 || calif > 10)

Console.WriteLine("Ingresaste un error\n");

else

{ Console.WriteLine("驴Tienes beca? 1.- SI / 2.- NO\n"); leer = Console.ReadLine(); siNo = Convert.ToInt32(leer);

}

if (siNo ==1) { //INICIO IF Console.WriteLine("Escribe de cuanto es tu beca.\n 1.- 50\n 2.- 100\n"); leer = Console.ReadLine();


porcentaje = Convert.ToInt32(leer);

switch (porcentaje) {//INICIO SWITCH

case 1:

beca50++; suma1 = suma1 + calif;

break;

case 2:

beca100++; suma2 = suma2 + calif;

break;

default:

Console.WriteLine("Ingresaste un error\n");

break;

}//FIN SWITCH


}//FIN IF

else { sinBeca++; suma = suma + calif; }

}//FIN FOR

Console.WriteLine("El promedio general es: {0} \nPromedio becados al 50% {1} \nPromedio becados al 100% {2} \nPromedio sin beca {3}", (suma + suma1 + suma2)/3 ,(suma1/beca50) ,(suma2/beca100) ,(suma/sinBeca));

Console.ReadKey(); } } }


Corrida

8- NĂşmeros pares e impares Diagrama


Rational


Prueba

Codigo using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks;

namespace Programa { class Program


{ static void Main(string[] args) { int i = 1, numero, cantidad; int parma = 0,parme = 0 ,nonma = 0, nonme = 0; string par = "no", non = "no"; Console.WriteLine("Cuantos numeros vas a ingresar?"); cantidad = int.Parse(Console.ReadLine()); while(i<=cantidad) { Console.WriteLine("Ingresa el numero {0}", i); numero = int.Parse(Console.ReadLine()); if(numero % 2 == 0) { if(par == "no") { parme = numero; parma = numero; par = "si"; }

if(numero > parma) { parma = numero; } if(numero < parme)


{ parme = numero; }

} else { if (non == "no") { nonme = numero; nonma = numero; non = "si"; }

if (numero > parma) { nonma = numero; } if (numero < parme) { nonme = numero; } } i++; }


Console.WriteLine("EL NUMERO PAR MAS GRANDE ES {0} PAR MAS CHICO {1}, NON MAS GRANDE {2}, NON MAS CHICO{3}",parma,parme,nonma,nonme); Console.ReadKey(); } } }

Corrida


9-Numeros Pares e Impares For Diagrama


Racional

Prueba

Codigo using System;


using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks;

namespace Programa { class Program { static void Main(string[] args) {

//INICIO DE VARIABLES int i = 0; int cantidad = 0; int edad = 0; int mayores = 0; int mayoresSuma = 0; int menores = 0; int menoresSuma = 0; int error = 0; string leer; //FIN DE VARIABLES

Console.WriteLine("Ingresa la cantidad de edades que introduciras"); leer = Console.ReadLine();


cantidad = Convert.ToInt32(leer);

//INICIO FOR for (i = 0; i <= cantidad - 1; i++) { Console.WriteLine("Ingresa la {0} edad", i + 1); leer = Console.ReadLine(); edad = Convert.ToInt32(leer);

//INICIO IF if (edad < 0 || edad > 120)

Console.WriteLine("Ingresaste un error", error++);

else

if (edad >= 18) { mayoresSuma = mayoresSuma + edad; mayores++; }

else


menoresSuma = menoresSuma + edad; menores++;

}//FINAL FOR Console.WriteLine("El nĂşmero total de mayores es de: {0} \n", mayores); Console.WriteLine("El nĂşmero total de menores es de: {0} \n", menores); Console.WriteLine("El promedio de las edades mayores es: {0} \n", mayoresSuma / mayores); Console.WriteLine("El promedio de las edades menores es: {0} \n", menoresSuma / menores); Console.WriteLine("El total de errores es: {0} \n", error); Console.ReadKey(); } } } Corrida


10-Edades con For Diagrama


Prueba

Codigo using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks;

namespace Cajera_Supermercado { class Program { static void Main(string[] args) { //DECLARACION DE VARIABLES


int i, cantidad, tipo = 0; double comestibles = 0; double medicamentos = 0; double otros = 0; double precio = 0; string leer;

//FIN DE VARIABLES

Console.WriteLine("Ingresa la cantidad de articulos"); leer = Console.ReadLine(); cantidad = Convert.ToInt32(leer);

for (i = 0; i <= cantidad - 1; i++) {//INICIO FOR Console.WriteLine("Ingresa el precio del articulo"); leer = Console.ReadLine(); precio = Convert.ToInt32(leer);

if (precio <= 0)

Console.WriteLine("El precio que ingresaste es incorrecto");


else

Console.WriteLine("Qué tipo de articulo es, ingresa un número. 1.- Comestible. 2.Medicamento. 3.- Otros"); leer = Console.ReadLine(); tipo = Convert.ToInt32(leer);

switch (tipo) {//INICIO SWITCH case 1: { comestibles = comestibles + precio; break; }//FIN CASE 1

case 2: { medicamentos = medicamentos + precio; break; }//FIN CASE 2

case 3: { otros = otros + precio; break; }//FIN CASE 3


}//FIN SWITCH }//FIN FOR

Console.WriteLine("El precio de los comestibles sin iva es: ${0}", comestibles); Console.WriteLine("El precio de los medicamentos sin iva es: ${0}", medicamentos); Console.WriteLine("El precio de otros sin iva es: ${0}", otros);

Console.WriteLine("El precio de los comestibles con iva es: ${0}", comestibles); Console.WriteLine("El precio de los medicamentos con iva es: ${0}", medicamentos * 1.05); Console.WriteLine("El precio de otros sin iva es: ${0}", otros * 1.10);

Console.ReadKey(); } } }

Corrida


11- Llamadas minutos segundos Do-while Diagrama


Prueba

Corrida

Codigo using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks;

namespace Programa {


class Program { static void Main(string[] args) {

//INICIO DE VARIABLES int i = 0; int cantidad = 0; int edad = 0; int mayores = 0; int mayoresSuma = 0; int menores = 0; int menoresSuma = 0; int error = 0; string leer; //FIN DE VARIABLES

Console.WriteLine("Ingresa la cantidad de edades que introduciras"); leer = Console.ReadLine(); cantidad = Convert.ToInt32(leer);

//INICIO FOR for (i = 0; i <= cantidad - 1; i++) { Console.WriteLine("Ingresa la {0} edad", i + 1);


leer = Console.ReadLine(); edad = Convert.ToInt32(leer);

//INICIO IF if (edad < 0 || edad > 120)

Console.WriteLine("Ingresaste un error", error++);

else

if (edad >= 18) { mayoresSuma = mayoresSuma + edad; mayores++; }

else

menoresSuma = menoresSuma + edad; menores++;

}//FINAL FOR


Console.WriteLine("El nĂşmero total de mayores es de: {0} \n", mayores); Console.WriteLine("El nĂşmero total de menores es de: {0} \n", menores); Console.WriteLine("El promedio de las edades mayores es: {0} \n", mayoresSuma / mayores); Console.WriteLine("El promedio de las edades menores es: {0} \n", menoresSuma / menores); Console.WriteLine("El total de errores es: {0} \n", error); Console.ReadKey(); } }

Racional


12- Calificaciones A, B y C Diagrama


Prueba

Corrida


Rational



13-Areas con do-While Diagrama


Prueba

Corrida

Codigo using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks;

namespace CostoLlamadaDoWhile { class Program


{ static void Main(string[] args) {//NO SE TOCAN

//INICIO DE VARIABLES int opcion = 0; int baseFigura = 0; int altura = 0; int lado = 0; string leer; //FIN DE VARIABLES

do { Console.WriteLine("Ingresa el número de la figura que deseas calcular su área. \n 1.Cuadrado \n 2.- Rectangulo \n 3.- Triángulo \n 4.- Salir \n"); leer = Console.ReadLine(); opcion = Convert.ToInt32(leer);

switch (opcion) {

case 1: Console.WriteLine("Ingresa el lado de tu cuadrado"); leer = Console.ReadLine(); lado = Convert.ToInt32(leer);


if (lado <= 0)

Console.WriteLine("Ingresaste un número inválido");

else

Console.WriteLine("El área de tu cuadrado es: {0} ", lado * lado);

break;

case 2: Console.WriteLine("Ingresa el lado de tu rectángulo");

Console.WriteLine("Ingresa la base"); leer = Console.ReadLine(); baseFigura = Convert.ToInt32(leer);

Console.WriteLine("Ingresa la altura"); leer = Console.ReadLine(); altura = Convert.ToInt32(leer);

if (baseFigura <= 0 || altura <= 0)

Console.WriteLine("Ingresaste un número incorrecto");


else

Console.WriteLine("El área de tu rectángulo es:{0} ", baseFigura * altura);

break;

case 3: Console.WriteLine("Ingresa el lado de tu triángulo");

Console.WriteLine("Ingresa la base"); leer = Console.ReadLine(); baseFigura = Convert.ToInt32(leer);

Console.WriteLine("Ingresa la altura"); leer = Console.ReadLine(); altura = Convert.ToInt32(leer);

if (baseFigura <= 0 || altura <= 0)

Console.WriteLine("Ingresaste un número incorrecto");

else

Console.WriteLine("El área de tu triángulo es: {0}", (baseFigura * altura) / 2);


break; }//FIN SWITCH

} while (opcion != 4);

Console.ReadKey(); } } }


Racional

14- Frutas con do-While Diagrama


Prueba

Corrida

Codigo using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks;

namespace CostoLlamadaDoWhile


{ class Program { static void Main(string[] args) {

//DECLARACION DE VARIABLES

int opcion = 0; int datos = 0; int verif = 0; int verif0 = 0; int verif00 = 0; int suma1 = 0; int suma2 = 0; int suma3 = 0; int paso = 0; string fecha, leer, placa;

//FIN DE VARIABLES

Console.WriteLine("Ingresa la fecha de la captura"); fecha = Console.ReadLine();

do {


do {

Console.WriteLine("\nIngresa la placa del automovil"); placa = Console.ReadLine();

Console.WriteLine("\nIngresa el tipo de verificaci贸n\n 1.- Cero 0 \n 2.- Doble Cero 00"); leer = Console.ReadLine(); verif = Convert.ToInt32(leer);

if (verif == 1) { Console.WriteLine("\n驴El automovil paso la verificaci贸n? 1.- Si / 2.- No"); leer = Console.ReadLine(); paso = Convert.ToInt32(leer); if (paso == 1) { Console.WriteLine("\nEl automovil debe pagar $274"); verif0++; suma2 = suma2 + 274; } else Console.WriteLine("\nEl automovil debe pagar $219"); suma3 = suma3 + 219; } else //ELSE DE VALIDACION SI ES CERO O DOBLE CERO


{ Console.WriteLine("\n多El automovil paso la verificaci坦n? 1.- Si / 2.- No"); leer = Console.ReadLine(); paso = Convert.ToInt32(leer); if (paso == 1) { Console.WriteLine("\nEl automovil debe pagar $548"); verif00++; suma1 = suma1 + 548; } else Console.WriteLine("\nEl automovil debe pagar $219"); suma3 = suma3 + 219; } Console.WriteLine("多Tus datos son correctos? 1.- SI / 2.- NO \nSI ELIGES NO, TUS DATOS SE VOLVERAN A PEDIR.");

leer = Console.ReadLine(); datos = Convert.ToInt32(leer); } while (datos != 1); Console.WriteLine("\n多Deseas ingresar otro coche? 1.- SI / 2.- NO"); leer = Console.ReadLine(); opcion = Convert.ToInt32(leer); }//FIN WHILE while (opcion != 2);


Console.WriteLine("\n\n\n{0}", fecha); Console.WriteLine("\nEl total de coches con verificaci贸n 0 fueron: Console.WriteLine(" Y la ganancia parcial es de:

{0}", verif0); ${0}", suma2);

Console.WriteLine("\nEl total de coches con verificaci贸n doble cero 00 fueron: verif00); Console.WriteLine("Y la ganancia parcial es de:

{0}",

${0}", suma1);

Console.WriteLine("\nEl parcial ganado de coches que no pasaron la verificaci贸n fue de: {0}", suma3); Console.WriteLine("\nEl total ganado fue de: Console.ReadKey(); } } }

Racional

${0}", suma1 + suma2);


15-Verificacion con Do-while


Prueba

Corrida

Codigo using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks;


namespace Frutas_con_while { class Program { static void Main(string[] args) {

//Declaraci贸n de variables

string fecha; int ensalada = 0; int ventaJ = 0; double kilosJ = 0; int ventaM = 0; double kilosM = 0; int ventaZ = 0; double kilosZ = 0; int ventaP = 0; double kilosP = 0; int ventaS = 0; double kilosS = 0; int opcion = 0; int vasos = 0; double kilosTotal = 0; double ventaTotal = 0;


int correccion = 0; string leer;

//Fin de variables

Console.WriteLine("\nIngresa la fecha de captura"); fecha = Console.ReadLine();

do {//INICIO DO WHILE

Console.WriteLine("Qué ensalada se vendió? Ingresa una de las siguientes opciones.\n J.- Jícama\n M.- Mango\n P.- Pepino\n S.- Sandía\n Z.- Zanahoria\n "); leer = Console.ReadLine(); ensalada = Convert.ToChar(leer);

do//CORRECION DE DATOS { switch (ensalada) {//INICIO SWITCH

case 'J': Console.WriteLine("Cuantos vasos de jícama se vendieron?"); leer = Console.ReadLine();


vasos = Convert.ToInt32(leer);

kilosJ = vasos / 7.0; //NO IMPRIME LOS DECIMALES ventaJ = vasos * 17;

break;

case 'M':

Console.WriteLine("Cuantos vasos de mango se vendieron?"); leer = Console.ReadLine(); vasos = Convert.ToInt32(leer);

kilosM = vasos / 5.0; //NO IMPRIME LOS DECIMALES

ventaM = vasos * 17;

break;

case 'Z':

Console.WriteLine("Cuantos vasos de zanahoria se vendieron?"); leer = Console.ReadLine(); vasos = Convert.ToInt32(leer);

kilosZ = vasos / 6.5; //NO IMPRIME LOS DECIMALES


ventaZ = vasos * 17;

break;

case 'P':

Console.WriteLine("Cuantos vasos de pepino se vendieron?"); leer = Console.ReadLine(); vasos = Convert.ToInt32(leer);

kilosP = vasos / 6.0; //NO IMPRIME LOS DECIMALES

ventaP = vasos * 17;

break;

case 'S':

Console.WriteLine("Cuantos vasos de sandĂ­a se vendieron?"); leer = Console.ReadLine(); vasos = Convert.ToInt32(leer);

kilosS = vasos / 5.5; //NO IMPRIME LOS DECIMALES

ventaS = vasos * 17;


break;

default:

Console.WriteLine("Ingresaste un error");

break;

}//FIN SWITCH

Console.WriteLine("¿Están correctos tus datos? \n 1.- Si \n 2.- No"); leer = Console.ReadLine(); correccion = Convert.ToInt32(leer); } while (correccion != 1);

Console.WriteLine("¿Deseas ingresar otros datos?\n 1.- Si\n 2.- No\n"); leer = Console.ReadLine(); opcion = Convert.ToInt32(leer);

}//FIN DO WHILE while (opcion != 2); Console.WriteLine("{0}",fecha);


Console.WriteLine("Kilogramos vendidos de JICAMA: {0}\n\n Venta: ${1}\n",kilosJ ,ventaJ); Console.WriteLine("Kilogramos vendidos de MANGO: {0}\n Venta: ${1}\n", kilosM, ventaM); Console.WriteLine("Kilogramos vendidos de ZANAHORIA: {0}\n Venta: ${1}\n", kilosZ, ventaZ); Console.WriteLine("Kilogramos vendidos de PEPINOS: {0}\n Venta: ${1}\n", kilosP, ventaP); Console.WriteLine("Kilogramos vendidos de SANDIA: {0}\n Venta: ${1}\n", kilosS, ventaS); ventaTotal = ventaJ + ventaM + ventaP + ventaS + ventaZ; kilosTotal = kilosJ + kilosM + kilosP + kilosS + kilosS + kilosZ; Console.WriteLine("La venta total fue de ${0}\n Kilos totales vendidos: {1}", ventaTotal, kilosTotal); Console.WriteLine("Gracias por usar el programa"); Console.ReadKey();

} } }


Racional


16-Verificacion con For


Prueba


Corrida

Codigo using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks;

namespace CostoLlamadaDoWhile { class Program { static void Main(string[] args) {

//DECLARACION DE VARIABLES


int menu = 0; int autos = 0; int sAutos = 0; int camiones = 0; int sCamiones = 0; int trailers = 0; int sTrailers = 0; string opcion; string leer;

//FIN DE VARIABLES do { Console.WriteLine(" Ingresa una de las opciones del menĂş o presiona 4 para terminar el programa. \n \n MenĂş\n \n \n 1.- Auto \n \n 2.- Camion \n \n 3.- Trailer\n \n 4.- Salir \n \n"); leer = Console.ReadLine(); menu = Convert.ToInt32(leer);

switch (menu) {//INICIO SWTICH

case 1:

autos++; sAutos = sAutos + 50;


break;

case 2: camiones++; sCamiones = sCamiones + 100; break;

case 3: trailers++; sTrailers = sTrailers + 200; break;

case 4: Console.WriteLine("El total de hoy es: \n \n"); break; }//FIN SWITCH

}//FIN DO while (menu != 4);

Console.WriteLine(" Total de autos: {0}\n \n Cobrado: {1} \n \n Total de camiones: {2} \n \n Cobrado: {3} \n \n Total de trailers: {4} \n \n Cobrado: {5} \n \n", autos, sAutos, camiones, sCamiones, trailers, sTrailers); Console.WriteLine(" Total Cobrado: {0}", sAutos + sCamiones + sTrailers); Console.ReadKey( }


} }

Racional


17-Inventario con do-While

Prueba

Codigo using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks;


namespace CostoLlamadaDoWhile { class Program { static void Main(string[] args) { //DECLARACION DE VARIABLES

int i = 0; int cantidad = 0; int verif = 0; int verif0 = 0; int verif00 = 0; int suma1 = 0; int suma2 = 0; int paso = 0; int suma3 = 0; string fecha, leer, placa;

//FIN DE VARIABLES

Console.WriteLine("Ingresa la fecha de la captura"); fecha = Console.ReadLine();


Console.WriteLine("\nIngresa la cantidad de autos que entraron el día de hoy a verificación"); leer = Console.ReadLine(); cantidad = Convert.ToInt32(leer);

for (i = 0; i <= cantidad - 1; i++)

{ //INICIO FOR

Console.WriteLine("\nIngresa la placa del automovil"); placa = Console.ReadLine();

Console.WriteLine("\nIngresa el tipo de verificación\n 1.- Cero 0 \n 2.- Doble Cero 00"); leer = Console.ReadLine(); verif = Convert.ToInt32(leer);

if (verif == 1) { Console.WriteLine("\n¿El automovil paso la verificación? 1.- Si / 2.- No"); leer = Console.ReadLine(); paso = Convert.ToInt32(leer);

if (paso == 1) { Console.WriteLine("\nEl automovil debe pagar $274"); verif0++;


suma2 = suma2 + 274; }

else

Console.WriteLine("\nEl automovil debe pagar $219"); suma3 = suma3 + 219; }

else //ELSE DE VALIDACION SI ES CERO O DOBLE CERO {

Console.WriteLine("\n驴El automovil paso la verificaci贸n? 1.- Si / 2.- No"); leer = Console.ReadLine(); paso = Convert.ToInt32(leer); if (paso == 1) { Console.WriteLine("\nEl automovil debe pagar $548"); verif00++; suma1 = suma1 + 548; } else Console.WriteLine("\nEl automovil debe pagar $219"); suma3 = suma3 + 219; } }//FIN FOR


Console.WriteLine("\n\n\n{0}", fecha); Console.WriteLine("\nEl total de coches con verificaci贸n 0 fueron: Console.WriteLine(" Y la ganancia parcial es de:

{0}", verif0);

${0}", suma2);

Console.WriteLine("\nEl total de coches con verificaci贸n doble cero 00 fueron: {0}", verif00); Console.WriteLine("Y la ganancia parcial es de:

${0}", suma1);

Console.WriteLine("El parcial ganado de coches que no pasaron la verificaci贸n: {0}", suma3); Console.WriteLine("\n El total ganado fue de: suma3); Console.ReadKey(); } }

${0}", suma1 + suma2 +



18- Caseta con for




Prueba

Corrida

Codigo using System; using System.Collections.Generic;


using System.Linq; using System.Text; using System.Threading.Tasks;

namespace CostoLlamadaDoWhile { class Program { static void Main(string[] args) { //DECLARACION DE VARIABLES

int i = 0; int cantidad = 0; int verif = 0; int verif0 = 0; int verif00 = 0; int suma1 = 0; int suma2 = 0; int paso = 0; int suma3 = 0; string fecha, leer, placa;

//FIN DE VARIABLES

Console.WriteLine("Ingresa la fecha de la captura");


fecha = Console.ReadLine();

Console.WriteLine("\nIngresa la cantidad de autos que entraron el día de hoy a verificación"); leer = Console.ReadLine(); cantidad = Convert.ToInt32(leer);

for (i = 0; i <= cantidad - 1; i++)

{ //INICIO FOR

Console.WriteLine("\nIngresa la placa del automovil"); placa = Console.ReadLine();

Console.WriteLine("\nIngresa el tipo de verificación\n 1.- Cero 0 \n 2.- Doble Cero 00"); leer = Console.ReadLine(); verif = Convert.ToInt32(leer);

if (verif == 1) { Console.WriteLine("\n¿El automovil paso la verificación? 1.- Si / 2.- No"); leer = Console.ReadLine(); paso = Convert.ToInt32(leer);

if (paso == 1) {


Console.WriteLine("\nEl automovil debe pagar $274"); verif0++; suma2 = suma2 + 274; }

else

Console.WriteLine("\nEl automovil debe pagar $219"); suma3 = suma3 + 219; }

else //ELSE DE VALIDACION SI ES CERO O DOBLE CERO {

Console.WriteLine("\n驴El automovil paso la verificaci贸n? 1.- Si / 2.- No"); leer = Console.ReadLine(); paso = Convert.ToInt32(leer);

if (paso == 1)

{ Console.WriteLine("\nEl automovil debe pagar $548"); verif00++; suma1 = suma1 + 548;


} else

Console.WriteLine("\nEl automovil debe pagar $219"); suma3 = suma3 + 219; } }//FIN FOR

Console.WriteLine("\n\n\n{0}", fecha);

Console.WriteLine("\nEl total de coches con verificaci贸n 0 fueron: Console.WriteLine(" Y la ganancia parcial es de:

{0}", verif0);

${0}", suma2);

Console.WriteLine("\nEl total de coches con verificaci贸n doble cero 00 fueron: {0}", verif00); Console.WriteLine("Y la ganancia parcial es de:

${0}", suma1);

Console.WriteLine("El parcial ganado de coches que no pasaron la verificaci贸n: {0}", suma3);

Console.WriteLine("\n El total ganado fue de: suma3); Console.ReadKey(); } }

${0}", suma1 + suma2 +


Raciona


Caseta con Do-While Diagrama


Prueba

Codigo using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks;

namespace Cobro_caseta_for { class Program { static void Main(string[] args) {

//DECLARACION DE VARIABLES

int i = 0; int cantidad = 0;


int autos = 0; int vehiculo = 0; int camiones = 0; int trailers = 0; int sAutos = 0; int sCamiones = 0; int sTrailers = 0; string leer;

//FIN DE VARIABLES

do {

Console.WriteLine("Ingresa la cantidad de vehiculos que pasaron por la caseta"); leer = Console.ReadLine(); cantidad = Convert.ToInt32(leer);

if (cantidad <= 0)

Console.WriteLine(" \nIngresaste un dato invรกlido, intenta de nuevo \n");

} while (cantidad <= 0);


Console.ReadKey(); } } }

Racional


20- Caseta con do-While Diagrama


Prueba

Corrida

Codigo using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks;

namespace Caseta_cobro_while {


class Program { static void Main(string[] args) { //INICIO DE VARIABLES int i = 0; int cantidad = 0; int autos = 0; int menu = 0; int camiones = 0; int trailers = 0; int sAutos = 0; int sCamiones = 0; int sTrailers = 0; int error = 0; string leer; //FIN DE VARIABLES

Console.WriteLine("Ingresa la cantidad de vehiculos que pasaron por la caseta\n"); leer = Console.ReadLine(); cantidad = Convert.ToInt32(leer);

if (cantidad <= 0)

Console.WriteLine("Ingresaste un error, intenta de nuevo\n"); else


while (i <= cantidad -1 ) { Console.WriteLine(" Ingresa una de las opciones del menĂş \n \n Auto \n \n 2.- Camion \n \n 3.- Trailer\n \n "); leer = Console.ReadLine(); menu = Convert.ToInt32(leer); switch (menu) {//INICIO SWTICH case 1:

autos++; sAutos = sAutos + 50; i++; break; case 2: camiones++; sCamiones = sCamiones + 100; i++; break; case 3: trailers++; sTrailers = sTrailers + 200; i++; break; default: Console.WriteLine("\n \n Ingresaste un error.");

MenĂş\n \n \n 1.-


error++; break; }//FIN SWITCH }//FIN while Console.WriteLine(" Total de autos: {0}\n \n Cobrado: {1} \n \n Total de camiones: {2} \n \n Cobrado: {3} \n \n Total de trailers: {4} \n \n Cobrado: {5} \n \n", autos, sAutos, camiones, sCamiones, trailers, sTrailers); Console.WriteLine("

Total Cobrado: {0}\n \n", sAutos + sCamiones + sTrailers);

Console.WriteLine("

El total de errores ingresados son: {0}" ,error);

Console.ReadKey(); } } }

Racional


21-Caseta con While Diagrama

Prueba


Corrida

Codigo using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks;

namespace Caseta_cobro_do_while { class Program { static void Main(string[] args) { //DECLARACION DE VARIABLES

int menu = 0; int autos = 0; int sAutos = 0;


int camiones = 0; int sCamiones = 0; int trailers = 0; int sTrailers = 0; string opcion; string leer;

//FIN DE VARIABLES do { Console.WriteLine(" Ingresa una de las opciones del menú o presiona 4 para terminar el programa. \n \n Menú\n \n \n 1.- Auto \n \n 2.- Camion \n \n 3.- Trailer\n \n 4.- Salir \n \n"); leer = Console.ReadLine(); menu = Convert.ToInt32(leer);

switch (menu) {//INICIO SWTICH

case 1:

autos++; sAutos = sAutos + 50; break;

case 2: camiones++;


sCamiones = sCamiones + 100; break;

case 3: trailers++; sTrailers = sTrailers + 200; break;

case 4: Console.WriteLine("El total de hoy es: \n \n"); break; }//FIN SWITCH

}//FIN DO while (menu != 4);

Console.WriteLine(" Total de autos: {0}\n \n Cobrado: {1} \n \n Total de camiones: {2} \n \n Cobrado: {3} \n \n Total de trailers: {4} \n \n Cobrado: {5} \n \n", autos, sAutos, camiones, sCamiones, trailers, sTrailers); Console.WriteLine(" Total Cobrado: {0}", sAutos + sCamiones + sTrailers); Console.ReadKey();

} } }


Racional

22-Metodo Diagrama


Prueba

Corrida

Codigo using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks;


namespace Exponente_y_raiz { class Program { static void Main(string[] args) { //DECLARACION DE VARIABLES

int menu = 0; Double numBase = 0; Double exponente = 0; Double numRaiz = 0; Double resultadoExp = 0; Double resultadoRaiz = 0;

string leer; //FIN DE VARIABLES do { Console.WriteLine("Ingresa una de las siguientes opciones del menu \n\n\n \n \n 1.- Realizar un exponente. \n \n 2.-Realizar una raiz. \n \n 3.-Salir.\n\n "); leer = Console.ReadLine(); menu = Convert.ToInt32(leer);

Menu


switch (menu) {//INICIO SWITCH case 1: do { Console.WriteLine(" Ingresa el nĂşmero base\n \n"); leer = Console.ReadLine(); numBase = Convert.ToInt32(leer); } while (numBase <= 0);

do { Console.WriteLine(" Ingresa el exponente \n \n"); leer = Console.ReadLine(); exponente = Convert.ToInt32(leer); } while (exponente <= 0);

resultadoExp = Math.Pow(numBase, exponente);

if (resultadoExp % 2 == 0)

Console.WriteLine("El resultado del exponente {0} es par y es entero\n\n", resultadoExp);


else

Console.WriteLine("El resultado del exponente {0} es impar y es non\n\n", resultadoExp);

break;

case 2:

do { Console.WriteLine("Ingresa el nĂşmero a sacar raiz\n\n"); leer = Console.ReadLine(); numRaiz = Convert.ToInt32(leer); }

while (numRaiz <= 0); resultadoRaiz = Math.Sqrt(numRaiz);

if (resultadoRaiz % 2 == 0)

Console.WriteLine("El resultado de la raiz {0} es par y es entero\n\n", resultadoRaiz);

else Console.WriteLine("El resultado de la raiz {0} es impar y es non\n\n", resultadoRaiz);


break; case 3: Console.WriteLine("Gracias por ocupar el programa"); break; }//FIN SWITCH } while (menu != 3); Console.ReadKey(); } } }


Racional


Issuu converts static files into: digital portfolios, online yearbooks, online catalogs, digital photo albums and more. Sign up and create your flipbook.