elhacker.net cabecera Bienvenido(a), Visitante. Por favor Ingresar o Registrarse
¿Perdiste tu email de activación?.

 

 


Tema destacado: Como proteger una cartera - billetera de Bitcoin


  Mostrar Temas
Páginas: [1]
1  Programación / Programación C/C++ / Proyecto Analizador de Parentesis implementado con Puntero de Clase Pila en: 8 Julio 2019, 18:02 pm
Código
  1. #include <iostream>
  2. #include <string.h>
  3. #include <stdlib.h>
  4. using namespace std;
  5. struct Nodo{
  6. int Elemento;
  7. Nodo *Sig;
  8. };
  9. class Pila{
  10. private:
  11. Nodo *Tope;
  12. public:
  13. void Crear();
  14. bool Vacia();
  15. void Meter(int);
  16. void Sacar(int &);
  17. //int Cima();
  18. void Mostrar();
  19. void Analizar();
  20. };
  21. void Pila::Crear(){
  22.   Tope=NULL;
  23. }
  24. bool Pila::Vacia(){
  25.  return Tope==NULL;
  26. }
  27. //int Pila::Cima(){
  28.  //if(!Vacia()){
  29.  //return Tope->Elemento;
  30.  //}
  31. //}
  32. void Pila::Meter(int E){
  33.  Nodo *aux=new Nodo();
  34.  if(aux!=NULL){
  35. aux->Elemento=E;
  36. aux->Sig=Tope;
  37. Tope=aux;
  38.  }
  39. }
  40. void Pila::Sacar(int &E){
  41.  if(!Vacia()){
  42. Nodo *aux=Tope;
  43. E=Tope->Elemento;
  44. Tope=Tope->Sig;
  45. delete(aux);
  46.  }
  47. }
  48. void Pila::Analizar(){
  49.    Pila p;
  50. char frase [30];
  51. int x,c,d;
  52. p.Crear();
  53. c=0;
  54. d=0;
  55. cout<<"Escriba un texto: "<<endl;
  56. cin>>frase;
  57. int i=0;
  58. while(frase[i]!='\0'){
  59.   if(frase[i]=='('){
  60.   p.Meter(frase[i]);
  61.   c++;
  62.   }
  63.   if(frase[i]==')'){
  64.   p.Sacar(x);
  65.   d++;
  66.   }
  67.   i++;
  68. }
  69. if(c==d)
  70. cout<<"Los parentesis estan correctos"<<endl;
  71. else
  72. cout<<"Los parentesis estan incorrectos"<<endl;
  73. }
  74. void Pila::Mostrar(){
  75. Nodo *aux=Tope;
  76. if (!Vacia()) {
  77.   while (aux!=NULL){
  78. cout<<"||\t";
  79. cout<<aux->Elemento;
  80. cout<<"\t ||\n";
  81. aux=aux->Sig;
  82. }
  83. }else{
  84. cout<<" ||\t \t||\n";
  85. }
  86. }
  87. int main(){
  88. bool menu=true;int i;Pila P;
  89.    while(menu){
  90. cout<<"\t\t*********************************"<<endl;
  91. cout<<"\t\t*\tMENU\t\t\t*"<<endl;
  92. cout<<"\t\t*********************************"<<endl;
  93. cout<<"\t\t*\t1.-Analizar Frase: \t*"<<endl;
  94. cout<<"\t\t*\t2.-Mostrar Pila\t\t*"<<endl;
  95. cout<<"\t\t*\t3.-Salir\t\t*"<<endl;
  96. cout<<"\t\t*********************************"<<endl;
  97. cin>>i;
  98.        if(i==1){
  99.            P.Analizar();
  100.        }else{
  101.            if(i==2){
  102.                P.Mostrar();
  103.            }else{
  104.                if(i==3){
  105.                    exit(0);
  106.                }
  107.            }
  108.        }
  109. }
  110.    return 0;
  111. }
  112.  
