Sie sind auf Seite 1von 10

#include<cstdlib>

#include<iostream>
#include<iomanip>
void mostrarBits(unsigned);
void mostrarGray(unsigned);
const int tam=14;
using namespace std;
int main()
{

char A=201,B=205,C=187,D=186,E=200,F=188,G=204,H=185,opc;
int opcion;
system("color 1f");
cout<<endl;

cout<<"\t\t"<<A<<B<<B<<B<<B<<B<<B<<B<<B<<B<<B<<B<<B<<B<<B<<B<<B<<B<<B<<B<<B
<<B<<B<<B<<B<<B<<B<<B<<B<<B<<B<<B<<B<<B<<B<<B<<B<<B<<B<<B<<B<<B<<B<<B<<B<<B<<B<<
B<<B<<C<<endl;
{cout<<"\a\t\t"<<D<<"\t\t\tMENU"<<"\t\t\t "<<D<<endl; }
cout<<"\t\t"<<G<<B<<B<<B<<B<<B<<B<<B<<B<<B<<B<<B<<B<<B<<B<<B<<B<<B<<B<<B<<B
<<B<<B<<B<<B<<B<<B<<B<<B<<B<<B<<B<<B<<B<<B<<B<<B<<B<<B<<B<<B<<B<<B<<B<<B<<B<<B<<
B<<B<<H<<endl;
cout<<"\t\t"<<D<<"\t\t\t\t\t\t "<<D<<endl;
cout<<"\t\t"<<D<<"1. C"<<char(224)<<"digo Binario Natural\t\t\t "<<D<<endl;
cout<<"\t\t"<<D<<"2. C"<<char(224)<<"digo BCD\t\t\t\t\t "<<D<<endl;
cout<<"\t\t"<<D<<"3. C"<<char(224)<<"digo Exceso 3\t\t\t\t "<<D<<endl;
cout<<"\t\t"<<D<<"4. C"<<char(224)<<"digo Johnson\t\t\t\t "<<D<<endl;
cout<<"\t\t"<<D<<"5. C"<<char(224)<<"digo Gray\t\t\t\t\t "<<D<<endl;
cout<<"\t\t"<<D<<"\t\t\t\t\t\t "<<D<<endl;
cout<<"\t\t"<<E<<B<<B<<B<<B<<B<<B<<B<<B<<B<<B<<B<<B<<B<<B<<B<<B<<B<<B<<B<<B<
<B<<B<<B<<B<<B<<B<<B<<B<<B<<B<<B<<B<<B<<B<<B<<B<<B<<B<<B<<B<<B<<B<<B<<B<<B<<B<<B
<<B<<F<<endl;
cout<<endl;
cout<<"\t\t"<<" Ingrese opci"<<char(224)<<"n: ";
system("cls");

cin>>opcion;

switch(opcion)
{
case 1:
{ system("color 3f") ;
unsigned n,j,k;
char a[tam];
char A=218,B=196,C=194,D=191,E=192,F=193,G=179,H=195,I=197,J=180,K=217;
cout<<endl;
cout<<"\tCONVERTIR UN ENTERO POSITIVO DEL SISTEMA DECIMAL AL BINARIO"<<endl<<endl;
cout<<" Se graficar"<<char(160)<<" una tabla de conversi"<<char(224)<<"n desde 0 hasta el
n"<<char(233)<<"mero ingresado "<<endl<<endl;
cout<<" Ingrese un entero sin signo: "; cin>>n;
cout<<"\n\t\t"<<A<<B<<B<<B<<B<<B<<B<<B<<B<<B<<C;
for(k=0; k<=tam; k++)
{

a[k]=B;

cout<<a[k];}
cout<<D<<endl;
cout<<"\t\t"<<G<<" sistema "<<G<<"\tsistema "<<G<<endl;
cout<<"\t\t"<<G<<" decimal "<<G<<"\tBinomial "<<G;
cout<<"\n\t\t"<<H<<B<<B<<B<<B<<B<<B<<B<<B<<B<<I;
for(k=0; k<=tam; k++)
{

a[k]=B;

cout<<a[k];}
cout<<J<<endl;
for(j=0; j<=n; j++){
mostrarBits(j);}
cout<<"\t\t"<<E<<B<<B<<B<<B<<B<<B<<B<<B<<B<<F;
for(k=0; k<=tam; k++)
{

a[k]=B;

cout<<a[k];}
cout<<K<<endl;

}
break;
//-------------------------------------------------------------------------------------------------------------------case 2:
{

system("color 4f");
int V[100],i=0,cont=0,dig=0,n1,n2,n3,n4,aux,num,m1,cociente;
cout<<endl;
cout<<endl;

cout<<"\tCONVERTIR UN ENTERO POSITIVO DEL SISTEMA DECIMAL A


C"<<char(224)<<"DIGO BCD"<<endl;
cout<<endl;
cout<<" Ingrese un entero sin signo: ";

cin>>m1;

while(m1>0)
{ dig=m1%10;
cociente=m1/10;
m1=cociente;
V[i]=dig;
i++;
cont=cont+1;
}
cout<<"\n Su equivalente en c"<<char(224)<<"digo BCD es: ";
for(i=(cont-1); i>=0; i--)
{
aux=V[i];n1=0;n2=0;n3=0;n4=0;
if(aux>=8)
{n1=1;aux=aux-8;}
if(aux>=4)
{n2=1;aux=aux-4;}
if(aux>=2)
{n3=1;aux=aux-2;}
if(aux>=1)

{n4=1;aux=aux-1;}
cout<<n1<<n2<<n3<<n4<<" ";
}
}

break;

//--------------------------------------------------------------------------------------------------------------------------case 3:
{

system("color 6f");
int V[100],i=0,cont=0,dig=0,n1,n2,n3,n4,aux,num,m1,cociente;
cout<<endl;
cout<<endl;

cout<<"\tCONVERTIR UN ENTERO POSITIVO DEL SISTEMA DECIMAL A


C"<<char(224)<<"DIGO EXCESO 3"<<endl;
cout<<endl;
cout<<" Ingrese un entero sin signo: ";

cin>>m1;

while(m1>0)
{
dig=m1%10;
cociente=m1/10;
m1=cociente;
V[i]=dig+3;
i++;
cont=cont+1;
}
cout<<endl;
cout<<" Su equivalente en c"<<char(224)<<"digo Exceso 3 es: ";
for(i=(cont-1); i>=0; i--)
{
aux=V[i];n1=0;n2=0;n3=0;n4=0;
if(aux>=8)
{n1=1;aux=aux-8;}
if(aux>=4)

{n2=1;aux=aux-4;}
if(aux>=2)
{n3=1;aux=aux-2;}
if(aux>=1)
{n4=1;aux=aux-1;}
cout<<n1<<n2<<n3<<n4<<" ";
}
}

break;
//------------------------------------------------------------------------------------------------------------------------

case 4:
{

system("color 5f");
int k,u,M,m1,N,S,i;

char
a[tam],A=218,B=196,C=194,D=191,E=192,F=193,G=179,H=195,I=197,J=180,K=217;
cout<<endl;
cout<<"\tCONVERTIR ENTEROS POSITIVOS DEL SISTEMA DECIMAL A
C"<<char(224)<<"DIGO JOHNSON "<<endl;
cout<<endl;
cout<<" Se graficar"<<char(160)<<" una tabla de conversi"<<char(224)<<"n
dependiendo del n"<<char(233)<<"mero de bits a ingresar"<<endl;
cout<<endl;
cout<<"Ingrese n"<<char(233)<<"mero de bits: ";
cin>>m1;
cout<<endl;
cout<<endl;
cout<<endl;
if(m1<=7){
M=8;S=9-m1;}
else{
M=m1;S=1;}

cout<<"\n\t\t"<<A<<B<<B<<B<<B<<B<<B<<B<<B<<B<<C;
for(k=0; k<=M+2; k++)
{

a[k]=B;

cout<<a[k];}
cout<<D<<endl;
cout<<"\t\t"<<G<<" sistema "<<G;
for(k=1; k<=(M/2-4); k++)
{

a[k]=(char)32;

cout<<a[k];}
cout<<" c"<<char(224)<<"digo ";
for(k=1; k<=((M-M/2)-3); k++)
{

a[k]=(char)32;

cout<<a[k];}
cout<<G<<endl;
cout<<"\t\t"<<G<<" decimal "<<G;
for(k=1; k<=((M/2)-4); k++)
{

a[k]=(char)32;

cout<<a[k];}
cout<<" johnson ";
for(k=1; k<=(M-M/2-3); k++)
{

a[k]=(char)32;

cout<<a[k];}
cout<<G;
cout<<"\n\t\t"<<H<<B<<B<<B<<B<<B<<B<<B<<B<<B<<I;
for(k=0; k<=M+2; k++)
{

a[k]=B;

cout<<a[k];}
cout<<J<<endl;
N=m1;
for(k=1;k<=N;k++)

{
cout<<"\t\t"<<G<<setw(5)<<k-1<<"\t "<<G<<" ";
for(i=1;i<=N-k+1;i++)
cout<<0;
for(i=0;i<=k-2;i++)
cout<<1;
for(u=1; u<=S; u++)
{

a[u]=(char)32;cout<<a[u];}
cout<<G<<"\n";
}
for(k=1;k<=N;k++)
{
cout<<"\t\t"<<G<<setw(5)<<N+k-1<<"\t "<<G<<" ";
for(i=1;i<=N-k+1;i++)
cout<<1;
for(i=0;i<=k-2;i++)
cout<<0;
for(u=1; u<=S; u++)

a[u]=(char)32;cout<<a[u];}
cout<<G<<"\n";
}
cout<<"\t\t"<<E<<B<<B<<B<<B<<B<<B<<B<<B<<B<<F;

for(k=0; k<=M+2; k++)


{

a[k]=B;

cout<<a[k];}
cout<<K<<endl;
}
break;
//----------------------------------------------------------------------------------------------------------------------------------

case 5:
{
system("color 3f") ;
unsigned n,valor,k;
double c;
char a[tam];
char A=218,B=196,C=194,D=191,E=192,F=193,G=179,H=195,I=197,J=180,K=217;
cout<<endl;
cout<<"\tCONVERTIR ENTEROS POSITIVOS DEL SISTEMA DECIMAL A C"<<char(224)<<"DIGO
GRAY"<<endl<<endl;
cout<<" Se graficar"<<char(160)<<" una tabla de conversi"<<char(224)<<"n desde 0 hasta el
n"<<char(233)<<"mero ingresado "<<endl<<endl;
cout<<" Ingrese un entero sin signo: "; cin>>n;
cout<<"\n\t\t"<<A<<B<<B<<B<<B<<B<<B<<B<<B<<B<<C;
for(k=0; k<=tam; k++)
{

a[k]=B;

cout<<a[k];}
cout<<D<<endl;
cout<<"\t\t"<<G<<" Sistema "<<G<<"\tC"<<char(224)<<"digo "<<G<<endl;
cout<<"\t\t"<<G<<" Decimal "<<G<<"\tGray

"<<G;

cout<<"\n\t\t"<<H<<B<<B<<B<<B<<B<<B<<B<<B<<B<<I;
for(k=0; k<=tam; k++)
{

a[k]=B;

cout<<a[k];}
cout<<J<<endl;
for(valor=0; valor<=n; valor++){
mostrarGray(valor);}
cout<<"\t\t"<<E<<B<<B<<B<<B<<B<<B<<B<<B<<B<<F;
for(k=0; k<=tam; k++)
{

a[k]=B;

cout<<a[k];}

cout<<K<<endl;
}
break;
//-----------------------------------------------------------------------------------default: {
cout<<"\t\t\n\nIngrese una opci"<<char(224)<<"n v"<<(char)160<<"lida";}
}
//----------------------------------------------------------------------------------------------cout<<endl;
do{
cout<<(char)168<<"Desea regresar al MEN"<<(char)233<<"? (S/N): ";
cin>>opc;
if(opc=='S' || opc=='s')
{
system("cls");
return main();
}
if(opc=='N' || opc=='n')
{
cout<<endl;
cout<<"\t\tGRACIAS POR USAR ESTE PROGRAMA!!!"<<endl;
cout<<endl;
}
}
while(opc!='S' && opc!='N' && opc!='s' && opc!='n');
system("PAUSE");
return EXIT_SUCCESS;

//-----------------------------------------------------------------------void mostrarBits(unsigned valor)


{
unsigned i, mostrarMask=1<<11;

cout<<"

\t\t"<<(char)179<<setw(5)<<valor<<" "<<(char)179;

for(i=1; i<=12; i++)


{

cout<<(valor & mostrarMask ? '1': '0');


valor<<=1;
if(i%4==0)
cout<<" ";
}
cout<<(char)179<<"\n";
}

//----------------------------------------------------------------------------void mostrarGray(unsigned valor)


{
unsigned i,T, mostrarMask=1<<11;
cout<<"

\t\t"<<(char)179<<setw(5)<<valor<<" "<<(char)179;

for(i=1; i<=12; i++)


{
T=(valor^(valor>>1));
cout<<(T & mostrarMask ? '1': '0');
valor<<=1;
if(i%4==0)
cout<<" ";

}
cout<<(char)179<<"\n";
}

Das könnte Ihnen auch gefallen