"CODIGO DE PROGRAMACION C++"
/*AUTOMATAS Y LENGUAJES FORMALES*/
/*AUTHOR : JUAN CARLOS CELESTINO GUILLERMO*/
/*CONVERSION DE DECIMAL A BINARIO, OCTAL Y HEXADECIMAL*/
#include <iostream>
#include <conio.h>
#include <stdio.h>
#include <cstdlib>
#include <math.h>
#include <string>
#include <fstream>
#include <iomanip>
FILE *doc;
using namespace std;
void decimal();
void datos();
void menu();
int opcion;
int numBinario;
int numOctal;
int numHexadecimal;
int numero;
int salidaArchivo;
int i;
int main(int argc, char** argv) {
doc=fopen("doc.txt","a+");
do{
menu();
switch(opcion){
case
1:
decimal();
break;
case
2:
cout
<< " \t\t\t----SALIR--- " << endl;
break;
default:
cout
<< "\t\t\t[[[ OPCION NO
VALIDA ]]]" << endl;
cout
<< "\t\t\t [[[[[[[
ERROR ]]]]]] " <<
endl;
printf("%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%\n",
205, 205, 205,205, 205, 205,205, 205, 205,205, 205, 205, 205, 205, 205, 205,
205, 205, 205, 205, 205, 205, 205, 205, 205,
205, 205, 205, 205, 205, 205, 205, 205, 205, 205, 205, 205, 205, 205,
205, 205, 205, 205, 205, 205, 205, 205, 205, 205, 205, 205, 205, 205, 205, 205,
205, 205, 205, 205, 205, 205, 205, 205, 205, 205, 205, 205, 205, 205, 205, 205,
205, 205, 205, 205, 205, 205, 205, 205, 205, 205);
break;
}
}while(opcion!=2);
return 0;
}
void menu(){
printf("\t%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%\n",
201, 205, 205, 205, 205, 205, 205, 205, 205, 205, 205, 205, 205, 205, 205, 205,
205, 205, 205, 205, 205, 205, 205, 205, 205, 205, 205, 205, 205, 205, 205, 205,
205, 205, 205, 205, 205, 205, 205, 205, 205, 205, 205, 205, 205, 205, 205, 205,
205, 205, 205, 205, 205, 205, 205, 205, 205, 205, 187);
printf("\t%c %c\n",
186, 186);
printf("\t%c AUTOMATAS Y LENGUAJES
FORMALES%c %c\n", 186,
169, 186);
printf("\t%c ALUMNO: JUAN CARLOS CELESTINO
GUILLERMO%c %c\n", 186, 184,
186);
printf("\t%c CONVERSION DE SISTEMAS
NUMERICOS %c\n", 186,
186);
printf("\t%c GRUPO: ICO-19 %c\n", 186, 186);
printf("\t%c
%c\n", 186, 186);
printf("\t%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%\n\n\n",
200, 205, 205, 205, 205, 205, 205, 205, 205, 205, 205, 205, 205, 205, 205, 205,
205, 205, 205, 205, 205, 205, 205, 205, 205, 205, 205, 205, 205, 205, 205, 205,
205, 205, 205, 205, 205, 205, 205, 205, 205, 205, 205, 205, 205, 205, 205, 205,
205, 205, 205, 205, 205, 205, 205, 205, 205, 205, 188);
cout << "\t\t
***CONVERSION DE SISTEMA DECIMAL A BASES***\n" << endl;
cout <<
"\t 1.- SISTEMA NUMERICO DECIMAL. "
<< endl;
cout
<< "\t 2.- SALIR. \n" << endl;
cout << "\t ELIGE
UNA OPCION: ";
cin >> opcion;
printf("%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%\n",
205, 205, 205,205, 205, 205,205, 205, 205,205, 205, 205, 205, 205, 205, 205,
205, 205, 205, 205, 205, 205, 205, 205, 205,
205, 205, 205, 205, 205, 205, 205, 205, 205, 205, 205, 205, 205, 205,
205, 205, 205, 205, 205, 205, 205, 205, 205, 205, 205, 205, 205, 205, 205, 205,
205, 205, 205, 205, 205, 205, 205, 205, 205, 205, 205, 205, 205, 205, 205, 205,
205, 205, 205, 205, 205, 205, 205, 205, 205, 205);
return ;
}
void decimal(){
int
binario[20];
int hexadecimal[20];
int i;
int j;
int numBinario;
int numOctal;
int
numHexadecimal;
int
numero;
int octal[10];
cout <<
"\t\t[[[[[CONVERSION DE NUMEROS DECIMALES]]]]]\n" << endl;
cout <<
"\tINGRESA EL NUMERO DECIMAL A TRANSFORMAR: " ;
cin>>numero;
numBinario=numero;
numOctal=numero;
numHexadecimal=numero;
i=1;
cout <<
"\n\tEL NUMERO TRANSFORMADO A BINARIO ES: ";
if
(numBinario > 0) {
while (numBinario > 0) {
binario[i-1]=numBinario%2;
numBinario=floor(numBinario/2);
i=i+1;
}
for (j=i-1;j>=1;j--) {
cout<<binario[j-1];
}
}
else {
cout<<"***EL
NUMERO ES NEGATICO***"<<endl;
}
cout << "\n\tEL
NUMERO TRANSFORMADO A OCTAL ES: ";
i=1;
if (numOctal>0) {
while (numOctal>0) {
octal[i-1]=numOctal%8;
numOctal=floor(numOctal/8);
i=i+1;
}
for (j=i-1;j>=1;j--) {
cout<<octal[j-1];
}
}
else {
cout<<"***EL
MUNERO ES NEGATIVO***"<<endl;
}
cout <<
"\n\tEL NUMERO TRANSFORMADO A HEXADECIMAL ES: ";
i=1;
if (numHexadecimal>0) {
while (numHexadecimal>0) {
hexadecimal[i-1]=numHexadecimal%16;
numHexadecimal=floor(numHexadecimal/16);
i=i+1;
}
for (j=i-1;j>=1;j--) {
if (hexadecimal[j-1]<10) {
cout<<hexadecimal[j-1];
}
else {
if (hexadecimal[j-1]==10) {
cout<<"A";
}
else {
if
(hexadecimal[j-1]==11) {
cout<<"B";
}
else {
if (hexadecimal[j-1]==12)
{
cout<<"C";
}
else {
if
(hexadecimal[j-1]==13) {
cout<<"D";
}
else {
if
(hexadecimal[j-1]==14) {
cout<<"E";
}
else {
if
(hexadecimal[j-1]==15) {
cout<<"F";
}
}
}
}
}
}
}
}
}
else{
cout<<"***EL
NUMERO ES NEGATIVO***"<<endl;
}
printf("\n%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%\n",
205, 205, 205,205, 205, 205,205, 205, 205,205, 205, 205, 205, 205, 205, 205,
205, 205, 205, 205, 205, 205, 205, 205, 205,
205, 205, 205, 205, 205, 205, 205, 205, 205, 205, 205, 205, 205, 205,
205, 205, 205, 205, 205, 205, 205, 205, 205, 205, 205, 205, 205, 205, 205, 205,
205, 205, 205, 205, 205, 205, 205, 205, 205, 205, 205, 205, 205, 205, 205, 205,
205, 205, 205, 205, 205, 205, 205, 205, 205, 205);
return;
}
No hay comentarios.:
Publicar un comentario