Aki les presento mi coleccion de programas de la uni jaja muy feos pero eso me piden esto les ayudara mucho a los principiantes y mas que nada por que no hay muchos articulos referentes a c#.net
Autorbuses Este programa calcula un n numero de boletos con diferentes precios en el dia noche y tarde
Citarusing System;
using System.Collections.Generic;
using System.Text;
namespace Autobuses
{
class Program
{
static void Main(string[] args)
{
int ou = 1;
double precio=0;
Console.WriteLine(" - AD0 By _Bj0rD_ - ");
do
{
Console.WriteLine(" Digite el numero de boletos que adquirira ");
double bol = double.Parse(Console.ReadLine());
if (bol < 0)
{
Console.WriteLine("Numero de boletos erroneo");
ou = 0;
}
else
{
Console.WriteLine("Su viaje sera de DIA, TARDE o NOCHE");
string viaj = Console.ReadLine();
if (viaj == "DIA" || viaj == "dia" || viaj == "Dia" || viaj == "d" || viaj == "D")
{
precio = bol * 50;
}
else if (viaj == "TARDE" || viaj == "tarde" || viaj == "Tarde" || viaj == "t" || viaj == "T")
{
precio = bol * 75;
}
else if (viaj == "NOCHE" || viaj == "noche" || viaj == "Noche" || viaj == "n" || viaj == "N")
{
precio = bol * 100;
}
Console.WriteLine("El total por {0} boletos durante el/la {1} es: {2}", bol, viaj, precio);
Console.WriteLine("Desea Reiniciar S/N");
string s = Console.ReadLine();
if (s == "S" || s == "s")
{
ou = 0;
}
else
{
ou = 1;
}
}
} while (ou == 0);
}
}
}
Calculadora usando metodos solo sirve para dos numeros
Citarusing System;
using System.Collections.Generic;
using System.Text;
namespace ConsoleApplication2
{
class Program
{
class calc
{
private double opercaciones;
public void suma(double a, double b)
{
opercaciones = a + b;
Console.WriteLine("El Resultado es: " + opercaciones);
}
public void resta(double a, double b)
{
opercaciones = a - b;
Console.WriteLine(opercaciones);
}
public void multiplicacion(double a, double b)
{
opercaciones = a * b;
Console.WriteLine(opercaciones);
}
public void division(double a, double b)
{
opercaciones = a / b;
Console.WriteLine(opercaciones);
}
}
static void Main(string[] args)
{
string reiniciar;
do
{
Console.ForegroundColor = ConsoleColor.Blue;
Console.BackgroundColor = ConsoleColor.Yellow;
calc oper = new calc();
string operacion;
string desicion;
Console.WriteLine("Calculadora By _Bj0rD_");
Console.WriteLine();
Console.WriteLine("---------------------------------");
Console.WriteLine("Que Operacion Deseas Hacer");
Console.WriteLine("Suma");
Console.WriteLine("Resta");
Console.WriteLine("Multiplicacion");
Console.WriteLine("Division");
Console.WriteLine("---------------------------------");
operacion = Console.ReadLine();
if (operacion == "suma")
{
do
{
Console.WriteLine("Introduce Los Numeros a Sumar");
double a = double.Parse(Console.ReadLine());
double c = double.Parse(Console.ReadLine());
oper.suma(a, c);
Console.WriteLine("Hacer Otra Operacion? Si/No");
desicion = Console.ReadLine();
}
while (desicion == "s");
}
else if (operacion == "resta")
{
do
{
Console.WriteLine("Introduce Los Numeros a Restar");
double a = double.Parse(Console.ReadLine());
double c = double.Parse(Console.ReadLine());
oper.resta(a, c);
Console.WriteLine("Deseas Hacer Otra Operacion? Si/No");
desicion = Console.ReadLine();
}
while (desicion == "s");
}
else if (operacion == "multiplicacion")
{
do
{
Console.WriteLine("Introduce Los Numeros a Multiplicar");
double a = double.Parse(Console.ReadLine());
double c = double.Parse(Console.ReadLine());
oper.multiplicacion(a, c);
Console.WriteLine("Deseas Hacer Otra Operacion? Si/No");
desicion = Console.ReadLine();
}
while (desicion == "s");
}
else if (operacion == "division")
{
do
{
Console.WriteLine("Introduce Los Numeros a Dividir");
double a = double.Parse(Console.ReadLine());
double c = double.Parse(Console.ReadLine());
oper.division(a, c);
Console.WriteLine("Deseas Hacer Otra Operacion? Si/No");
desicion = Console.ReadLine();
}
while (desicion == "s");
}
Console.WriteLine("Deseas Reiniciar la Calcu Si/No");
reiniciar = Console.ReadLine();
} while (reiniciar == "s");
}
}
}
Maquina espendedora este programa simula una maquina de monedas (DE productos)
Citarusing System;
using System.Collections.Generic;
using System.Text;
namespace ConsoleApplication1
{
class Program
{
class menu
{
public void start(string entrar)
{
double price = 0;
double cambio;
double reprice = 0;
double tot = 0;
string producto;
string des;
do
{
Console.WriteLine("MakiNa ExpENdEdorA De _Bj0rD_");
Console.WriteLine("Selecciona Un Producto");
Console.WriteLine("A1 -- Doritos --");
Console.WriteLine("B1 -- Crush De Naranja --");
Console.WriteLine("C1 -- Pizza --");
Console.WriteLine("D1 -- Coca Cola --");
Console.WriteLine("E1 -- Cigarros --");
Console.WriteLine("F1 -- Ruffles --");
Console.WriteLine("G1 -- Halls --");
Console.WriteLine("A2 -- Trident --");
Console.WriteLine("B2 -- HotNuts --");
Console.WriteLine("C2 -- GoldenNuts --");
Console.WriteLine("D2 -- Panditas --");
Console.WriteLine("E2 -- Sprite --");
Console.WriteLine("F2 -- Enchilados --");
Console.WriteLine("G2 -- MaxAir --");
Console.WriteLine("A3 -- Crujitos --");
Console.WriteLine("B3 -- Sangria --");
producto = Console.ReadLine();
if (producto == "A1")
{
Console.WriteLine("Deposite 5$ Pesos");
double A1 = 5;
tot = tot + A1;
Console.WriteLine("Introduce El Valor De Tu Moneda (Solo Se Aceptan 10, 5, 2, 1, .50");
price = double.Parse(Console.ReadLine());
while (price < A1)
{
Console.WriteLine("Tu Moneda Es Insuficiente Deposita Otra");
Console.WriteLine("Introduce El Valor De Tu Moneda (Solo Se Aceptan 10, 5, 2, 1, .50");
reprice = double.Parse(Console.ReadLine());
price = price + reprice;
}
cambio = price - A1;
Console.WriteLine("Tu Cambio Es: " + cambio);
}
else if (producto == "B1")
{
Console.WriteLine("Deposite 6$ Pesos");
double B1 = 6;
tot = tot + B1;
Console.WriteLine("Introduce El Valor De Tu Moneda (Solo Se Aceptan 10, 5, 2, 1, .50");
price = double.Parse(Console.ReadLine());
while (price < B1)
{
Console.WriteLine("Tu Moneda Es Insuficiente Deposita Otra");
Console.WriteLine("Introduce El Valor De Tu Moneda (Solo Se Aceptan 10, 5, 2, 1, .50");
reprice = double.Parse(Console.ReadLine());
price = price + reprice;
}
cambio = price - B1;
Console.WriteLine("Tu Cambio Es: " + cambio);
}
else if (producto == "C1")
{
Console.WriteLine("Deposite 15$ Pesos");
double C1 = 15;
tot = tot + C1;
Console.WriteLine("Introduce El Valor De Tu Moneda (Solo Se Aceptan 10, 5, 2, 1, .50");
price = double.Parse(Console.ReadLine());
while (price < C1)
{
Console.WriteLine("Tu Moneda Es Insuficiente Deposita Otra");
Console.WriteLine("Introduce El Valor De Tu Moneda (Solo Se Aceptan 10, 5, 2, 1, .50");
reprice = double.Parse(Console.ReadLine());
price = price + reprice;
}
cambio = price - C1;
Console.WriteLine("Tu Cambio Es: " + cambio);
}
else if (producto == "D1")
{
Console.WriteLine("Deposite 6$ Pesos");
double D1 = 6;
tot = tot + D1;
Console.WriteLine("Introduce El Valor De Tu Moneda (Solo Se Aceptan 10, 5, 2, 1, .50");
price = double.Parse(Console.ReadLine());
while (price < D1)
{
Console.WriteLine("Tu Moneda Es Insuficiente Deposita Otra");
Console.WriteLine("Introduce El Valor De Tu Moneda (Solo Se Aceptan 10, 5, 2, 1, .50");
reprice = double.Parse(Console.ReadLine());
price = price + reprice;
}
cambio = price - D1;
Console.WriteLine("Tu Cambio Es: " + cambio);
}
else if (producto == "E1")
{
Console.WriteLine("Deposite 21$ Pesos");
double E1 = 21;
tot = tot + E1;
Console.WriteLine("Introduce El Valor De Tu Moneda (Solo Se Aceptan 10, 5, 2, 1, .50");
price = double.Parse(Console.ReadLine());
while (price < E1)
{
Console.WriteLine("Tu Moneda Es Insuficiente Deposita Otra");
Console.WriteLine("Introduce El Valor De Tu Moneda (Solo Se Aceptan 10, 5, 2, 1, .50");
reprice = double.Parse(Console.ReadLine());
price = price + reprice;
}
cambio = price - E1;
Console.WriteLine("Tu Cambio Es: " + cambio);
}
else if (producto == "F1")
{
Console.WriteLine("Deposite 4.5$ Pesos");
double F1 = 4.5;
tot = tot + F1;
Console.WriteLine("Introduce El Valor De Tu Moneda (Solo Se Aceptan 10, 5, 2, 1, .50");
price = double.Parse(Console.ReadLine());
while (price < F1)
{
Console.WriteLine("Tu Moneda Es Insuficiente Deposita Otra");
Console.WriteLine("Introduce El Valor De Tu Moneda (Solo Se Aceptan 10, 5, 2, 1, .50");
reprice = double.Parse(Console.ReadLine());
price = price + reprice;
}
cambio = price - F1;
Console.WriteLine("Tu Cambio Es: " + cambio);
}
else if (producto == "G1")
{
Console.WriteLine("Deposite 3.5$ Pesos");
double G1 = 3.5;
tot = tot + G1;
Console.WriteLine("Introduce El Valor De Tu Moneda (Solo Se Aceptan 10, 5, 2, 1, .50");
price = double.Parse(Console.ReadLine());
while (price < G1)
{
Console.WriteLine("Tu Moneda Es Insuficiente Deposita Otra");
Console.WriteLine("Introduce El Valor De Tu Moneda (Solo Se Aceptan 10, 5, 2, 1, .50");
reprice = double.Parse(Console.ReadLine());
price = price + reprice;
}
cambio = price - G1;
Console.WriteLine("Tu Cambio Es: " + cambio);
}
else if (producto == "A2")
{
Console.WriteLine("Deposite 3.5$ Pesos");
double A2 = 3.5;
tot = tot + A2;
Console.WriteLine("Introduce El Valor De Tu Moneda (Solo Se Aceptan 10, 5, 2, 1, .50");
price = double.Parse(Console.ReadLine());
while (price < A2)
{
Console.WriteLine("Tu Moneda Es Insuficiente Deposita Otra");
Console.WriteLine("Introduce El Valor De Tu Moneda (Solo Se Aceptan 10, 5, 2, 1, .50");
reprice = double.Parse(Console.ReadLine());
price = price + reprice;
}
cambio = price - A2;
Console.WriteLine("Tu Cambio Es: " + cambio);
}
else if (producto == "B2")
{
Console.WriteLine("Deposite 4$ Pesos");
double B2 = 4;
tot = tot + B2;
Console.WriteLine("Introduce El Valor De Tu Moneda (Solo Se Aceptan 10, 5, 2, 1, .50");
price = double.Parse(Console.ReadLine());
while (price < B2)
{
Console.WriteLine("Tu Moneda Es Insuficiente Deposita Otra");
Console.WriteLine("Introduce El Valor De Tu Moneda (Solo Se Aceptan 10, 5, 2, 1, .50");
reprice = double.Parse(Console.ReadLine());
price = price + reprice;
}
cambio = price - B2;
Console.WriteLine("Tu Cambio Es: " + cambio);
}
else if (producto == "C2")
{
Console.WriteLine("Deposite 4.5$ Pesos");
double C2 = 4.5;
tot = tot + C2;
Console.WriteLine("Introduce El Valor De Tu Moneda (Solo Se Aceptan 10, 5, 2, 1, .50");
price = double.Parse(Console.ReadLine());
while (price < C2)
{
Console.WriteLine("Tu Moneda Es Insuficiente Deposita Otra");
Console.WriteLine("Introduce El Valor De Tu Moneda (Solo Se Aceptan 10, 5, 2, 1, .50");
reprice = double.Parse(Console.ReadLine());
price = price + reprice;
}
cambio = price - C2;
Console.WriteLine("Tu Cambio Es: " + cambio);
}
else if (producto == "D2")
{
Console.WriteLine("Deposite 5$ Pesos");
double D2 = 5;
tot = tot + D2;
Console.WriteLine("Introduce El Valor De Tu Moneda (Solo Se Aceptan 10, 5, 2, 1, .50");
price = double.Parse(Console.ReadLine());
while (price < D2)
{
Console.WriteLine("Tu Moneda Es Insuficiente Deposita Otra");
Console.WriteLine("Introduce El Valor De Tu Moneda (Solo Se Aceptan 10, 5, 2, 1, .50");
reprice = double.Parse(Console.ReadLine());
price = price + reprice;
}
cambio = price - D2;
Console.WriteLine("Tu Cambio Es: " + cambio);
}
else if (producto == "E2")
{
Console.WriteLine("Deposite 7$ Pesos");
double E2 = 7;
tot = tot + E2;
Console.WriteLine("Introduce El Valor De Tu Moneda (Solo Se Aceptan 10, 5, 2, 1, .50");
price = double.Parse(Console.ReadLine());
while (price < E2)
{
Console.WriteLine("Tu Moneda Es Insuficiente Deposita Otra");
Console.WriteLine("Introduce El Valor De Tu Moneda (Solo Se Aceptan 10, 5, 2, 1, .50");
reprice = double.Parse(Console.ReadLine());
price = price + reprice;
}
cambio = price - E2;
Console.WriteLine("Tu Cambio Es: " + cambio);
}
else if (producto == "F2")
{
Console.WriteLine("Deposite 3$ Pesos");
double F2 = 3;
tot = tot + F2;
Console.WriteLine("Introduce El Valor De Tu Moneda (Solo Se Aceptan 10, 5, 2, 1, .50");
price = double.Parse(Console.ReadLine());
while (price < F2)
{
Console.WriteLine("Tu Moneda Es Insuficiente Deposita Otra");
Console.WriteLine("Introduce El Valor De Tu Moneda (Solo Se Aceptan 10, 5, 2, 1, .50");
reprice = double.Parse(Console.ReadLine());
price = price + reprice;
}
cambio = price - F2;
Console.WriteLine("Tu Cambio Es: " + cambio);
}
else if (producto == "G2")
{
Console.WriteLine("Deposite 4$ Pesos");
double G2 = 4;
tot = tot + G2;
Console.WriteLine("Introduce El Valor De Tu Moneda (Solo Se Aceptan 10, 5, 2, 1, .50");
price = double.Parse(Console.ReadLine());
while (price < G2)
{
Console.WriteLine("Tu Moneda Es Insuficiente Deposita Otra");
Console.WriteLine("Introduce El Valor De Tu Moneda (Solo Se Aceptan 10, 5, 2, 1, .50");
reprice = double.Parse(Console.ReadLine());
price = price + reprice;
}
cambio = price - G2;
Console.WriteLine("Tu Cambio Es: " + cambio);
}
else if (producto == "A3")
{
Console.WriteLine("Deposite 5$ Pesos");
double A3 = 5;
tot = tot + A3;
Console.WriteLine("Introduce El Valor De Tu Moneda (Solo Se Aceptan 10, 5, 2, 1, .50");
price = double.Parse(Console.ReadLine());
while (price < A3)
{
Console.WriteLine("Tu Moneda Es Insuficiente Deposita Otra");
Console.WriteLine("Introduce El Valor De Tu Moneda (Solo Se Aceptan 10, 5, 2, 1, .50");
reprice = double.Parse(Console.ReadLine());
price = price + reprice;
}
cambio = price - A3;
Console.WriteLine("Tu Cambio Es: " + cambio);
}
else if (producto == "B3")
{
Console.WriteLine("Deposite 7$ Pesos");
double B3 = 7;
tot = tot + B3;
Console.WriteLine("Introduce El Valor De Tu Moneda (Solo Se Aceptan 10, 5, 2, 1, .50");
price = double.Parse(Console.ReadLine());
while (price < B3)
{
Console.WriteLine("Tu Moneda Es Insuficiente Deposita Otra");
Console.WriteLine("Introduce El Valor De Tu Moneda (Solo Se Aceptan 10, 5, 2, 1, .50");
reprice = double.Parse(Console.ReadLine());
price = price + reprice;
}
cambio = price - B3;
Console.WriteLine("Tu Cambio Es: " + cambio);
}
Console.WriteLine("La Maquina Tiene {0} Peso(s)", tot);
Console.WriteLine("Deseas Realizar Otra Compra");
des = Console.ReadLine();
} while (des == "s" | des == "si" | des == "Si" | des == "SI" | des == "S");
Console.ReadLine();
}
}
static void Main(string[] args)
{
string ini;
Console.ForegroundColor = ConsoleColor.Black;
Console.BackgroundColor = ConsoleColor.White;
menu entrar = new menu();
Console.WriteLine("Bienvenido a La Tienda De _Bj0rD_");
ini = Console.ReadLine();
entrar.start(ini);
}
}
}
Simulador de intereses en un bancoCitarusing System;
using System.Collections.Generic;
using System.Text;
namespace ConsoleApplication5
{
class Program
{
static double calc(double a, double b, double c)
{
double total, tot=0;
double t = b / 100;
for (int d=0; d<c; d++)
{
total = a * t;
tot = tot + total;
}
return tot;
}
static void Main(string[] args)
{
int ouk = 0;
do
{
Console.WriteLine(" -- BanK0 AzTeKa -- l33t 1nc. ");
Console.WriteLine(" Digite su capital inicial ");
double capital = double.Parse(Console.ReadLine());
if (capital < 500)
{
Console.WriteLine("Capital Erronea");
ouk = 3;
}
else
{
do
{
Console.WriteLine("Que interes mensual desea tener");
double interes = double.Parse(Console.ReadLine());
if (interes > 8 || interes < 1)
{
Console.WriteLine("Taza de interes erroneo");
ouk = 1;
}
else
{
do
{
Console.WriteLine("Digite a cuantos meses quiere ver su inversion");
double mes = double.Parse(Console.ReadLine());
if (mes < 1 || mes > 12)
{
Console.WriteLine("Numero de meses erroneo");
ouk = 1;
}
else
{
double x = calc(capital, interes, mes);
Console.WriteLine("Su interes generado en {0} meses es {1}", mes, x);
double capt = x + capital;
Console.WriteLine("Su capital total es: " + capt);
Console.WriteLine("Desea hacer otra operacion 1- Si 2- No");
int sal = int.Parse(Console.ReadLine());
if (sal == 1)
{
ouk = 3;
}
else
{
ouk = 0;
}
}
} while (ouk == 1);
}
} while (ouk == 1);
}
} while (ouk == 3);
}
}
}
Verificador de contraseñas este programa lo hize ayer por una duda de alguien del foro pero era en c++ y lo hize en c# tiene un defecto ahi pero es que no lo habia visto xD
Citarusing System;
using System.Collections;
using System.Collections.Generic;
using System.Text;
namespace ConsoleApplication7
{
class Program
{
static void Main(string[] args)
{
int ou = 0;
do
{
int c = 0;
string a,b,p;
p = DateTime.Now.TimeOfDay.ToString();
string t = DateTime.Now.Minute.ToString();
string r = DateTime.Now.Second.ToString();
Console.WriteLine(p);
Console.WriteLine("{0}:{1}",t, r);
Console.WriteLine("ingrese una contraseña");
a = Console.ReadLine();
int len = a.Length;
if (len < 8 || len > 3)
{
do
{
Console.WriteLine("Digite nuevamente su contraseña");
b = Console.ReadLine();
int len1 = b.Length;
if (len == len1)
{
for (int i = 0; i < len; i++)
{
c++;
char[] z = b.ToCharArray();
char[] x = a.ToCharArray();
if (z != x)
{
Console.WriteLine("Las contraseñas no son iguales");
}
else
{
ou = 0;
}
&nbs
Simulador de biblioteca Altas y bajas de usuarios sin matrices
Citarusing System;
using System.Collections.Generic;
using System.Text;
namespace Biblio_UVM
{
class LibrosUvm
{
/* Libros */
string[] autores =
{
"1- ARTURO PEREZ-REVERTE", "2- DAN BROWN", "3- ERNESTO CHE GUEVARA", "4- GABRIEL GARCIA MARQUEZ", "5- HG WELLS",
"6- ISAAC ASIMOV", "7- MIGUEL DE CERVANTES", "8- RAY BRADBURY", "9- RAMON SAMPEDRO", "10- WILLIAM GIBSON",
};
public string[] Buscar(string palabra)
{
string[] resultado;
int cantidad = 0;
int[] posiciones = new int[autores.Length];
for (int i = 0; i < autores.Length; i++)
if (autores.IndexOf(palabra) >= 0)
{
posiciones[cantidad] = i;
cantidad++;
}
resultado = new string[cantidad];
for (int i = 0; i < cantidad; i++)
resultado = autores[posiciones];
return (resultado);
}
}
class program
{
static void Main(string[] args)
{
string uno = ("#1000 CABO TRAFALGAR");
string dos = ( "#2000 ANGELES Y DEMONIOS & #2001 EL CODIGO DA VINCI" );
string tres = ( "#3000 DIARIOS DE MOTOCICLETA. NOTAS DE VIAJE" );
string cuatro = ( "#4000 MEMORIA DE MIS PUTAS TRISTES" );
string cinco = ( "#5000 La Maquina del Tiempo & #5001 La Guerra de los Mundos" );
string seis = ( "#6000 Yo Robot" );
string siete = ( "#7000 DON QUIJOTE DE LA MANCHA" );
string ocho = ( "#8000 Fahrenheit 451" );
string nueve = ( "#9000 CARTAS DESDE EL INFIERNO" );
string diez = ( "#0100 Neuromancer" );
string sac;
string aut1 = "a", aut2 = "a", aut3 = "a", aut4 = "a", aut5 = "a", aut6 = "a", aut7 = "a", aut8 = "a", aut9 = "a", aut10 = "a", aut11 = "a";
string lib1 = "a", lib2 = "a", lib3 = "a", lib4 = "a", lib5 = "a", lib6 = "a", lib7 = "a", lib8 = "a", lib9 = "a", lib10 = "a", lib11 = "a";
string user1 = "a", user2 = "a", user3 = "a", user4 = "a", user5 = "a", user6 = "a", user7 = "a", user8 = "a", user9 = "a", user10 = "a", user11 = "a";
string mat1="a", mat2 = "a", mat3 = "a", mat4 = "a", mat5 = "a", mat6 = "a", mat7 = "a", mat8 = "a", mat9 = "a", mat10 = "a", mat11 = "a";
string cont1 = "a", cont2 = "a", cont3 = "a", cont4 = "a", cont5 = "a", cont6 = "a", cont7 = "a", cont8 = "a", cont9 = "a", cont10 = "a", cont11 = "a";
string mat, cont, exit;
double ou = 0, aw = 0, altybaj, totlibs=0;
double users = 0, inc = 0, inccont = 0, lib = 0, prests = 0;
LibrosUvm d = new LibrosUvm();
string palabra;
string[] resultado;
double opc;
do
{
do
{
double granted = 0;
Console.ForegroundColor = ConsoleColor.DarkGreen;
Console.WriteLine(" !!! Biblio UVM");
Console.ForegroundColor = ConsoleColor.Red;
Console.WriteLine(" -----------------------------------------");
Console.WriteLine(" | Escoja Una Opcion Porfavor |");
Console.WriteLine(" -----------------------------------------");
Console.ForegroundColor = ConsoleColor.DarkGreen;
Console.WriteLine(" | 1-. Busqueda de libros |");
Console.WriteLine(" | 2-. Altas y Bajas Libros y Usuarios |");
Console.WriteLine(" | 3-. Altas y Bajas De Prestamos |");
Console.WriteLine(" | 4-. Salir Del Programa |");
Console.WriteLine(" |_______________________________________|");
opc = double.Parse(Console.ReadLine());
Console.Clear();
do
{
/* Apartir de aqui! Empieza Codigo de menus */
if (opc == 1)
{
Console.ForegroundColor = ConsoleColor.Red;
Console.WriteLine(" -----------------------------------------");
Console.WriteLine(" | Busqueda de Libros |");
Console.WriteLine(" -----------------------------------------");
Console.ForegroundColor = ConsoleColor.DarkGreen;
Console.WriteLine(" | 1-. Busqueda Por Autor |");
Console.WriteLine(" -----------------------------------------");
double search = double.Parse(Console.ReadLine());
if (search == 1)
{
Console.Write("Introduce Parte del Nombre del Autor: ");
palabra = Console.ReadLine();
palabra = palabra.Trim();
Console.Write("Buscando: \"{0}\" ", palabra);
palabra = palabra.ToUpper();
Console.WriteLine("Buscando: \"{0}\"", palabra);
Console.WriteLine("Libros que contienen \"{0}\":", palabra);
resultado = d.Buscar(palabra);
foreach (string s in resultado)
Console.WriteLine(s);
Console.WriteLine("Digita La Clave del libro deseado");
double desp = double.Parse(Console.ReadLine());
Console.WriteLine("Clave - Nombre del libro");
if (desp == 1)
Console.WriteLine(uno);
else if (desp == 2)
Console.WriteLine(dos);
else if (desp == 3)
Console.WriteLine(tres);
else if (desp == 4)
Console.WriteLine(cuatro);
else if (desp == 5)
Console.WriteLine(cinco);
else if (desp == 6)
Console.WriteLine(seis);
else if (desp == 7)
Console.WriteLine(siete);
else if (desp == 8)
Console.WriteLine(ocho);
else if (desp == 9)
Console.WriteLine(nueve);
else if (desp == 10)
Console.WriteLine(diez);
Console.WriteLine(" -----------------------------------------");
Console.WriteLine(" | Deseas Sacar un Libro De Este Autor? |");
Console.Write(" | "); sac = Console.ReadLine();
if (sac == "si" || sac == "SI")
{
aw = 1;
opc = 3;
}
else if (sac == "no" || sac == "NO")
ou = 1;
}
}
else if (opc == 2)
{
Console.Clear();
Console.ForegroundColor = ConsoleColor.White;
Console.WriteLine("*----...Entrando a Biblio UVM...----*");
Console.WriteLine("| Digita tu Matricula "); mat = Console.ReadLine();
Console.WriteLine("| Digita tu Contraseña "); cont = Console.ReadLine();
if (mat == cont)
{
double inval = 0;
Console.ForegroundColor = ConsoleColor.Blue;
Console.WriteLine(" -----------------------------------------");
Console.WriteLine(" | Altas y Bajas Usuarios & Libros |");
Console.WriteLine(" -----------------------------------------");
Console.ForegroundColor = ConsoleColor.DarkGreen;
Console.WriteLine(" | 1-. Altas de Usuarios |");
Console.WriteLine(" | 2-. Bajas Usuarios |");
Console.WriteLine(" | 3-. Altas Libros |");
Console.WriteLine(" | 4-. Bajas Libros |");
Console.WriteLine(" -----------------------------------------");
Console.WriteLine(" |"); altybaj = double.Parse(Console.ReadLine());
if (altybaj == 1)
{
Console.WriteLine(" -----------------------------------------");
Console.WriteLine(" | Registro de Nuevos Usuarios |");
users++;
do
{
if (users == 1)
{
Console.WriteLine(" |---------------------------------------|");
Console.Write(" | Nombre De Usuario:"); user1 = Console.ReadLine();
Console.Write(" | Matricula:"); mat1 = Console.ReadLine();
Console.Write(" | Digite su contraseña nueva:"); cont1 = Console.ReadLine();
Console.Write(" | Confirme Su Contraseña:"); string conf = Console.ReadLine();
if (cont1 == conf)
{
Console.Clear();
Console.WriteLine(" |Felicidades Cuenta Habilitada|");
Console.WriteLine(" |Bienvenido {0} ", user1);
Console.WriteLine(" |Tu Codigo de acceso es \"A21\"");
inval = 0;
}
else
{ inc = 1; inval = 1; }
}
if (users == 2)
{
Console.WriteLine(" |---------------------------------------|");
Console.Write(" | Nombre De Usuario:"); user2 = Console.ReadLine();
Console.Write(" | Matricula:"); mat2 = Console.ReadLine();
Console.Write(" | Digite su contraseña nueva:"); cont2 = Console.ReadLine();
Console.Write(" | Confirme Su Contraseña:"); string conf = Console.ReadLine();
if (cont2 == conf)
{
Console.Clear();
Console.WriteLine(" |Felicidades Cuenta Habilitada|");
Console.WriteLine(" |Bienvenido {0} ", user2);
Console.WriteLine(" |Tu Codigo de acceso es \"B32\"");
inval = 0;
}
else
{inc = 1; inval = 1;}
}
if (users == 3)
{
Console.WriteLine(" |---------------------------------------|");
Console.Write(" | Nombre De Usuario:"); user3 = Console.ReadLine();
Console.Write(" | Matricula:"); mat3 = Console.ReadLine();
Console.Write(" | Digite su contraseña nueva:"); cont3 = Console.ReadLine();
Console.Write(" | Confirme Su Contraseña:"); string conf = Console.ReadLine();
if (cont3 == conf)
{
Console.Clear();
Console.WriteLine(" |Felicidades Cuenta Habilitada|");
Console.WriteLine(" |Bienvenido {0} ", user3);
Console.WriteLine(" |Tu Codigo de acceso es \"C57\"");
inval = 0;
}
else
{ inc = 1; inval = 1; }
}
if (users == 4)
{
Console.WriteLine(" |---------------------------------------|");
Console.Write(" | Nombre De Usuario:"); user4 = Console.ReadLine();
Console.Write(" | Matricula:"); mat4 = Console.ReadLine();
Console.Write(" | Digite su contraseña nueva:"); cont4 = Console.ReadLine();
Console.Write(" | Confirme Su Contraseña:"); string conf = Console.ReadLine();
if (cont4 == conf)
{
Console.Clear();
Console.WriteLine(" |Felicidades Cuenta Habilitada|");
Console.WriteLine(" |Bienvenido {0} ", user4);
Console.WriteLine(" |Tu Codigo de acceso es \"D67\"");
inval = 0;
}
else
{ inc = 1; inval = 1; }
}
if (users == 5)
{
Console.WriteLine(" |---------------------------------------|");
Console.Write(" | Nombre De Usuario:"); user5 = Console.ReadLine();
Console.Write(" | Matricula:"); mat5 = Console.ReadLine();
Console.Write(" | Digite su contraseña nueva:"); cont5 = Console.ReadLine();
Console.Write(" | Confirme Su Contraseña:"); string conf = Console.ReadLine();
if (cont5 == conf)
{
Console.Clear();
Console.WriteLine(" |Felicidades Cuenta Habilitada|");
Console.WriteLine(" |Bienvenido {0} ", user5);
Console.WriteLine(" |Tu Codigo de acceso es \"E44\"");
inval = 0;
}
else
{ inc = 1; inval = 1; }
}
if (users == 6)
{
Console.WriteLine(" |---------------------------------------|");
Console.Write(" | Nombre De Usuario:"); user6 = Console.ReadLine();
Console.Write(" | Matricula:"); mat6 = Console.ReadLine();
Console.Write(" | Digite su contraseña nueva:"); cont6 = Console.ReadLine();
Console.Write(" | Confirme Su Contraseña:"); string conf = Console.ReadLine();
if (cont6 == conf)
{
Console.Clear();
Console.WriteLine(" |Felicidades Cuenta Habilitada|");
Console.WriteLine(" |Bienvenido {0} ", user6);
Console.WriteLine(" |Tu Codigo de acceso es \"F89\"");
inval = 0;
}
else
{ inc = 1; inval = 1; }
}
if (users == 7)
{
Console.WriteLine(" |---------------------------------------|");
Console.Write(" | Nombre De Usuario:"); user7 = Console.ReadLine();
Console.Write(" | Matricula:"); mat7 = Console.ReadLine();
Console.Write(" | Digite su contraseña nueva:"); cont7 = Console.ReadLine();
Console.Write(" | Confirme Su Contraseña:"); string conf = Console.ReadLine();
if (cont7 == conf)
{
Console.Clear();
Console.WriteLine(" |Felicidades Cuenta Habilitada|");
Console.WriteLine(" |Bienvenido {0} ", user7);
Console.WriteLine(" |Tu Codigo de acceso es \"G12\"");
inval = 0;
}
else
{ inc = 1; inval = 1; }
}
if (users == 8)
{
Console.WriteLine(" |---------------------------------------|");
Console.Write(" | Nombre De Usuario:"); user8 = Console.ReadLine();
Console.Write(" | Matricula:"); mat8 = Console.ReadLine();
Console.Write(" | Digite su contraseña nueva:"); cont8 = Console.ReadLine();
Console.Write(" | Confirme Su Contraseña:"); string conf = Console.ReadLine();
if (cont8 == conf)
{
Console.Clear();
Console.WriteLine(" |Felicidades Cuenta Habilitada|");
Console.WriteLine(" |Bienvenido {0} ", user8);
Console.WriteLine(" |Tu Codigo de acceso es \"H56\"");
inval = 0;
}
else
{ inc = 1; inval = 1; }
}
if (users == 9)
{
Console.WriteLine(" |---------------------------------------|");
Console.Write(" | Nombre De Usuario:"); user9 = Console.ReadLine();
Console.Write(" | Matricula:"); mat9 = Console.ReadLine();
Console.Write(" | Digite su contraseña nueva:"); cont9 = Console.ReadLine();
Console.Write(" | Confirme Su Contraseña:"); string conf = Console.ReadLine();
if (cont9 == conf)
{
Console.Clear();
Console.WriteLine(" |Felicidades Cuenta Habilitada|");
Console.WriteLine(" |Bienvenido {0} ", user9);
Console.WriteLine(" |Tu Codigo de acceso es \"I04\"");
inval = 0;
}
else
{ inc = 1; inval = 1; }
}
if (users == 10)
{
Console.WriteLine(" |---------------------------------------|");
Console.Write(" | Nombre De Usuario:"); user10 = Console.ReadLine();
Console.Write(" | Matricula:"); mat10 = Console.ReadLine();
Console.Write(" | Digite su contraseña nueva:"); cont10 = Console.ReadLine();
Console.Write(" | Confirme Su Contraseña:"); string conf = Console.ReadLine();
if (cont10 == conf)
{
Console.Clear();
Console.WriteLine(" |Felicidades Cuenta Habilitada|");
Console.WriteLine(" |Bienvenido {0} ", user10);
Console.WriteLine(" |Tu Codigo de acceso es \"J76\"");
inval = 0; ;
}
else
{ inc = 1; inval = 1; }
}
if (users == 11)
&n
Calculo de numeros primosEste programa muestra el numero de numeros primos que quieras ver (esta preparado para los primero 50 numero primos)
Citarusing System;
using System.Collections.Generic;
using System.Text;
namespace Primos
{
class Program
{
static double prim(double a)
{
double cont = 0, contneg = 0;
for (int b = 1; a >= b; b++)
{
double c = a / b;
double d = c % 2;
if (d == 0 || d == 1)
{
cont++;
}
else
{
contneg++;
}
}
if (cont == 2)
{
return a;
}
else
{
int g = 0;
return g;
}
}
static void Main(string[] args)
{
string opc = "n";
int contl=0;
double[] primos = new double[50];
for (int w = 1; w <= 229; w++)
{
double t = prim(w);
if (t > 0)
{
primos[contl] = t;
contl++;
}
}
Console.WriteLine("Cuantos valores quieres desplegar?");
int val = int.Parse(Console.ReadLine());
for (int s = 0; s < val; s++)
{
Console.WriteLine("{0}-. {1} ",s+1 , primos);
}
do
{
int cont = 0;
Console.WriteLine(" --- Numeros Primos By _Bj0rD_ --- ");
Console.WriteLine("Dame El numero de primos a mostrar ");
int num = int.Parse(Console.ReadLine());
for (int w = 1; w <= 229; w++)
{
double x = prim(w);
if (x >= 1)
{
cont++;
Console.WriteLine("{0}-. {1} ", cont, x);
if (num == cont)
{
w = 230;
}
}
}
Console.WriteLine("Reiniciar S/N");
opc = Console.ReadLine();
} while (opc == "S" || opc == "s");
}
}
}
Division de dos numerosCitarusing System;
using System.Collections.Generic;
using System.Text;
namespace test
{
class Program
{
static void divi1(double a, double b)
{
double res;
res = a / b;
Console.WriteLine(res);
return;
}
static double divid2(double a, double b)
{
double res;
res = a / b;
return res;
}
[STAThread]
static void Main(string[] args)
{
double a, b;
Console.WriteLine("------Divisiones x _Bj0rD_------");
Console.WriteLine(" Dame El Primer Valor ");
a = double.Parse(Console.ReadLine());
Console.WriteLine(" Dame El Segundo Valor");
b = double.Parse(Console.ReadLine());
divi1(a, b);
divid2(a, b);
double res1 = divid2(a, b);
Console.WriteLine("res1");
Console.ReadLine();
}
}
}
Calculo de salariosCitarusing System;
using System.Collections.Generic;
using System.Text;
namespace test
{
class Program
{
static void salary(double sb, double ht)
{
double sal, res, salint;
sal = sb * ht;
res = sal * .05;
salint = sal - res;
Console.WriteLine("Tu Salario Integral es: {0}", salint);
return;
}
static void Main(string[] args)
{
double sb, ht;
string op1, op, opc;
do
{
Console.WriteLine(" --- Salarios x _Bj0rD_ --- ");
do
{
Console.WriteLine(" - Digita Tu Salario Base - ");
sb = double.Parse(Console.ReadLine());
if (sb >= 70)
{
op = "n";
Console.Clear();
}
else
{
Console.WriteLine("El Salario Base No es Correcto");
op = "S";
}
} while (op == "S");
do
{
Console.WriteLine(" - Digita tus Horas de Trabajo - ");
ht = double.Parse(Console.ReadLine());
if (ht < 10 || ht > 50)
{
Console.WriteLine("las horas de trabajo deben ser mayores a 10");
Console.WriteLine("Y menores que 50");
op1 = "S";
}
else
{
op1 = "n";
Console.Clear();
}
} while (op1 == "S");
salary(sb, ht);
Console.WriteLine("Deseas Calcular Otro Salario? S/N");
opc = Console.ReadLine();
} while (opc == "S" || opc == "s");
Console.WriteLine("GraTz");
Console.ReadLine();
}
}
}
Multiplicacion , Raiz cuadrada y cuboCitarusing System;
using System.Collections.Generic;
using System.Text;
namespace Ejercicio1
{
class Program
{
static void Main(string[] args)
{
double a = 0, b = 0;
Console.ForegroundColor = ConsoleColor.White;
Console.WriteLine(" Ejercicio 1 PoO ");
Console.ForegroundColor = ConsoleColor.Green;
Console.WriteLine(" Introduzca Una Variable ");
a = double.Parse(Console.ReadLine());
Console.WriteLine(" Introduzca La Segunda Variable");
b = double.Parse(Console.ReadLine());
double c = a * b;
Console.WriteLine(" El Producto de las variables es: " + c);
double d = c * c * c;
Console.WriteLine(" El Cubo del producto es: " + d);
double e = Math.Sqrt(d);
Console.WriteLine(" La Raiz Cuadrada Del Cubo es: " + e);
Console.ReadLine();
}
}
}
Comisiones por ventaCitarusing System;
using System.Collections.Generic;
using System.Text;
namespace Ejercicio1
{
class Program
{
static void Main(string[] args)
{
string ou;
do
{
Console.Clear();
double venta = 0;
Console.ForegroundColor = ConsoleColor.Red;
Console.WriteLine("--------------------------------------------");
Console.WriteLine("| Comisiones _Bj0rD_ |");
Console.Write("| Digite el Monto de Su Venta ........ ");
venta = double.Parse(Console.ReadLine());
if (venta > 7000)
{
double sal = venta * .05;
Console.WriteLine("| Su Comision es...... " + sal);
}
else if(venta <= 0)
{
Console.WriteLine("| El monto de la venta no es valido..... |");
}
else
{
double sal1 = venta * .03;
Console.WriteLine("| Su Comision es...... " + sal1);
}
Console.WriteLine("| Desea Salir ?? (s/n) |");
ou = Console.ReadLine();
} while (ou == "n" || ou == "N");
}
}
}
pares del 1 al 100, nones del 1 al 100, de la z a la a, de la A a la ZCitarusing System;
using System.Collections.Generic;
using System.Text;
namespace test
{
class Program
{
static void Main(string[] args)
{
double a = 0;
while (a < 100)
{
a++;
a++;
Console.WriteLine(a);
}
double b = 1;
while (b < 100)
{
Console.WriteLine(b);
b++;
b++;
}
char c = 'z';
while (c >= 'a')
{
Console.WriteLine(c);
c--;
}
char x = 'A';
while (x <= 'Z')
{
Console.WriteLine(x);
x++;
}
Console.ReadLine();
}
}
}
Buenas.
Te he reescrito el ejemplo de la máquina expendedora de una forma muchísimo más eficiente, hechale un vistazo que seguro que te es interesante.
using System;
using System.Collections.Generic;
using System.Text;
namespace ConsoleApplication1
{
struct Producto
{
public string ID;
public string Nombre;
public double Precio;
public Producto(string id, string nombre, double precio)
{
ID = id;
Nombre = nombre;
Precio = precio;
}
}
class menu
{
Producto[] listaDeProductos = new Producto[] {
new Producto("A1", "Doritos", 5),
new Producto("B1", "Crush De Naranja", 6),
new Producto("C1", "Pizza", 15),
new Producto("D1", "Coca Cola", 6),
new Producto("E1", "Cigarros", 21),
new Producto("F1", "Ruffles", 4.5),
new Producto("G1", "Halls", 3.5),
new Producto("A2", "Trident", 3.5),
new Producto("B2", "HotNuts", 4),
new Producto("C2", "GoldenNuts", 4.5),
new Producto("D2", "Panditas", 5),
new Producto("E2", "Sprite", 7),
new Producto("F2", "Enchilados", 3),
new Producto("G2", "MaxAir", 4),
new Producto("A3", "Crujitos", 5),
new Producto("B3", "Sangria", 7),
};
public void start(string entrar)
{
Dictionary<String, Producto> ProductosEnLaMaquina = new Dictionary<string, Producto>();
for (int buc = 0; buc < listaDeProductos.Length; buc++)
ProductosEnLaMaquina.Add(listaDeProductos[buc].ID, listaDeProductos[buc]);
double total = 0;
string des = "";
do
{
Console.WriteLine("MakiNa ExpENdEdorA De _Bj0rD_");
foreach (Producto p in ProductosEnLaMaquina.Values)
Console.WriteLine(p.ID + " --- " + p.Nombre);
string producto = Console.ReadLine().ToUpper();
while(!ProductosEnLaMaquina.ContainsKey(producto))
{
Console.WriteLine("Producto no disponible, por favor seleccione otro.");
producto = Console.ReadLine().ToUpper();
}
Console.WriteLine("Deposite " + ProductosEnLaMaquina[producto].Precio.ToString() + "$ Pesos");
double price = SolicitarMoneda();
while (price < ProductosEnLaMaquina[producto].Precio)
{
Console.WriteLine("Faltan " + (ProductosEnLaMaquina[producto].Precio - price).ToString() + " Peso(s)");
price += SolicitarMoneda();
}
Console.WriteLine("Su cambio: " + (price - ProductosEnLaMaquina[producto].Precio).ToString());
total += ProductosEnLaMaquina[producto].Precio;
Console.WriteLine("La máquina tiene " + total.ToString() + " Peso(s)");
Console.WriteLine("¿Desea realizar otra compra?");
des = Console.ReadLine();
} while (des.ToLower() == "s" || des.ToLower() == "si");
Console.ReadLine();
}
private double SolicitarMoneda()
{
bool monedaCorrecta = false;
double res = 0;
while (!monedaCorrecta)
{
Console.WriteLine("Introduzca una moneda (Solo Se Aceptan 10, 5, 2, 1, .50");
try
{
res = double.Parse(Console.ReadLine());
if (res != 0.5 && res != 1 && res != 2 && res != 5 && res != 10)
Console.WriteLine("Moneda no aceptada, solo se aceptan monedas de 10, 5, 2, 1, .50");
else
monedaCorrecta = true;
}
catch {
Console.WriteLine("Por favor, no intente introducir objetos extraños en la ranura de la moneda.");
}
}
return res;
}
}
class Program
{
static void Main(string[] args)
{
string ini;
Console.ForegroundColor = ConsoleColor.Black;
Console.BackgroundColor = ConsoleColor.White;
menu entrar = new menu();
Console.WriteLine("Bienvenido a la tienda del Dr. Gusman");
ini = Console.ReadLine();
entrar.start(ini);
}
}
}
Un saludo.
Todos son en modod de consola?? , verdad
bueno aki dejo otro link con otros ejercicios, para k se hagan en uno solo el hilo
http://foro.elhacker.net/index.php/topic,185614.0.html
Averiguar la letra del DNI de España. Introduce los números y te muestra su letra.
using System;
using System.Collections.Generic;
using System.Text;
namespace DNILetra
{
class Program
{
static void Main(string[] args)
{
Dictionary<int,char> Letras = new Dictionary<int,char>();
Letras.Add(0,'T'); Letras.Add(12,'N');
Letras.Add(1,'R'); Letras.Add(13,'J');
Letras.Add(2,'W'); Letras.Add(14,'Z');
Letras.Add(3,'A'); Letras.Add(15,'S');
Letras.Add(4,'G'); Letras.Add(16,'Q');
Letras.Add(5,'M'); Letras.Add(17,'V');
Letras.Add(6,'Y'); Letras.Add(18,'H');
Letras.Add(7,'F'); Letras.Add(19,'L');
Letras.Add(8,'P'); Letras.Add(20,'C');
Letras.Add(9,'D'); Letras.Add(21,'K');
Letras.Add(10,'X'); Letras.Add(22,'E');
Letras.Add(11,'B');
Console.Write("Introduce nº DNI: ");
string snumber = Console.ReadLine();
int inumber = -1;
if ((snumber.Length != 8) || (!Int32.TryParse(snumber, out inumber)))
{
throw new ArgumentException("No válido.");
}
else
{
inumber = inumber % 23;
Console.WriteLine("Letra: {0}",Letras[inumber]);
}
Console.ReadKey();
}
}
}
Modificaciones a Autorbuses. Creo que de esta forma queda más claro y didáctico para novatos... aunque no es, ni de lejos, la solución ideal.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Linq.Expressions;
namespace ElHacker
{
class Program
{
public Program()
{
Console.WriteLine(" - AD0 By _Bj0rD_ - ");
SacarBillete();
}
private void SacarBillete()
{
double precio = 0;
int numeroBoletos = ObtenerNumeroBoletos();
string franja = ObtenerFranjaHoraria();
precio = numeroBoletos * CalculaPrecio(franja);
Console.WriteLine("El total por {0} boletos durante el/la {1} es: {2}", numeroBoletos, franja, precio);
Console.WriteLine("Desea Reiniciar? S/N");
string s = Console.ReadLine().ToUpper();
if (s.StartsWith("S"))
SacarBillete();
}
private int CalculaPrecio(string franja)
{
if (franja.StartsWith("D"))
return 50;
if (franja.StartsWith("T"))
return 75;
return 100;
}
private string ObtenerFranjaHoraria()
{
Console.Write("Su viaje sera de DIA, TARDE o NOCHE?: ");
string franja = Console.ReadLine().ToUpper();
if (!franja.StartsWith("D") && !franja.StartsWith("T") && !franja.StartsWith("N"))
{
Console.WriteLine("Franja no válida. Inténtelo de nuevo.");
return ObtenerFranjaHoraria();
}
return franja;
}
private int ObtenerNumeroBoletos()
{
Console.Write("Digite el numero de boletos que adquirira: ");
int boletos = LeerNumero();
if (boletos < 1)
{
Console.Write("Debe comprar al menos un boleto.");
return ObtenerNumeroBoletos();
}
return boletos;
}
private int LeerNumero()
{
int retorno = 0;
try
{
retorno = Convert.ToInt32(Console.ReadLine());
}
catch (FormatException)
{
Console.WriteLine("No es un dato correcto. Inténtelo de nuevo: ");
return LeerNumero();
}
return retorno;
}
static void Main(string[] args)
{
new Program();
}
}
}
Amigos buen dia un placer estar en este foro, quisiera un poquito de ayuda. En la universidad nos piden un proyecto de convertir numeros enteros en romanos con clases y no se por donde empezar podrian darme alguna sugerencia. Gracias de Antemano
Cita de: MLEON SCOTT en 28 Octubre 2008, 13:56 PM
Amigos buen dia un placer estar en este foro, quisiera un poquito de ayuda. En la universidad nos piden un proyecto de convertir numeros enteros en romanos con clases y no se por donde empezar podrian darme alguna sugerencia. Gracias de Antemano
man abre tu duda en otro hilo para ayudarte mas ordenadamente , y coloca lo que llevas hecho
son puras aplicaciones en consola y no lo especifican.
aparte dice programas en c#, te imaginas algo grafico, deberian cambiar el nombre dle tema :-X
Que es esto?? Un post para poner programas del colegio? Pos aki teneis un par mas.
Es un juego en el k escribes una frase i luego te pregunta k palabra habia en la posicion x.
using System;
using System.Collections.Generic;
using System.Text;
namespace JocDeParaules
{
class Program
{
public const char FI = '\r';
public const int N = 20;
static void Main(string[] args)
{
Random r = new Random();
int x,posicio=0,i=0;
x = Environment.TickCount;
char c;
bool encert=false;
char[][] frase;
char[] paraula = new char[N];
Console.WriteLine("Instrodueix el nombre de paraules");
x = Convert.ToInt32(Console.ReadLine());
frase = new char[x][];
Console.WriteLine("Introdueix una frase:");
c = Convert.ToChar(Console.Read());
Console.WriteLine("Et keden 10 segons per memoritzar la frase, bona sort");
while (Environment.TickCount <= x + 4000000) ;
while (Environment.TickCount <= x + 40000);
Console.Read();
Console.Clear();
while (c != FI)
{
PasaSeparador(ref c);
if (c != FI) paraula = ObtenirParaula(ref c, N);
frase[i] = paraula;
i++;
}
posicio = r.Next(i);
while (!encert)
{
Console.WriteLine("Quina paraula hi ha a la posicio " + (posicio+1));
Console.ReadLine();
c = (char)Console.Read();
paraula = ObtenirParaula(ref c, N);
encert=Igual(frase[posicio], paraula);
}
if (encert) Console.WriteLine("Molt be, l'has encertat");
}
static bool Igual(char[] t, char[] t2)
{
int i=0;
bool igual = true;
if (t.Length == t2.Length)
{
while (i < t2.Length && igual)
{
if (t[i] != t2[i])
igual = false;
else
i++;
}
}
else
igual = false;
return igual;
}
static bool Sep(char c)
{
return (c == ' ' || c == '.' || c == ',' || c == ';');
}
static bool EsLletra(char c)
{
return ((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z'));
}
static char[] ObtenirParaula(ref char c, int max)
{
char[] t = new char[max];
char[] tCopia;
int nElem = 0;
while (EsLletra(c) && nElem < max)
{
t[nElem] = c;
nElem++;
c = (char)Console.Read();
}
tCopia = CopiaPlena(t, nElem);
return tCopia;
}
static char[] CopiaPlena(char[] t, int nElem)
{
int i;
char[] tCopia = new char[nElem];
for (i = 0; i < nElem; i++) tCopia[i] = t[i];
return tCopia;
}
static int PasaSeparador(ref char c)
{
int nSep = 0;
while (Sep(c))
{
nSep++;
c = (char)Console.Read();
}
return nSep;
}
static void Mostrar(char[] [] t)
{
int i;
for (i = 0; i < t.Length; i++) Console.Write(t[i]);
Console.Write("\n");
}
}
}
Muestra kuantas letras hay de cada letra en el .txt
sing System;
using System.Collections.Generic;
using System.Text;
using System.IO;
namespace histograma
{
class Program
{
static void Main(string[] args)
{
const string origen = "dades.txt";
const int N=26;
int[] tFreq = new int[N];
char x;
int i, pos;
StreamReader sr;
for (i=0;i<N;i++) tFreq[i]=0;
Console.Clear();
if (File.Exists(origen))
{
Console.WriteLine("CONTINGUT DEL FITXER " + origen);
Console.WriteLine("\nHISTOGRAMA DE LLETRES\n");
sr = new StreamReader(origen);
while (!sr.EndOfStream)
{
x = (char)sr.Read();
//Console.Write(x); //Activar para ver el txt
if (x >= 'A' && x <= 'Z')
{
x = (char)(((int)x) + 32);
}
if (x >= 'a' && x <= 'z')
{
pos = (int)x - 97;
tFreq[pos] = tFreq[pos] + 1;
}
}
for (i = 0; i < N; i++)
{
Console.Write((char)(i+65));
Console.Write(" : ");
if (tFreq[i] >= 10) Console.Write(tFreq[i]);
else MostrarAsteriscs(tFreq[i]);
Console.Write("\n");
}
sr.Close();
}
else Console.WriteLine("Fitxer inexistent");
}
static void MostrarAsteriscs(int n)
{
int i;
for (i = 1; i <= n; i++) Console.Write("*");
}
}
}
DADO UN NUMERO ENTERO QUE CONVIERTA AH NUMEROS ROMANOS
int Miles, Resto, Cen, Dec, Uni,N;
Console.Write("Ingrese un Numero:");
N=int.Parse(Console.ReadLine());
Miles = N / 1000;
Resto = N % 1000;
Cen = Resto / 100;
Resto = Resto % 100;
Dec = Resto / 10;
Resto = Resto % 10;
Uni = Resto;
Console.Write("En Número Romanos es : ");
switch (Miles)
{
case 1: Console.Write("M"); break;
case 2: Console.Write("MM"); break;
case 3: Console.Write("MMM"); break;
}
switch (Cen)
{
case 1: Console.Write("C"); break;
case 2: Console.Write("CC"); break;
case 3: Console.Write("CCC"); break;
case 4: Console.Write("CD"); break;
case 5: Console.Write("D"); break;
case 6: Console.Write("DC"); break;
case 7: Console.Write("DCC"); break;
case 8: Console.Write("DCCC"); break;
case 9: Console.Write("CM"); break;
}
switch (Dec)
{
case 1: Console.Write("X");
break;
case 2: Console.Write("XX");
break;
case 3: Console.Write("XXX");
break;
case 4: Console.Write("XL");
break;
case 5: Console.Write("L");
break;
case 6: Console.Write("LX");
break;
case 7: Console.Write("LXX");
break;
case 8: Console.Write("LXXX");
break;
case 9: Console.Write("XC");
break;
}
switch (Uni)
{
case 1: Console.Write("I"); break;
case 2: Console.Write("II"); break;
case 3: Console.Write("III"); break;
case 4: Console.Write("IV"); break;
case 5: Console.Write("V"); break;
case 6: Console.Write("VI"); break;
case 7: Console.Write("VII"); break;
case 8: Console.Write("VIII"); break;
case 9: Console.Write("IX"); break;
}
aqui les dejo un programilla no esta muy pro pero alguien le servira
saludos
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace WindowsApplication1
{
public partial class FormTarea1 : Form
{
public FormTarea1()
{
InitializeComponent();
}
private void cmdTiempo_Click(object sender, EventArgs e)
{
// Programa que calcule el tiempo en recorrer x distancia
// by sylar
// Declaracion de las variables
double Tiempo;
// calculo del Tiempo
Tiempo = 60 * 1.609 / 80;
// salida del Tiempo
txtTiempo.Text = Tiempo.ToString();
}
private void cmdSalida_Click(object sender, EventArgs e)
{
Close();
}
}
}
:D
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace WindowsApplication1
{
public partial class Frmtarea18 : Form
{
public Frmtarea18()
{
InitializeComponent();
}
private void cmdCalculo_Click(object sender, EventArgs e)
{
//Programa que captura tres precios en el principal, llame a una funcion que calcula
//el iva del 1primer precio e imprima el 1 primer precio en el principal, se deberas hacar para le 2 segundo y 3 tercero.
//modo visual
//sylar
//Declaracion de variables
double P1, P2, P3, Res, Res2, Res3;
//Asignacion de valor a las variables
P1 = System.Int32.Parse(txtPrecio1.Text);
P2 = System.Int32.Parse(txtPrecio2.Text);
P3 = System.Int32.Parse(txtPrecio3.Text);
//Llamar funcion
Res = Iva(P1);
//Llamar funcion
Res2 = Iva2(P2);
//Llamar funcion
Res3 = Iva3(P3);
//Salida de datos
txtP1.Text = Res.ToString();
//Salida de datos
txtP2.Text = Res2.ToString();
//Salida de datos
txtP3.Text = Res3.ToString();
}
//Funcion
double Iva(double P1s)
{
//Calculo del Iva
return P1s * 1.1;
}
//Funcion
double Iva2(double P2s)
{
//Calculo del Iva
return P2s * 1.1;
}
//Funcion
double Iva3(double P3s)
{
//Calculo del iva
return P3s * 1.1;
}
private void cmdSalida_Click(object sender, EventArgs e)
{
Close();
}
}
}
Hola una pregunta, tengo un programa con botones, a estos como puedo ponerles sonido a una frecuancia definida...
espero me puedan ayudar gracias.
Saludos.
using System;
using System.Collections.Generic;
using System.Text;
namespace ConsoleApplication1
{
class Program
{
static int[] Edades = new int[20];
static void Main(string[] args)
{
int op;
string leido;
do
{
Console.Clear();
Console.WriteLine("1. Almacenar Datos");
Console.WriteLine("2. Recuperar Datos");
Console.Write("Elige una opcion:");
op = int.Parse(Console.ReadLine());
switch (op)
{
case 1: AlmacenarEdades();
break;
case 2: RecuperarDatos();
break;
default: Console.Write("Opcion incorrecta");
break;
}
Console.Write("Desea salir?: s/n");
leido = Console.ReadLine();
} while (leido != "s");
Console.ReadKey();
}
static void AlmacenarEdades()
{
Console.WriteLine("Introduce 20 edades: ");
for (int x = 0; x < 20; x++)
{
Edades
- = int.Parse(Console.ReadLine());
}
}
static void RecuperarDatos()
{
Console.WriteLine("Las edades introducidas fueron: ");
for (int x = 0; x < 20; x++)
{
Console.WriteLine(Edades - );
}
}
}
}
Para los que no lo sepan
n! = 1*2*3*4...*n-1*n
using System;
using System.Collections.Generic;
using System.Text;
namespace Ejercicios
{
class Program
{
static void Main(string[] args)
{
long contador=1;
Console.WriteLine("Programa para calcular n!");
Console.Write("N = ");
int numero = int.Parse(Console.ReadLine());
for (int i = 2; i <= numero; i++)
{
contador *= i;
}
Console.WriteLine("n! = {0}", contador);
Console.Read();
}
}
}
men si tienes por haí el kodigo del juego "Sopa de letrras" te agradecería si me lo facilitaras.... :huh:
hola!! muy buenos tus programas
un muy buen aporte!...
oye he querido cambiar el color de las letras y del fondo con c#
por ejemplo utilizar lo que pones
Console.BackgroundColor = ConsoleColor.Yellow;
y
using System;
using System.Text;
using System.Collections;
pero no funciona
en la consola me aparece:
System.CONSOLE Does not contain a definition of background
cual seria la solucion?? que debo de instalar o en que estoy mal
agradeceria mucho tu respuesta..
gracias!!
Ami me funciona correctamente así:
using System;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
Console.BackgroundColor = ConsoleColor.Yellow;
Console.Write("Hola");
Console.Read();
}
}
}
1: using System;
2: using System.Collections.Generic;
3: using System.Text;
4: using System.Net.NetworkInformation;
5:
6: namespace D4N93R.Traceroute
7: {
8: //Delegado para los eventos del Traceroute
9: public delegate void TracertEventHandler(object sender, TracertEventArgs e);
10:
11: public class Tracert
12: {
13: int m_timeout = 0;
14: string m_host = "";
15: int m_maxHops = 0;
16:
17: public event TracertEventHandler EchoReceived;
18: public event TracertEventHandler ErrorReceived;
19: public event TracertEventHandler TracertCompleted;
20:
21: public Tracert(string host, int TimeOut, int maxHops)
22: {
23: m_host = host;
24: m_timeout = TimeOut;
25: m_maxHops = maxHops;
26: }
27: public void Start()
28: {
29: PingReply reply;
30: Ping pinger = new Ping();
31: PingOptions options = new PingOptions();
32:
33: //Con esto le decimos al paquete que nada más salte un equipo.
34: options.Ttl = 1;
35:
36: options.DontFragment = true;
37:
38: byte[] buffer = Encoding.ASCII.GetBytes("Algo de datos");
39: try
40: {
41: do
42: {
43: //Tiempo antes del comando
44: DateTime start = DateTime.Now;
45:
46: //Mandamos el ping
47: reply = pinger.Send(m_host,
48: m_timeout,
49: buffer,
50: options);
51:
52: //Restamos la diferencia de tiempo para conocer la latencia.
53: long milliseconds = DateTime.Now.Subtract(start).Milliseconds;
54: if ((reply.Status == IPStatus.TtlExpired)
55: || (reply.Status == IPStatus.Success))
56: {
57: //Damos respuesta en caso de que encontremos un host
58: //o que se haya finalizado el proceso.
59: OnEchoReceived(reply, milliseconds, options.Ttl);
60: }
61: else
62: {
63: OnErrorReceived(reply, milliseconds);
64: }
65: options.Ttl++;
66:
67: //Mientras no haya terminado, es decir, no sea Success
68: //seguimos mandando ping con un TTL aumentado.
69:
70: // Notemos que cuando la resuesta es Success
71: //es porque el paquete llego al destino
72: } while ((reply.Status != IPStatus.Success)
73: && (options.Ttl < m_maxHops));
74: }
75: catch (PingException pex)
76: {
77: //Acá pueden implementar algo en caso de algun error.
78: throw pex.InnerException;
79: }
80: finally
81: {
82: if (TracertCompleted != null)
83: TracertCompleted(this, new TracertEventArgs(null, 0, 0));
84: }
85: }
86:
87:
88: //Manejo de los eventos.
89: private void OnErrorReceived(PingReply reply, long milliseconds)
90: {
91: InvokeErrorReceived(reply, milliseconds);
92: }
93:
94: private void OnEchoReceived(PingReply reply, long milliseconds, int ttl)
95: {
96: InvokeEchoReceived(reply, milliseconds, ttl);
97: }
98: public void InvokeEchoReceived(PingReply reply, long milliseconds, int ttl)
99: {
100: if (EchoReceived != null)
101: EchoReceived(this, new TracertEventArgs(reply, milliseconds,ttl));
102: }
103: public void InvokeErrorReceived(PingReply reply, long milliseconds)
104: {
105: if (ErrorReceived != null)
106: ErrorReceived(this, new TracertEventArgs(reply, milliseconds,0));
107: }
108: }
109: }
Weno soy iniciado en estos temas de programacion en c sharp, stoy studiando en un instituo, y kisiera que me ayudaras a resolver un problema
De una lista de enteros de un vector me pide capturar dos elementos menores ingresados por teclado. Lo estado intentando y solo puedo encontra el mas minimo, pero el sgte menor como lo capturo?
bueno ,dejo un ejemplo bastante basico, pero creo que deja una idea clara de como usar delegados,
el programa no hace nada del otro mundo ,solo "filtra" arreglos, espero que puedan abstraer la idea
using System;
using System.Collections;
public delegate bool filtro(int i);
class Filtros{
public static bool Positivos(int i){
return (i>=0);
}
public static bool Negativos(int i){
return (i<=0);
}
}
class Filtador{
public static int[] Filtrador(int[] a, filtro fil){
ArrayList aList = new ArrayList();
for (int i = 0; i < a.Length; i++)
{
if (fil(a[i])) { aList.Add(a[i]); }
}
return ((int[])aList.ToArray(typeof(int)));
}
}
class hello
{
static void Main()
{
int[] a= {4,-4,6,-6,8,-8,10,-10};
int[] b;
filtro j;
j = Filtros.Positivos;
b = Filtador.Filtrador(a,j);
foreach (int ca in b) Console.Write(ca + " ");
Console.WriteLine();
j = Filtros.Negativos;
b = Filtador.Filtrador(a, j);
foreach (int ca in b) Console.Write(ca + " ");
}
}
Hola necesito ayuda, necesito hace en C# una matriz...la cual con 1 textbox voy ingresando los numero (tiene que ser una matriz de 4x4) y despues al elegir en el radiobutom por ejemplo la opcion suamar, que sume las matrizes ...Me ayudas?