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



No hay comentarios:

Publicar un comentario