Captura:
Código:
Romanos.cpp;
#include<iostream> #include<stdlib.h> #include<stdio.h> #include<string.h> #include <windows.h> #include <time.h> #define N 11 //define la longitud maxima que es posible para el numero using namespace std; //PROTOTIPOS void unidades(char num[N],int x); void unidades2(char num[N],int x); bool decenas(char num[N],int x); void centenas(char num[N],int x); void miles(char num[N],int x); void romaneline(char num[N],int x); void gotoxy(short x, short y); int main(){ char num[N]; bool b,a; int x,y=-1,i,n; system("color 1f"); //Load_Game(); ///sleep(99); system("cls"); do{ system("title Conversor de Numeros Decimales a Romanos"); system("cls"); fflush(stdin); do{a=true; b=true; cout<<"\nIngrese el numero: ";cin.getline(num,N); x=strlen(num);}while(x<1||x>10); fflush(stdin);cout<<"\n\n"; n=x; while(x>=1){ y++; fflush(stdin); switch(x){ case 1:if(a==true&&b==true)unidades(num,y);a++;if(num[0]=='0'){x=1;}break; case 2:b=decenas(num,y);if(num[y+1]=='0'){x=1;}break; case 3:centenas(num,y);break; case 4:if(b==true)miles(num,y);break; case 5:b=decenas(num,y);break; case 6:centenas(num,y);break; case 7:cout<<" Lo siento solo puedo convertir hasta 999,999";x=1;break; } --x; fflush(stdin); }y=-1; fflush(stdin);if(strlen(num)<7){ romaneline(num,n);} cout<<"\n\n\nSalir 0: ";cin>>i;}while(i!=0); } void unidades(char num[N],int x){ switch(num[x]){//UNIDADES case '0':cout<<" ";break; case '1':cout<<"I";break; case '2':cout<<"II";break; case '3':cout<<"III";break; case '4':cout<<"IV";break; case '5':cout<<"V";break; case '6':cout<<"VI";break; case '7':cout<<"VII";break; case '8':cout<<"VIII";break; case '9':cout<<"IX";break; } } void unidades2(char num[N],int x){ switch(num[x]){//UNIDADES case '1':cout<<"XI";break; case '2':cout<<"XII";break; case '3':cout<<"XIII";break; case '4':cout<<"XIV";break; case '5':cout<<"XV";break; case '6':cout<<"XVI";break; case '7':cout<<"XVII";break; case '8':cout<<"XVII";break; case '9':cout<<"XIX";break; } } bool decenas(char num[N],int x){ bool r=true; switch(num[x]){//DECENAS case '1':if(num[x+1]!='0'){unidades2(num,x+1);r=false;}else{cout<<"X";}break; case '2':cout<<"XX";break; case '3':cout<<"XXX";break; case '4':cout<<"XL";break; case '5':cout<<"L";break; case '6':cout<<"LX";break; case '7':cout<<"LXX";break; case '8':cout<<"LXXX";break; case '9':cout<<"XC";break; //case 0:cout<<"cien";break; } return r; } void centenas(char num[N],int x){ switch(num[x]){ case '1':cout<<"C";break; case '2':cout<<"CC";break; case '3':cout<<"CCC";break; case '4':cout<<"CD";break; case '5':cout<<"D";break; case '6':cout<<"DC";break; case '7':cout<<"DCC";break; case '8':cout<<"DCCC";break; case '9':cout<<"CM";break; } } void miles(char num[N],int x){ int w=0,y=3; switch(num[x]){ case '1':cout<<"M";break; case '2':cout<<"MM";break; case '3':cout<<"MMM";break; case '4':cout<<"IV";/*gotoxy(w,y);cout<<"__";gotoxy(w+2,y+1);*/break; case '5':cout<<"V";/*gotoxy(w,y);cout<<"__";gotoxy(w+2,y+1);*/break; case '6':cout<<"VI";/*gotoxy(w,y);cout<<"__";gotoxy(w+2,y+1);*/break; case '7':cout<<"VII";/*gotoxy(w,y);cout<<"__";gotoxy(w+2,y+1);*/break; case '8':cout<<"VIII";/*gotoxy(w,y);cout<<"____";gotoxy(w+4,y+1);*/break; case '9':cout<<"IX";/*gotoxy(w,y);cout<<"__";gotoxy(w+2,y+1);*/break; } } void romaneline(char num[N],int x){ int w=0,y=3; int linea=0,q=-1,i; while(x>=1){ q++; fflush(stdin); switch(x){ case 4:switch(num[q]){case '4':case '5':case'6':case '7':case '9': linea=linea+2;break;case '8':linea=linea+4;break;}break; case 5:switch(num[q]){case '1': linea=linea+1;break;case '2':linea=linea+2;break;case '3':linea=linea+3;}break; case 6:switch(num[q]){case '1': linea=linea+1;break;case '2':case'4':case '5':case'6':case '7':case '9':linea=linea+2;break;case '3':linea=linea+3;}break; } --x; fflush(stdin); }q=-1; gotoxy(w,y);for(i=0;i<linea;i++)cout<<"_"; gotoxy(w,6); } void gotoxy(short x, short y){ COORD Cursor_Pos = {x, y}; SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), Cursor_Pos); }
Descarga el código desde:
No hay comentarios :
Publicar un comentario