CLASE EJECUTORA
using System;
namespace Enunciado_5
{
class Program
{
static void Main(string[] args)
{
double coefA = 0, coefB = 0, coefC = 0;
bool control = true;
while (control == true)
{
Console.Clear();
Console.WriteLine("RESOLVER ECUACIONES DE SEGUNDO GRADO");
Console.WriteLine("ECUACIONES DEL TIPO: Ax^2 + Bx + C = 0");
bool rep = true;
while (rep == true)
{
try
{
Console.WriteLine("\nINTRODUCIR EL VALOR PARA A:");
coefA = Double.Parse(Console.ReadLine());
Console.ForegroundColor=ConsoleColor.Cyan;
Console.WriteLine("\nINTRODUCIR EL VALOR PARA B:");
coefB = Double.Parse(Console.ReadLine());
Console.ForegroundColor=ConsoleColor.Magenta;
Console.WriteLine("\nINTRODUCIR EL VALOR PARA C:");
coefC = Double.Parse(Console.ReadLine());
rep = false;
}
catch (FormatException)
{
Console.Clear();
Console.WriteLine("¡ERROR!. INTRODUCIR SOLO VALORES NUMERICOS");
rep = true;
}
}
double Bcuadrado = coefB * coefB;
double cuatroAC = 4 * coefA * coefC;
if (Bcuadrado < cuatroAC && coefA > 0 && coefC > 0)
{
Console.Clear();
Console.WriteLine("LA ECUACION NO TIENE SOLUCION." +
"\nEL RESULTADO DE LA RAIZ CUADRADA ES NEGATIVA.");
}
else
{
Ecuacion ecu = new Ecuacion(coefA, coefB, coefC);
Console.WriteLine("\nVALOR 1 = {0}",ecu.raizpositiva());
Console.WriteLine("VALOR 2 = {0}",ecu.raiznegativa());
}
Console.WriteLine("\n¿DESEA SEGUIR INGRESANDO? (Y/N)");
bool repSwitch = true;
while (repSwitch == true)
{
string SioNO = Console.ReadLine();
switch (SioNO)
{
case "y": case "Y":
control = true;
repSwitch = false;
break;
case "n": case "N":
control = false;
repSwitch = false;
break;
default:
Console.WriteLine(
"\nLA ENTRADA NO ES LA CORRECTA. PULSE \"Y\" o \"N\".");
repSwitch = true;
break;
}
}
}
}
}
}
CLASE CONVENCIONAL
using System;
namespace Enunciado_5
{
public class Ecuacion
{
private double X, Y, Z;
public Ecuacion(double x, double y, double z)
{
X = x;
Y = y;
Z = z;
}
public double raizpositiva()
{
double result = ((-Y + System.Math.Sqrt (Y * Y - 4 * X * Z)) / (2 * X));
return result;
}
public double raiznegativa()
{
double result = ((-Y - System.Math.Sqrt(Y * Y - 4 * X * Z)) / (2 * X));
return result;
}
}
}
martes, 18 de septiembre de 2012
lunes, 17 de septiembre de 2012
DISEÑE UNA CLASE DE NOMBRE PALINDROMA QUE RECIBA DE UNA FRASE Y, VERIFIQUE SI ES O NO UNA FRASE PALÍNDROMA SI LO ES RETORNE UN VERDADERO CASO CONTRARIO UN FALSO, EJEMPLO ANITA LAVA LA TINA. REALICE UN PROGRAMA PARA PROBAR LA CLASE PALÍNDROMA.
CLASE EJECUTORA
using System;
namespace Enunciado_3
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("*****FRASE PALINDROMA******");
Console.WriteLine("INGRESE UNA FRASE: ");
string frase = Console.ReadLine();
Palindroma ObjPalind = new Palindroma(frase);
Console.ReadKey();
}
}
}
CLASE CONVENCIONAL
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Enunciado_3
{
class Palindroma
{
private string frase;
private string frasepalind;
private string frasesinespacios;
public Palindroma()
{
this.frase = null;
this.frasesinespacios = null;
this.frasepalind = null;
}
public Palindroma(string cadena)
{
frase = cadena;
frasesinespacios = frase.Replace(" ", "");
for (int i = frasesinespacios.Length - 1; i >= 0; i--)
{
frasepalind = frasepalind + frasesinespacios.Substring(i, 1);
}
Console.WriteLine(frasesinespacios);
Console.WriteLine(frasepalind);
if (frasesinespacios == frasepalind)
{
Console.WriteLine("VERDADERO");
}
else
Console.WriteLine("FALSO");
}
}
}
using System;
namespace Enunciado_3
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("*****FRASE PALINDROMA******");
Console.WriteLine("INGRESE UNA FRASE: ");
string frase = Console.ReadLine();
Palindroma ObjPalind = new Palindroma(frase);
Console.ReadKey();
}
}
}
CLASE CONVENCIONAL
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Enunciado_3
{
class Palindroma
{
private string frase;
private string frasepalind;
private string frasesinespacios;
public Palindroma()
{
this.frase = null;
this.frasesinespacios = null;
this.frasepalind = null;
}
public Palindroma(string cadena)
{
frase = cadena;
frasesinespacios = frase.Replace(" ", "");
for (int i = frasesinespacios.Length - 1; i >= 0; i--)
{
frasepalind = frasepalind + frasesinespacios.Substring(i, 1);
}
Console.WriteLine(frasesinespacios);
Console.WriteLine(frasepalind);
if (frasesinespacios == frasepalind)
{
Console.WriteLine("VERDADERO");
}
else
Console.WriteLine("FALSO");
}
}
}
CREE UN CLASE DENOMINADA ENCRIPTACION, QUE RECIBA COMO PARÁMETRO UNA PALABRA Y LA RETORNE EN UN CONJUNTO DE NÚMEROS, EJEMPLO GABRIELA = 946374041, O CARACTERES CUALQUIERA $%^#@$, PERO QUE AL INGRESAR LOS MISMO CARACTERES RETORNE LA PALABRA ORIGINAL. IMPLEMENTE UN PROGRAMA PARA EJECUTAR LA CLASE ENCRIPTACION.
CLASE EJECUTORA
using System;
namespace Enunciado_2
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("INGRESE EL NOMBRE A ENCRIPTAR");
string cadena = Console.ReadLine();
cadena = cadena.ToUpper();
Encriptacion ObjEncrp = new Encriptacion(cadena);
Console.WriteLine("DESENCRIPTAR EL CODIGO");
Console.WriteLine("INGRESE EL CODIGO");
string cadena2 = Console.ReadLine();
ObjEncrp.Desencriptacion(cadena2);
Console.ReadKey();
}
}
}
CLASE CONVENCIONAL
using System;
namespace Enunciado_2
{
class Encriptacion
{
private string letra;
private char[] chars;
public Encriptacion()
{
this.letra = null;
this.chars = null;
}
public Encriptacion(string cadena)
{
chars = cadena.ToCharArray();
for (int i = 0; i < cadena.Length; i++)
{
letra = this.FormatEncript(cadena.Substring(i, 1));
chars[i] = Convert.ToChar(letra);
}
Console.WriteLine("NOMBRE ENCRIPTADO");
Console.WriteLine(chars);
}
public void Desencriptacion(string cadena2)
{
chars = cadena2.ToCharArray();
for (int i = 0; i < cadena2.Length; i++)
{
letra = this.FormatDesencript(cadena2.Substring(i, 1));
chars[i] = Convert.ToChar(letra);
}
Console.WriteLine("CODIGO DESENCRIPTADO");
Console.WriteLine(chars);
}
private string FormatEncript(string letra)
{
if (letra == "A") { return "0"; }
if (letra == "B") { return "1"; }
if (letra == "C") { return "2"; }
if (letra == "D") { return "3"; }
if (letra == "E") { return "4"; }
if (letra == "F") { return "5"; }
if (letra == "G") { return "6"; }
if (letra == "H") { return "7"; }
if (letra == "I") { return "8"; }
if (letra == "J") { return "9"; }
if (letra == "K") { return "!"; }
if (letra == "L") { return "#"; }
if (letra == "M") { return "$"; }
if (letra == "N") { return "%"; }
if (letra == "O") { return "/"; }
if (letra == "P") { return "("; }
if (letra == "Q") { return ")"; }
if (letra == "R") { return "="; }
if (letra == "S") { return "?"; }
if (letra == "T") { return "¿"; }
if (letra == "U") { return "+"; }
if (letra == "V") { return "*"; }
if (letra == "B") { return ">"; }
if (letra == "X") { return "-"; }
if (letra == "Y") { return "_"; }
if (letra == "Z") { return "<"; }
return "Letra no definida";
}
private string FormatDesencript(string letra)
{
if (letra == "0") { return "A"; }
if (letra == "1") { return "B"; }
if (letra == "2") { return "C"; }
if (letra == "n") { return "D"; }
if (letra == "4") { return "E"; }
if (letra == "5") { return "F"; }
if (letra == "6") { return "G"; }
if (letra == "7") { return "H"; }
if (letra == "8") { return "I"; }
if (letra == "9") { return "J"; }
if (letra == "!") { return "K"; }
if (letra == "#") { return "L"; }
if (letra == "$") { return "M"; }
if (letra == "%") { return "N"; }
if (letra == "/") { return "O"; }
if (letra == "(") { return "P"; }
if (letra == ")") { return "Q"; }
if (letra == "=") { return "R"; }
if (letra == "?") { return "S"; }
if (letra == "¿") { return "T"; }
if (letra == "+") { return "U"; }
if (letra == "*") { return "V"; }
if (letra == ">") { return "W"; }
if (letra == "-") { return "X"; }
if (letra == "_") { return "Y"; }
if (letra == "<") { return "Z"; }
return null;
}
}
}
using System;
namespace Enunciado_2
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("INGRESE EL NOMBRE A ENCRIPTAR");
string cadena = Console.ReadLine();
cadena = cadena.ToUpper();
Encriptacion ObjEncrp = new Encriptacion(cadena);
Console.WriteLine("DESENCRIPTAR EL CODIGO");
Console.WriteLine("INGRESE EL CODIGO");
string cadena2 = Console.ReadLine();
ObjEncrp.Desencriptacion(cadena2);
Console.ReadKey();
}
}
}
CLASE CONVENCIONAL
using System;
namespace Enunciado_2
{
class Encriptacion
{
private string letra;
private char[] chars;
public Encriptacion()
{
this.letra = null;
this.chars = null;
}
public Encriptacion(string cadena)
{
chars = cadena.ToCharArray();
for (int i = 0; i < cadena.Length; i++)
{
letra = this.FormatEncript(cadena.Substring(i, 1));
chars[i] = Convert.ToChar(letra);
}
Console.WriteLine("NOMBRE ENCRIPTADO");
Console.WriteLine(chars);
}
public void Desencriptacion(string cadena2)
{
chars = cadena2.ToCharArray();
for (int i = 0; i < cadena2.Length; i++)
{
letra = this.FormatDesencript(cadena2.Substring(i, 1));
chars[i] = Convert.ToChar(letra);
}
Console.WriteLine("CODIGO DESENCRIPTADO");
Console.WriteLine(chars);
}
private string FormatEncript(string letra)
{
if (letra == "A") { return "0"; }
if (letra == "B") { return "1"; }
if (letra == "C") { return "2"; }
if (letra == "D") { return "3"; }
if (letra == "E") { return "4"; }
if (letra == "F") { return "5"; }
if (letra == "G") { return "6"; }
if (letra == "H") { return "7"; }
if (letra == "I") { return "8"; }
if (letra == "J") { return "9"; }
if (letra == "K") { return "!"; }
if (letra == "L") { return "#"; }
if (letra == "M") { return "$"; }
if (letra == "N") { return "%"; }
if (letra == "O") { return "/"; }
if (letra == "P") { return "("; }
if (letra == "Q") { return ")"; }
if (letra == "R") { return "="; }
if (letra == "S") { return "?"; }
if (letra == "T") { return "¿"; }
if (letra == "U") { return "+"; }
if (letra == "V") { return "*"; }
if (letra == "B") { return ">"; }
if (letra == "X") { return "-"; }
if (letra == "Y") { return "_"; }
if (letra == "Z") { return "<"; }
return "Letra no definida";
}
private string FormatDesencript(string letra)
{
if (letra == "0") { return "A"; }
if (letra == "1") { return "B"; }
if (letra == "2") { return "C"; }
if (letra == "n") { return "D"; }
if (letra == "4") { return "E"; }
if (letra == "5") { return "F"; }
if (letra == "6") { return "G"; }
if (letra == "7") { return "H"; }
if (letra == "8") { return "I"; }
if (letra == "9") { return "J"; }
if (letra == "!") { return "K"; }
if (letra == "#") { return "L"; }
if (letra == "$") { return "M"; }
if (letra == "%") { return "N"; }
if (letra == "/") { return "O"; }
if (letra == "(") { return "P"; }
if (letra == ")") { return "Q"; }
if (letra == "=") { return "R"; }
if (letra == "?") { return "S"; }
if (letra == "¿") { return "T"; }
if (letra == "+") { return "U"; }
if (letra == "*") { return "V"; }
if (letra == ">") { return "W"; }
if (letra == "-") { return "X"; }
if (letra == "_") { return "Y"; }
if (letra == "<") { return "Z"; }
return null;
}
}
}
REALIZAR UNA CLASE EN C# DE NOMBRE ADIVINARNUMERO, SU OBJETIVO SERÁ PERMITIR QUE EL USUARIO AVERIGÜE UN NÚMERO ENTERO GENERADO ALEATORIAMENTE Y COMPRENDIDO ENTRE [0,100] QUE SE ALMACENARÁ, DENTRO DEL CÓDIGO DE LA CLASE, EN UNA VARIABLE ENTERO A LA QUE SE LLAMARÁ NÚMERO. LA CLASE RECIBIRÁ UN NÚMERO INGRESADO POR TECLADO COMO PARÁMETRO E INFORMARÁ DE SI EL NÚMERO QUE INTRODUCE EL USUARIO ES MAYOR O MENOR QUE EL NÚMERO GENERADO ALEATORIAMENTE. SI NO SE ACIERTA A LA PRIMERA, NO IMPORTA PORQUE TIENE 3 OPORTUNIDADES DE INTRODUCIR NÚMEROS DE FORMA ININTERRUMPIDA. CUANDO EL USUARIO ACIERTE, SE MOSTRARÁ UN MENSAJE DE FELICITACIÓN Y EL NÚMERO DE INTENTOS EMPLEADOS. TENER EN CUENTA: SI EL USUARIO INTRODUCE UN NÚMERO NO COMPRENDIDO ENTRE [0,100], EL PROGRAMA MOSTRARÁ UN MENSAJE INFORMATIVO. SI EL USUARIO TECLEA ASTERISCO, EL PROGRAMA DEBERÁ FINALIZAR. LA GENERACIÓN ALEATORIA DEL NÚMERO A ADIVINAR SE REALIZARÁ CON LA CLASE RANDOM Y EL MÉTODO NEXT() DEL C#.
CLASE EJECUTORA
using System;
namespace Enunciado_4
{
class Program
{
static void Main(string[] args)
{
int numer = 0;
Console.WriteLine("ADIVINAR EL NUMERO");
Console.WriteLine("SOLO TENDRAS 3 OPORTUNIDADES");
do
{
Console.WriteLine("INGRESE UN NUMERO COMPRENDIDO ENTRE 1 - 100");
numer = int.Parse(Console.ReadLine());
if (numer > 100)
{
Console.WriteLine("NUMERO FUERA DE RANGO");
}
} while ((numer > 0) && (numer > 100));
AdivinarNumero objeto1= new AdivinarNumero();
objeto1.Adivinar(numer);
objeto1.generarnumero();
Console.ReadKey();
}
}
}
CLASE CONVENCIONAL
using System;
namespace Enunciado_4
{
class AdivinarNumero
{
private int numero;
public AdivinarNumero()
{
this.numero=0;
}
public void Adivinar(int d)
{
this.numero=d;
}
public void generarnumero()
{
int a = 0;
int i = 0;
int cont = 0;
int veces = 0;
Random objeto2 = new Random();
for (i = 0; i < 1; i++)
{
a = objeto2.Next(1, 100);
}
if (this.numero == a)
{
Console.WriteLine("FELICITACIONES GANASTE EL NUMERO ERA EL {0}", a);
}
else
{
if (this.numero > a)
{
Console.WriteLine("EL NUMERO ES MAYOR AL GENERADO");
}
else
{
Console.WriteLine("EL NUMERO ES MENOR AL GENERADO");
}
}
if (this.numero != a)
{
do
{
Console.WriteLine("Ingrese de nuevo otro numero");
int c = int.Parse(Console.ReadLine());
if (c == a)
{
Console.WriteLine("FELICITACIONES GANASTE EL NUMERO ERA EL {0}", a);
Console.WriteLine("INTENTO {0}", veces + 2);
cont = 2;
}
else
{
if (c > a)
{
Console.WriteLine("EL NUMERO ES MAYOR AL GENERADO");
}
else
{
Console.WriteLine("EL NUMERO ES MENOR AL GENERADO2 ");
Console.WriteLine("PERDISTE");
}
}
cont++;
veces = veces + 1;
} while (cont < 2);
}
}
}
}
using System;
namespace Enunciado_4
{
class Program
{
static void Main(string[] args)
{
int numer = 0;
Console.WriteLine("ADIVINAR EL NUMERO");
Console.WriteLine("SOLO TENDRAS 3 OPORTUNIDADES");
do
{
Console.WriteLine("INGRESE UN NUMERO COMPRENDIDO ENTRE 1 - 100");
numer = int.Parse(Console.ReadLine());
if (numer > 100)
{
Console.WriteLine("NUMERO FUERA DE RANGO");
}
} while ((numer > 0) && (numer > 100));
AdivinarNumero objeto1= new AdivinarNumero();
objeto1.Adivinar(numer);
objeto1.generarnumero();
Console.ReadKey();
}
}
}
CLASE CONVENCIONAL
using System;
namespace Enunciado_4
{
class AdivinarNumero
{
private int numero;
public AdivinarNumero()
{
this.numero=0;
}
public void Adivinar(int d)
{
this.numero=d;
}
public void generarnumero()
{
int a = 0;
int i = 0;
int cont = 0;
int veces = 0;
Random objeto2 = new Random();
for (i = 0; i < 1; i++)
{
a = objeto2.Next(1, 100);
}
if (this.numero == a)
{
Console.WriteLine("FELICITACIONES GANASTE EL NUMERO ERA EL {0}", a);
}
else
{
if (this.numero > a)
{
Console.WriteLine("EL NUMERO ES MAYOR AL GENERADO");
}
else
{
Console.WriteLine("EL NUMERO ES MENOR AL GENERADO");
}
}
if (this.numero != a)
{
do
{
Console.WriteLine("Ingrese de nuevo otro numero");
int c = int.Parse(Console.ReadLine());
if (c == a)
{
Console.WriteLine("FELICITACIONES GANASTE EL NUMERO ERA EL {0}", a);
Console.WriteLine("INTENTO {0}", veces + 2);
cont = 2;
}
else
{
if (c > a)
{
Console.WriteLine("EL NUMERO ES MAYOR AL GENERADO");
}
else
{
Console.WriteLine("EL NUMERO ES MENOR AL GENERADO2 ");
Console.WriteLine("PERDISTE");
}
}
cont++;
veces = veces + 1;
} while (cont < 2);
}
}
}
}
IMPLEMENTAR UNA CLASE DENOMINADA TRANSFORMAR LA CUAL RETORNE UN VALOR EN LETRAS QUE RESULTE DE LA TRANSFORMACIÓN DE UNA CANTIDAD ENTERA ENVIADO COMO PARÁMETRO AL INSTANCIAR LA CLASE, EVALUAR CANTIDADES DE 1 A 10 SI EL USUARIO INGRESA UN VALOR FUERA DEL RANGO MUESTRE EL MENSAJE FUERA DE RANGO. CREE UN PROGRAMA PARA PROBAR LA CLASE TRANSFORMAR.
CLASE EJECUTORA
using System;
namespace sumadigitos
{
class Program
{
public static void Main(string[] args)
{
char op;
do{
int valor=0;
int validig=0;
valor= validarentrada();
validig=validardigito(valor);
Console.SetCursorPosition(20,10);
Console.Clear();
Console.SetCursorPosition(20,8);
Console.Write("El valor ingresado es: {0}",valor);
if(validig==1)
{
Console.SetCursorPosition(20,10);
Console.Write("El primer digito si es multiplo del segundo digito...!");
}else{
Console.SetCursorPosition(20,10);
Console.Write("El primer digito no es multiplo del segundo digito...!");
}
Console.SetCursorPosition(20,12);
Console.Write("Desea seguir ingresando pulse la letra: [s]");
op=char.Parse(Console.ReadLine());
}while(op=='s');
Console.ReadKey();
}
public static int validarentrada()
{
int cant=0;
do{
Console.Clear();
Console.SetCursorPosition(20,10);
Console.Write("INGRESAR UN VALOR DE DOS DIGITOS: ");
cant=int.Parse(Console.ReadLine());
}while((cant<=9)||(cant>99));
return cant;
}
public static int validardigito(int pvalor)
{
int cont=0;
int dig=0;
int num1=0,num2=0;
while(pvalor>=1)
{
dig=pvalor%10;
if(num1==0){
num1=dig;
}else{
num2=dig;
}
pvalor=pvalor/10;
}
if (num2 % num1 == 0){
return cont= 1;
}else{
return cont=0;
}
}
}
}
CLASE CONVENCIONAL
using System;
namespace Conversor
{
public class Transformar
{
private int valor;
public Transformar()
{
this.valor=0;
}
public Transformar(int valor)
{
this.valor=valor;
}
public void validacion()
{
if(this.valor<=10)
{
if(this.valor==1)
{
Console.WriteLine("Uno");
}
if(this.valor==2)
{
Console.WriteLine("Dos");
}
if(this.valor==3)
{
Console.WriteLine("Tres");
}
if(this.valor==4)
{
Console.WriteLine("Cuatro");
}
if(this.valor==5)
{
Console.WriteLine("Cinco");
}
if(this.valor==6)
{
Console.WriteLine("Seis");
}
if(this.valor==7)
{
Console.WriteLine("Siete");
}
if(this.valor==8)
{
Console.WriteLine("Ocho");
}
if(this.valor==9)
{
Console.WriteLine("Nueve");
}
if(this.valor==10)
{
Console.WriteLine("Diez");
}
}
else
{
Console.WriteLine("FUERA DE RANGO....! ");
}
}
}
}
using System;
namespace sumadigitos
{
class Program
{
public static void Main(string[] args)
{
char op;
do{
int valor=0;
int validig=0;
valor= validarentrada();
validig=validardigito(valor);
Console.SetCursorPosition(20,10);
Console.Clear();
Console.SetCursorPosition(20,8);
Console.Write("El valor ingresado es: {0}",valor);
if(validig==1)
{
Console.SetCursorPosition(20,10);
Console.Write("El primer digito si es multiplo del segundo digito...!");
}else{
Console.SetCursorPosition(20,10);
Console.Write("El primer digito no es multiplo del segundo digito...!");
}
Console.SetCursorPosition(20,12);
Console.Write("Desea seguir ingresando pulse la letra: [s]");
op=char.Parse(Console.ReadLine());
}while(op=='s');
Console.ReadKey();
}
public static int validarentrada()
{
int cant=0;
do{
Console.Clear();
Console.SetCursorPosition(20,10);
Console.Write("INGRESAR UN VALOR DE DOS DIGITOS: ");
cant=int.Parse(Console.ReadLine());
}while((cant<=9)||(cant>99));
return cant;
}
public static int validardigito(int pvalor)
{
int cont=0;
int dig=0;
int num1=0,num2=0;
while(pvalor>=1)
{
dig=pvalor%10;
if(num1==0){
num1=dig;
}else{
num2=dig;
}
pvalor=pvalor/10;
}
if (num2 % num1 == 0){
return cont= 1;
}else{
return cont=0;
}
}
}
}
CLASE CONVENCIONAL
using System;
namespace Conversor
{
public class Transformar
{
private int valor;
public Transformar()
{
this.valor=0;
}
public Transformar(int valor)
{
this.valor=valor;
}
public void validacion()
{
if(this.valor<=10)
{
if(this.valor==1)
{
Console.WriteLine("Uno");
}
if(this.valor==2)
{
Console.WriteLine("Dos");
}
if(this.valor==3)
{
Console.WriteLine("Tres");
}
if(this.valor==4)
{
Console.WriteLine("Cuatro");
}
if(this.valor==5)
{
Console.WriteLine("Cinco");
}
if(this.valor==6)
{
Console.WriteLine("Seis");
}
if(this.valor==7)
{
Console.WriteLine("Siete");
}
if(this.valor==8)
{
Console.WriteLine("Ocho");
}
if(this.valor==9)
{
Console.WriteLine("Nueve");
}
if(this.valor==10)
{
Console.WriteLine("Diez");
}
}
else
{
Console.WriteLine("FUERA DE RANGO....! ");
}
}
}
}
IMPLEMENTAR UN PROGRAMA QUE ME PERMITA INGRESAR UN VALOR NUMÉRICO DE TRES CIFRAS, DETERMINAR CUANTAS CIFRAS DE DICHO NUMERO SON NÚMEROS PARES IMPLEMENTADO CON CLASE
CLASE EJECUTORA
using System;
namespace Digitos
{
class Program
{
public static void Main(string[] args)
{
int cant=0;
do{
Console.Clear();
Console.SetCursorPosition(15,2);
Console.Write("INGRESE UNA CANTIDAD DE TRES DIGITOS: ");
cant = Convert.ToInt32(Console.ReadLine());
}while ((cant<=99) || (cant>999));
//Creo el Objeto para llamar a los metodos
Separar Objeto = new Separar(cant);
Objeto.SepararDigitos(cant);
Objeto.VerificarParSiNo(cant);
Objeto.VerResultadoProceso();
Console.ReadKey();
}
}
}
namespace Digitos
{
class Program
{
public static void Main(string[] args)
{
int cant=0;
do{
Console.Clear();
Console.SetCursorPosition(15,2);
Console.Write("INGRESE UNA CANTIDAD DE TRES DIGITOS: ");
cant = Convert.ToInt32(Console.ReadLine());
}while ((cant<=99) || (cant>999));
//Creo el Objeto para llamar a los metodos
Separar Objeto = new Separar(cant);
Objeto.SepararDigitos(cant);
Objeto.VerificarParSiNo(cant);
Objeto.VerResultadoProceso();
Console.ReadKey();
}
}
}
CLASE CONVENCIONAL
using System;
namespace Digitos
{
public class Separar
{
private int numero;
private int contador;
public Separar()
{
this.numero = 0;
this.contador = 0;
}
public Separar(int cant)
{
this.numero = cant;
}
public void SepararDigitos(int cantidad)
{
int digito=0;
while(cantidad>=1)
{
digito=cantidad%10;
if ((digito!=0) && (digito%2==0))
{
contador++;
cantidad=cantidad/10;
}
}
}
public void VerificarParSiNo(int num)
{
int cont=0;
cont=(num % 2);
if(cont==0){
Console.SetCursorPosition(18,4);
Console.Write("EL NUMERO {0} SI ES PAR",num);
}
else{
Console.SetCursorPosition(18,4);
Console.Write("EL NUMERO {0} NO ES PAR",num);
}
}
public void VerResultadoProceso()
{
Console.SetCursorPosition(20,6);
Console.WriteLine("TIENE TANTOS : {0} NUMEROS PARES",this.contador);
}
}
}
namespace Digitos
{
public class Separar
{
private int numero;
private int contador;
public Separar()
{
this.numero = 0;
this.contador = 0;
}
public Separar(int cant)
{
this.numero = cant;
}
public void SepararDigitos(int cantidad)
{
int digito=0;
while(cantidad>=1)
{
digito=cantidad%10;
if ((digito!=0) && (digito%2==0))
{
contador++;
cantidad=cantidad/10;
}
}
}
public void VerificarParSiNo(int num)
{
int cont=0;
cont=(num % 2);
if(cont==0){
Console.SetCursorPosition(18,4);
Console.Write("EL NUMERO {0} SI ES PAR",num);
}
else{
Console.SetCursorPosition(18,4);
Console.Write("EL NUMERO {0} NO ES PAR",num);
}
}
public void VerResultadoProceso()
{
Console.SetCursorPosition(20,6);
Console.WriteLine("TIENE TANTOS : {0} NUMEROS PARES",this.contador);
}
}
}
martes, 11 de septiembre de 2012
DESARROLLAR UN PROGRAMA QUE ME PERMITA LEER UN VALOR DESDE EL TECLADO Y DETERMINAR SI ES O NO UN NUMERO PRIMO
using System;
namespace verfdenumprimos
{
class
Program
{
public static void Main(string[] args)
{
char op;
do{
int num=0;
num=IngresoDelNumero();
int res=0,i=1,cont=0;
do{
if(num%i==0){
res=1;
cont=cont+res;
}
i++;
}while(i<=num);
if(cont==2){
Console.SetCursorPosition(15,6);
Console.Write("EL NUMERO
INGRESADO SI ES PRIMO");
}else{
Console.SetCursorPosition(15,6);
Console.Write("EL NUMERO
INGRESADO NO ES PRIMO");
}
Console.SetCursorPosition(15,9);
Console.Write("DESEA SEGUIR
VERIFICANDO [S/N]:");
op=char.Parse(Console.ReadLine());
}while(op=='s');
Console.ReadKey();
}
public static int IngresoDelNumero()
{
Console.Clear();
int cant=0;
Console.SetCursorPosition(15,4);
Console.Write("INGRESE EL
NUMERO A VERIFICAR: ");
cant=int.Parse(Console.ReadLine());
return cant;
}
}
}
Fecha: 11 de Septiembre del 2012
Suscribirse a:
Entradas (Atom)