miércoles, 14 de septiembre de 2011

Números romanos en Visual C++

Aplicación que permite transformar un número entre 1 y 2000 en formato arábigo en formato romano, realizado en Visual C++.

Se utiliza un control Texbox para mostrar el número en formato romano, para facilitar la operación de copiar el resultado y reutilizarlo en cualquier lugar, sin tener que reescribirlo.





- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Código Fuente
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -


private: System::Void button1_Click(System::Object^  sender, System::EventArgs^  e) {

	int dato_teclado=1234, unidades=0, decenas=0, centenas=0, millares=0;

	dato_teclado = Convert::ToInt32(this->textBox1->Text);

    millares=dato_teclado / 1000;
    dato_teclado = dato_teclado % 1000;
    centenas=dato_teclado / 100;
    dato_teclado = dato_teclado % 100;
    decenas=dato_teclado / 10;
    unidades = dato_teclado % 10;

	this->textBox2->Text = "";

    switch (millares)
    {
        case 1:
            this->textBox2->Text += "M";
            break;
        case 2:
            this->textBox2->Text += "MM";
            break;
        default:
            break;
    }

    switch (centenas)
    {
        case 1:
            this->textBox2->Text += "C";
            break;
        case 2:
            this->textBox2->Text += "CC";
            break;
        case 3:
            this->textBox2->Text += "CCC";
            break;
        case 4:
            this->textBox2->Text += "CD";
            break;
        case 5:
            this->textBox2->Text += "D";
            break;
        case 6:
            this->textBox2->Text += "DC";
            break;
        case 7:
            this->textBox2->Text += "DCC";
            break;
        case 8:
            this->textBox2->Text += "DCCC";
            break;
        case 9:
            this->textBox2->Text += "CM";
            break;
        default:
            break;
    }

    switch (decenas)
    {
        case 1:
            this->textBox2->Text += "X";
            break;
        case 2:
            this->textBox2->Text += "XX";
            break;
        case 3:
            this->textBox2->Text += "XXX";
            break;
        case 4:
            this->textBox2->Text += "XL";
            break;
        case 5:
            this->textBox2->Text += "L";
            break;
        case 6:
            this->textBox2->Text += "LX";
            break;
        case 7:
            this->textBox2->Text += "LXX";
            break;
        case 8:
            this->textBox2->Text += "LXX";
            break;
        case 9:
            this->textBox2->Text += "XC";
            break;
        default:
            break;
    }

    switch (unidades)
    {
        case 1:
            this->textBox2->Text +="I";
            break;
        case 2:
            this->textBox2->Text +="II";
            break;
        case 3:
            this->textBox2->Text +="III";
            break;
        case 4:
            this->textBox2->Text +="IV";
            break;
        case 5:
            this->textBox2->Text +="V";
            break;
        case 6:
            this->textBox2->Text +="VI";
            break;
        case 7:
            this->textBox2->Text +="VII";
            break;
        case 8:
            this->textBox2->Text +="VIII";
            break;
        case 9:
            this->textBox2->Text +="IX";
            break;
        default:
            break;
    }
}

No hay comentarios:

Publicar un comentario

Related Posts Plugin for WordPress, Blogger...