lunes, 17 de septiembre de 2012

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

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



No hay comentarios:

Publicar un comentario