2  Programación / Programación C/C++ / LOGIN CON CONTRASEÑA CIFRADA CON EL USO DE CLASES HEREDADAS (en desarrollo) en: 14 Diciembre 2018, 18:39 pm
Hola foro ya estoy devuelta por aqui y con un nuevo tema tengo una presentacion de este login en c++ para una tarea el ejercicio consiste en crear un login con encriptacion de la contraseña, la cual se la incripta por llevando la contraseña a un vector y el vector se multiplica con una matriz que nosotros eligamos en este caso la matriz es {{1,2,1},{0,-1,3},{2,1,0}} en el codigo dejo la matriz definida ya que nunca cambia solo el vector tiene que ser de 3 elementos si o si para poder multiplicar por la matriz, si ponemos un contraseña mas grande igual tenemos que llevarla a vector pero luego hay que cortar el vector en vectores de 3 elementos. todo esto debe ser diseñado con el uso de clase y herencia. estuve resolviendo este ejercicio por con la ayuda de getters y setters para los metodos de la clase pero me quede hasta donde tengo que heredar el atributo contraseña para poder usar el metodo cifrado de la clase cifrado alguien podria darme una mano con el tema de la herencia de la contraseña luego de hay todo es mas facil dejo mi 2 codigos uno con herencia y otro sin herencia HELP!!!!!! T_T T_T T_T
Código
  1. //lOGIN SIN HERRENCIA
  2. #include<iostream>
  3. #include<windows.h>
  4. #include <fstream>
  5. #include<stdlib.h>
  6. #include<conio.h>
  7. #define MAX 4
  8. #define MIN 1
  9. using namespace std;
  10. char nombre1[10];
  11. char apellido1[10];
  12. char contrasenia1[100];
  13. char cargo1[100];
  14. char cumpleanio1[100];
  15. char nombretxt[100];
  16. void borrar_pantalla();
  17. typedef char matriz[3][3];
  18. typedef char alfabeto[27];
  19. //typedef char palabra [100];
  20. class Registro_Usuario{
  21. public://atributos
  22. string nombre,apellido,contrasenia,cargo,fecha_nacimiento;
  23. public://metodos
  24. Registro_Usuario();//constructor de la clase
  25. ~Registro_Usuario();//destuctor de la clase
  26. void setregistro(string,string,string,string,string);
  27. string getregistronombre();
  28. string getregistroapellido();
  29. string getregistrocontrasenia();
  30. string getregistrocargo();
  31. string getregistrofecha_nacimiento();
  32. };
  33. //constructor, nos sirve para inicializar los atributos
  34. Registro_Usuario::Registro_Usuario(){
  35. }
  36. //destructor de la clase
  37. Registro_Usuario::~Registro_Usuario(){
  38. }
  39. //establecemos los valores a los atributos
  40. void Registro_Usuario::setregistro(string _nombre, string _apellido, string _contrasenia, string _cargo, string _fecha_nacimiento){
  41. nombre = _nombre;
  42. apellido = _apellido;
  43. contrasenia = _contrasenia;
  44. cargo = _cargo;
  45. fecha_nacimiento = _fecha_nacimiento;
  46. cout<<"\n\tEscriba el nombre de usuario: ";
  47. gets(nombretxt);
  48. fstream archivo;
  49. archivo.open(nombretxt,ios::out);
  50. if(archivo.bad()){
  51. cout<<"Mary te AMO <3";
  52. exit(1);
  53. }
  54. archivo<<"BIENVENIDO A PROVIDENCIA "<<nombre1<<endl;
  55. archivo<<"Nombre y Apellido: "<<apellido1<<endl;
  56. archivo<<"Contraseña: "<<contrasenia<<endl;
  57. archivo<<"cargo: "<<cargo1<<endl;
  58. archivo<<"cumpleaños: "<<cumpleanio1<<endl;
  59. archivo.close();
  60. }
  61. string Registro_Usuario::getregistronombre(){
  62. return nombre;
  63. }
  64. string Registro_Usuario::getregistroapellido(){
  65. return apellido;
  66. }
  67. string Registro_Usuario::getregistrocontrasenia(){
  68. return contrasenia;
  69. }
  70. string Registro_Usuario::getregistrocargo(){
  71. return cargo;
  72. }
  73. string Registro_Usuario::getregistrofecha_nacimiento(){
  74. return fecha_nacimiento;
  75. }
  76. class cifrado : public Registro_Usuario{
  77. private://atributos
  78. string contrasenia;
  79. public://metodos
  80. cifrado();// contructor de la clase cifrado
  81. ~cifrado();
  82. void setcifrado(string);
  83. string getcifradocontrasenia();
  84. };
  85. //contructor de la clase cifrado
  86. cifrado::cifrado(){
  87. }
  88. //destructor de la clase
  89. cifrado::~cifrado(){
  90. }
  91. //establecemos valores a los atributos
  92. void cifrado::setcifrado(string _contrasenia){
  93. contrasenia = _contrasenia;
  94. alfabeto alf = {'A','B','C','D','E','F','G','H','I','J','K','L','M','N','Ñ','O','P','Q','R','S','T','U','V','W','X','Y','Z'};
  95. matriz m = {{1,2,1},{0,-1,3},{2,1,0}};
  96. int longitud = 0;
  97. }
  98. string cifrado::getcifradocontrasenia(){
  99. return contrasenia;
  100. }
  101. int main(){
  102. const int tam = 4 ;
  103. int opcion_menu;
  104. char caracter;
  105. int i = 0;
  106. cout <<endl<<endl<< "\t\t\t    BIENVENIDOS A PROVIDENCIA" << endl<<endl<<endl;
  107. cout << "------------------------------------------------------------------------------------------------------------------------------------" << endl;
  108. cout << "\t\t\t|1. Ingresar como Usuario    |" << endl;
  109. cout << "\t\t\t|2. Registrarse              |" << endl;
  110. cout << "\t\t\t|3. Ingrersar como Visitante |" << endl;
  111. cout << "\t\t\t|4. Salir del Programa.      |"  << endl;
  112. cout << "------------------------------------------------------------------------------------------------------------------------------------\n" << endl;
  113. cout << " Introduzca Opcion:  ";
  114. cin >> opcion_menu;
  115. if((opcion_menu==1)||(opcion_menu==2)||(opcion_menu==3)||(opcion_menu==4)){
  116. if(opcion_menu==2){
  117. system("cls");
  118. Sleep(1000);
  119. cout<<endl<<endl<<"\n\tBienvenido a PROVIDENCIA: \n";//INGRESAR COMO USUARIO"
  120. gets(nombre1);
  121. cout<<"\n\tDigite su Nombre y Apellido: ";//INGRESAR COMO USUARIO"
  122. gets(apellido1);
  123. cout<<"\n\tDigite su contrasenia: ";//INGRESAR COMO USUARIO"
  124. while (caracter=getch()){
  125. if(caracter==13){
  126. contrasenia1[i]='\0';
  127. break;
  128. }else if (caracter==8){
  129. i--;
  130. cout<<("\b \b");
  131. }else
  132. cout<<("*");
  133. contrasenia1[i]=caracter;
  134. i++;
  135. }
  136. cout<<endl<<"\n\tDigite su Cargo: ";//INGRESAR COMO USUARIO"
  137. gets(cargo1);
  138. cout<<"\n\tDigite su Fecha de nacimineto: ";//INGRESAR COMO USUARIO"
  139. gets(cumpleanio1);
  140. Sleep(1000);    //SEGUNDO Y MEDIO QUE DURA LA PANTALLA, SE PUEDE AUMENTAR EL TIEMPO EN MILISEGUNDOS :v
  141.                 system("cls"); //LIMPIA TODO  
  142.                 main();
  143.                }
  144. if (opcion_menu==4){
  145. system("cls");  
  146. cout<<endl<<(" El Programa CERRARA en Cualquier Momento"); Sleep(3000);
  147. exit(0);
  148. }
  149. }
  150. if((opcion_menu<MIN)||(opcion_menu>MAX)){        
  151. try {        
  152. system("cls");
  153.             cout<<"\n\n\t  ============================\n"
  154.                 <<"\n\n\t | ESTA OPCION  ES INCORRECTA |\n"
  155.                 <<"\n\n\t  ============================\n";
  156.                 Sleep(1000);    //SEGUNDO Y MEDIO QUE DURA LA PANTALLA, SE PUEDE AUMENTAR EL TIEMPO EN MILISEGUNDOS :v
  157.                 system("cls"); //LIMPIA TODO  
  158.                 main();//Y VUELVE AL MENÚ
  159.     }
  160.   catch(...)
  161. {cout << "\n UN ERROR HA OCURRIDO " << endl;}
  162. }
  163. switch (opcion_menu){
  164. case 2:
  165. Registro_Usuario usuario;
  166. cifrado codificar;
  167. codificar.setcifrado(contrasenia1);
  168. usuario.setregistro(nombre1,apellido1,contrasenia1,cargo1,cumpleanio1);
  169. break;
  170. }
  171. getch();
  172. return 0;
  173. }
  174. /*void verificar_existencia_de_usuario(string nuevo_usuario)
  175. {
  176.     ifstream archivo(string nuevo_usuario);
  177.     if (!archivo)
  178.     {
  179.              cout<<"\n Nombre de Usuario DISPONIBLE\n"<<endl;Sleep(2500);
  180.              }
  181.              else
  182.              {
  183.              cout<<"\n Este Nombre de Usuario ya Existe.....INTENTELO DE NUEVO"<<endl; Sleep(2500); borrar_pantalla();main();      
  184.              }  
  185. }
  186. /*void Ingresar_PASS(password){
  187. char caracter;
  188. int i = 0;
  189.  
  190. cout << " Escriba su Nuevo PASS:                 " ;
  191. while (caracter=getch()){
  192. if(caracter==13){
  193. break;
  194. }else if (caracter==8){
  195. i--;
  196. cout<<("\b \b");
  197. }else
  198. cout<<("*");
  199. p.PASS[i]=caracter;
  200. i++;
  201. }
  202. cout<<"\n SE HA REGISTRADO CORRECTAMENTE"<<endl; Sleep(2500);
  203. }*/
  204. void borrar_pantalla()
  205. {
  206. system("CLS");
  207. }
