Bueno las partes:
MAIN.CPP
Código
#include "funciones.h" int main() { funciones Objetollamador; Objetollamador.PedirNumero(); return 0; }
FUNCIONES.CPP
Código
#include <iostream> using std::cout; using std::endl; using std::cin; #include "funciones.h" void funciones::PedirNumero() { int Numero; int NumeroCaracteres; cout << "Solo se pueden escribir numeros que contengan 0 y 1 (que sea un numero binario)" " y el programa acepta un numero con 10 caracteres o menos, de lo contrario\n" " el resultado no sera el deseado.\n"; cout << "Escriba su numero:\t"; cin >> Numero; cout << "Escriba la cantidad de caracteres que tiene su numero:\t"; cin >> NumeroCaracteres; cout << "Obteniendo valores...\n"; funciones::ExaminarNumero(Numero,NumeroCaracteres); } int funciones::ExaminarNumero(int Numero, int NumeroCaracteres) { int NumeroCaracteres1 = NumeroCaracteres; int Numero1 = Numero; if (Numero1 <= 9999999999) { if (Numero1 > 999999999) // si tiene 10 caracteres { int variable; int division1; int division2; int division3; int division4; int division5; int division6; int division7; int division8; int division9; int division10; division10 = Numero1 / 1000000000; variable = Numero1 % 1000000000; division9 = variable / 100000000; variable = variable % 100000000; division8 = variable / 10000000; variable = variable % 10000000; division7 = variable / 1000000; variable = variable % 1000000; division6= variable / 100000; variable = variable % 100000; division5 = variable / 10000; variable = variable % 10000; division4 = variable / 1000; variable = variable % 1000; division3= variable / 100; variable = variable % 100; division2= variable / 10; variable = variable % 10; division1 = variable / 1; variable = variable % 1; //Pasando a base 10. division10= division10 * 512; division9= division9 * 256; division8= division8 * 128; division7= division7 * 64; division6= division6 * 32; division5= division5 * 16; division4= division4 * 8; division3= division3 * 4; division2= division2 * 2; division1= division1 * 1; variable = (division1 + division2 + division3 + division4 + division5 + division6 + division7 + division8 + division9 + division10); cout << "NUMERO CONVERTIDO EN: " << variable << endl; cin.get(); cin.get(); } if ((Numero1 < 1000000000) & (Numero1 > 99999999)) // si tiene 9 caracteres { int variable; int division1; int division2; int division3; int division4; int division5; int division6; int division7; int division8; int division9; int division10; division10 = Numero1 / 1000000000; variable = Numero1 % 1000000000; division9 = variable / 100000000; variable = variable % 100000000; division8 = variable / 10000000; variable = variable % 10000000; division7 = variable / 1000000; variable = variable % 1000000; division6= variable / 100000; variable = variable % 100000; division5 = variable / 10000; variable = variable % 10000; division4 = variable / 1000; variable = variable % 1000; division3= variable / 100; variable = variable % 100; division2= variable / 10; variable = variable % 10; division1 = variable / 1; variable = variable % 1; //Pasando a base 10. division9= division9 * 256; division8= division8 * 128; division7= division7 * 64; division6= division6 * 32; division5= division5 * 16; division4= division4 * 8; division3= division3 * 4; division2= division2 * 2; division1= division1 * 1; variable = (division1 + division2 + division3 + division4 + division5 + division6 + division7 + division8 + division9); cout << "NUMERO CONVERTIDO EN: " << variable << endl; cin.get(); cin.get(); } if ((Numero1 < 100000000 & Numero1 > 9999999) ) // si tiene 8 caracteres { int variable; int division1; int division2; int division3; int division4; int division5; int division6; int division7; int division8; int division9; int division10; division10 = Numero1 / 1000000000; variable = Numero1 % 1000000000; division9 = variable / 100000000; variable = variable % 100000000; division8 = variable / 10000000; variable = variable % 10000000; division7 = variable / 1000000; variable = variable % 1000000; division6= variable / 100000; variable = variable % 100000; division5 = variable / 10000; variable = variable % 10000; division4 = variable / 1000; variable = variable % 1000; division3= variable / 100; variable = variable % 100; division2= variable / 10; variable = variable % 10; division1 = variable / 1; variable = variable % 1; //Pasando a base 10. division8= division8 * 128; division7= division7 * 64; division6= division6 * 32; division5= division5 * 16; division4= division4 * 8; division3= division3 * 4; division2= division2 * 2; division1= division1 * 1; variable = (division1 + division2 + division3 + division4 + division5 + division6 + division7 + division8); cout << "NUMERO CONVERTIDO EN: " << variable << endl; cin.get(); cin.get(); } if ((Numero1 < 10000000 & Numero1 > 999999) ) // si tiene 7 caracteres { int variable; int division1; int division2; int division3; int division4; int division5; int division6; int division7; int division8; int division9; int division10; division10 = Numero1 / 1000000000; variable = Numero1 % 1000000000; division9 = variable / 100000000; variable = variable % 100000000; division8 = variable / 10000000; variable = variable % 10000000; division7 = variable / 1000000; variable = variable % 1000000; division6= variable / 100000; variable = variable % 100000; division5 = variable / 10000; variable = variable % 10000; division4 = variable / 1000; variable = variable % 1000; division3= variable / 100; variable = variable % 100; division2= variable / 10; variable = variable % 10; division1 = variable / 1; variable = variable % 1; //Pasando a base 10. division7= division7 * 64; division6= division6 * 32; division5= division5 * 16; division4= division4 * 8 ; division3= division3 * 4; division2= division2 * 2; division1= division1 * 1; variable = (division1 + division2 + division3 + division4 + division5 + division6 + division7); cout << "NUMERO CONVERTIDO EN: " << variable << endl; cin.get(); cin.get(); } if ((Numero1 < 10000000 & Numero1 > 99999 )) // si tiene 6 caracteres { int variable; int division1; int division2; int division3; int division4; int division5; int division6; int division7; int division8; int division9; int division10; division10 = Numero1 / 1000000000; variable = Numero1 % 1000000000; division9 = variable / 100000000; variable = variable % 100000000; division8 = variable / 10000000; variable = variable % 10000000; division7 = variable / 1000000; variable = variable % 1000000; division6= variable / 100000; variable = variable % 100000; division5 = variable / 10000; variable = variable % 10000; division4 = variable / 1000; variable = variable % 1000; division3= variable / 100; variable = variable % 100; division2= variable / 10; variable = variable % 10; division1 = variable / 1; variable = variable % 1; //Pasando a base 10. division6= division6 * 32; division5= division5 * 16; division4= division4 * 8; division3= division3 * 4; division2= division2 * 2; division1= division1 * 1; variable = (division1 + division2 + division3 + division4 + division5 + division6); cout << "NUMERO CONVERTIDO EN: " << variable << endl; cin.get(); cin.get(); } if ((Numero1 < 100000 & Numero1 > 9999)) // si tiene 5 caracteres { int variable; int division1; int division2; int division3; int division4; int division5; int division6; int division7; int division8; int division9; int division10; division10 = Numero1 / 1000000000; variable = Numero1 % 1000000000; division9 = variable / 100000000; variable = variable % 100000000; division8 = variable / 10000000; variable = variable % 10000000; division7 = variable / 1000000; variable = variable % 1000000; division6= variable / 100000; variable = variable % 100000; division5 = variable / 10000; variable = variable % 10000; division4 = variable / 1000; variable = variable % 1000; division3= variable / 100; variable = variable % 100; division2= variable / 10; variable = variable % 10; division1 = variable / 1; variable = variable % 1; //Pasando a base 10. division5= division5 * 16; division4= division4 * 8; division3= division3 * 4; division2= division2 * 2; division1= division1 * 1; variable = (division1 + division2 + division3 + division4 + division5); cout << "NUMERO CONVERTIDO EN: " << variable << endl; cin.get(); cin.get(); } if ((Numero1 < 10000 & Numero1 > 999)) // si tiene 4 caracteres { int variable; int division1; int division2; int division3; int division4; int division5; int division6; int division7; int division8; int division9; int division10; division10 = Numero1 / 1000000000; variable = Numero1 % 1000000000; division9 = variable / 100000000; variable = variable % 100000000; division8 = variable / 10000000; variable = variable % 10000000; division7 = variable / 1000000; variable = variable % 1000000; division6= variable / 100000; variable = variable % 100000; division5 = variable / 10000; variable = variable % 10000; division4 = variable / 1000; variable = variable % 1000; division3= variable / 100; variable = variable % 100; division2= variable / 10; variable = variable % 10; division1 = variable / 1; variable = variable % 1; //Pasando a base 10. division4= division4 * 8; division3= division3 * 4; division2= division2 * 2; division1= division1 * 1; variable = (division1 + division2 + division3 + division4); cout << "NUMERO CONVERTIDO EN: " << variable << endl; cin.get(); cin.get(); } if ((Numero1 < 1000) & (Numero1 > 99)) // si tiene 3 caracteres { int variable; int division1; int division2; int division3; int division4; int division5; int division6; int division7; int division8; int division9; int division10; division10 = Numero1 / 1000000000; variable = Numero1 % 1000000000; division9 = variable / 100000000; variable = variable % 100000000; division8 = variable / 10000000; variable = variable % 10000000; division7 = variable / 1000000; variable = variable % 1000000; division6= variable / 100000; variable = variable % 100000; division5 = variable / 10000; variable = variable % 10000; division4 = variable / 1000; variable = variable % 1000; division3= variable / 100; variable = variable % 100; division2= variable / 10; variable = variable % 10; division1 = variable / 1; variable = variable % 1; //Pasando a base 10. division3= division3 * 4; division2= division2 * 2; division1= division1 * 1; variable = (division1 + division2 + division3); cout << "NUMERO CONVERTIDO EN: " << variable << endl; cin.get(); cin.get(); } if ((Numero1 < 100 & Numero1 > 9) ) // si tiene 2 caracteres { int variable; int division1; int division2; int division3; int division4; int division5; int division6; int division7; int division8; int division9; int division10; division10 = Numero1 / 1000000000; variable = Numero1 % 1000000000; division9 = variable / 100000000; variable = variable % 100000000; division8 = variable / 10000000; variable = variable % 10000000; division7 = variable / 1000000; variable = variable % 1000000; division6= variable / 100000; variable = variable % 100000; division5 = variable / 10000; variable = variable % 10000; division4 = variable / 1000; variable = variable % 1000; division3= variable / 100; variable = variable % 100; division2= variable / 10; variable = variable % 10; division1 = variable / 1; variable = variable % 1; //Pasando a base 10. division2= division2 * 2; division1= division1* 1; variable = (division1 + division2); cout << "NUMERO CONVERTIDO EN: " << variable << endl; cin.get(); cin.get(); } if (Numero1 < 10 ) // si tiene 1 caracter { int variable; int division1; int division2; int division3; int division4; int division5; int division6; int division7; int division8; int division9; int division10; division10 = Numero1 / 1000000000; variable = Numero1 % 1000000000; division9 = variable / 100000000; variable = variable % 100000000; division8 = variable / 10000000; variable = variable % 10000000; division7 = variable / 1000000; variable = variable % 1000000; division6= variable / 100000; variable = variable % 100000; division5 = variable / 10000; variable = variable % 10000; division4 = variable / 1000; variable = variable % 1000; division3= variable / 100; variable = variable % 100; division2= variable / 10; variable = variable % 10; division1 = variable / 1; variable = variable % 1; //Pasando a base 10. division1= division1 * 1 ; variable = (division1); cout << "NUMERO CONVERTIDO EN: " << variable << endl; cin.get(); cin.get(); } } else { cout << "El numero ingresado excede el maximo de caracteres permitidos.\n"; } return 0; }
FUNCIONES.H
Código
class funciones { public: void PedirNumero(); int ExaminarNumero(int,int); };