3  Programación / Programación C/C++ / RECURSION en su estado mas puro para invertir un vector! en: 12 Septiembre 2018, 23:27 pm
Código
  1. #include <iostream>
  2. #include <cstdlib>
  3. #include <conio.h>
  4. #include <string>
  5. #include <ctime>
  6. using namespace std;
  7. void cargar (int arreglo[],int num2,int n);
  8. void mostrar (int arreglo[],int num2,int n);
  9. void invertir (int arreglo[],int a,int b);
  10. void mostrarinversa (int arreglo[],int num2,int n);
  11. int main (){
  12. int n;
  13. cout<<"ingrese la longitud del vector: ";cin>>n;
  14. int arreglo[n];
  15. cargar (arreglo,0,n);
  16. cout<<endl<<endl;
  17. mostrar (arreglo,0,n);
  18. cout<<endl<<endl;
  19. invertir (arreglo,0,n);
  20. cout<<endl<<endl;
  21. mostrarinversa (arreglo,n-n+1,n);
  22. getch();
  23. return 0;
  24. }
  25. void invertir(int arreglo[],int a ,int b){
  26.   int n=b-a+1;
  27.   int aux;
  28.   if (n>1)
  29.      {
  30.      invertir(arreglo,a+1,b-1);
  31.      aux=arreglo[a];
  32.      arreglo[a]=arreglo[b ] ;
  33.      arreglo[ b]=aux ;
  34.       }
  35. }
  36. void mostrarinversa (int arreglo[],int num2,int n){
  37. if (n>0){
  38. mostrarinversa(arreglo,num2+1,n-1);
  39. cout<<arreglo[num2]<<" ";}  
  40. }
  41. void cargar (int arreglo[],int num2,int n){//en el siguiente metodo le pasado el vector y el indice que comienza en cero = num2
  42. if (n>0){   //num2 debe ir aumentando de 1 en 1
  43. srand(time(0));   //el srand sirve para sincronizar el rand con el reloj del pc
  44. cargar(arreglo,num2+1,n-1);   //llamamos a la misma funcion cargar pero menos el ultimo dato n-1
  45. arreglo[num2]=1+rand()% 10;}
  46. }
  47. void mostrar (int arreglo[],int num2,int n){
  48. if (n>0){
  49. mostrar(arreglo,num2+1,n-1);
  50. cout<<arreglo[num2]<<" ";}
  51. }

hola necesito ayuda en esto tengo que llevarlo a una matriz pero todo tiene que ser recurisvo desde cargar la matriz hasta mostrar la matriz solo se puede usar "If" HELP aun son muy nuevo en esto de la recursion



Mod: Es obligatorio el uso de etiquetas GeSHi para poner código.
Páginas: [1]
WAP2 - Aviso Legal - Powered by SMF 1.1.21 | SMF © 2006-2008, Simple Machines