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

 

 


Tema destacado: Introducción a la Factorización De Semiprimos (RSA)


  Mostrar Mensajes
Páginas: [1]
1  Programación / Programación C/C++ / Archivos en c++ en: 22 Noviembre 2014, 20:39 pm
Hola que tal, tengo una duda en el manejo de archivos en C++
ok, lo que pasa aquí es que necesito buscar en dos archivos distintos y imprimir los que tengan igual ID de usuario
algo así llevo
Código
  1.  
  2. void Prestamo::Mostrar()
  3. {
  4. ifstream prestamo("prestamo.txt");
  5. ifstream objeto("usuarios.txt");
  6. int dimension;
  7. if(!prestamo.good())
  8.   {
  9.       cout<<"\nARCHIVO PRESTAMOS INEXISTENTE";
  10.   }
  11.   if(!objeto.good())
  12.   {
  13.      cout<<"\nARCHIVO USUARIOS INEXISTENTE";
  14.   }
  15.   else{
  16.        prestamo.seekg(0,ios::end);
  17.        int nreg=(prestamo.tellg()/sizeof(pr));
  18.        int i;
  19.    for(i=0;i<nreg;i++)
  20.    {
  21.  
  22.        prestamo.read((char*)&pr,sizeof(Prestamo));
  23.  
  24.  
  25.                objeto.read((char*)&dimension,sizeof(int));
  26.                objeto.read((char*)&yo.id,dimension);
  27.                strcpy(yo.id, cifrar(yo.id, dimension));
  28.                yo.id[dimension]='\0';
  29.                objeto.read((char*)&dimension,sizeof(int));
  30.                objeto.read((char*)&yo.contra,dimension);
  31.                strcpy(yo.contra, cifrar(yo.contra, dimension));
  32.                yo.contra[dimension]='\0';
  33.                objeto.read((char*)&dimension,sizeof(int));
  34.                objeto.read((char*)&yo.tipo,dimension);
  35.                strcpy(yo.tipo, cifrar(yo.tipo, dimension));
  36.                yo.tipo[dimension]='\0';
  37.                objeto.read((char*)&dimension,sizeof(int));
  38.                objeto.read((char*)&yo.nombre,dimension);
  39.                strcpy(yo.nombre, cifrar(yo.nombre, dimension));
  40.                yo.nombre[dimension]='\0';
  41.                objeto.read((char*)&dimension,sizeof(int));
  42.                objeto.read((char*)&yo.fecha,dimension);
  43.                strcpy(yo.fecha, cifrar(yo.fecha, dimension));
  44.                yo.fecha[dimension]='\0';
  45.                objeto.read((char*)&dimension,sizeof(int));
  46.                objeto.read((char*)&yo.RFC,dimension);
  47.                strcpy(yo.RFC, cifrar(yo.RFC, dimension));
  48.                yo.RFC[dimension]='\0';
  49.                objeto.read((char*)&dimension,sizeof(int));
  50.                objeto.read((char*)&yo.telefono,dimension);
  51.                strcpy(yo.telefono, cifrar(yo.telefono, dimension));
  52.                yo.telefono[dimension]='\0';
  53.                objeto.read((char*)&dimension,sizeof(int));
  54.                objeto.read((char*)&yo.horario,dimension);
  55.                strcpy(yo.horario, cifrar(yo.horario, dimension));
  56.                yo.horario[dimension]='\0';
  57.                objeto.read((char*)&dimension,sizeof(int));
  58.                objeto.read((char*)&yo.LibrosPrestados,dimension);
  59.                strcpy(yo.LibrosPrestados, cifrar(yo.LibrosPrestados, dimension));
  60.                yo.LibrosPrestados[dimension]='\0';
  61.                if(objeto.eof())
  62.                    break;
  63.            if(prestamo.eof())
  64.            break;
  65.        cout<<"\n\nFecha: "<<fechaprestamo<<endl;
  66.        cout<<"\nFolio: "<<folio<<endl;
  67.        cout<<"\nID: "<<idusuario<<endl;
  68.        cout<<"\nStatus: "<<status<<endl;
  69.        cout<<yo.id<<endl;
  70.       if(strcmp(yo.id,idusuario)==0)
  71.                   {
  72.  
  73.    cout<<"______________________________"<<endl;
  74.    cout<<"ID: "<<yo.id<<endl;
  75.    cout<<"Nombre: "<<yo.nombre<<endl;
  76.    cout<<"______________________________"<<endl;
  77.                    }
  78.    }
  79.   }
  80.   prestamo.close();
  81.   objeto.close();
  82. }
  83.  
  84.  

De antemano Gracias
2  Programación / Java / Re: Arreglo de objetos en: 16 Marzo 2014, 22:33 pm
El error esta en la linea 115, lo hice por separado, es decir solo accediendo a la propiedad nombre de uno de los objetos y todo bien, el problema viene cuando intento comparar esa propiedad en los dos objetos .

el Error lo marca aqui:
Código
  1. for(i=0;i<n||i<a;i++)
  2. {
  3.  
  4. if(x[i].nombre.equals(temp))
  5. {e=1;  
  6.  
  7. }
  8. if(y[i].nombre.equals(temp)){
  9. u=1;
  10.  
  11. }
3  Programación / Java / Re: Arreglo de objetos en: 16 Marzo 2014, 19:47 pm
Di a notar que soy demasiado nueva en esto, disculpen por lo del código
y en realidad si estoy estudiando poo, pero apenas ando en inicios es de mis primeros programas. Aun sigue sin resolverse esto de antemano gracias.
Código
  1. import java.util.Scanner;
  2. public class Sistema {
  3. static Scanner Leer=new Scanner(System.in);
  4. public static void main(String[]arg)
  5. {
  6. int op, o,p;
  7. int a=0, n=0,i;
  8. int e=0;
  9. int u=0;
  10. String temp;
  11. Contado[] x=new Contado[5];
  12. Credito[] y=new Credito[5];
  13. for (i=0;i<5;i++)
  14. {
  15. x[i]=new Contado();
  16. y[i]=new Credito();
  17. }
  18.  
  19.  
  20. do{
  21. System.out.println("Menu");
  22. System.out.println("1.Ventas de Contado");
  23. System.out.println("2.Ventas a Credito");
  24. System.out.println("3.Modificar");
  25. System.out.println("4.Eliminar");
  26. System.out.println("5.Salir");
  27. op=Leer.nextInt();
  28. switch(op)
  29. {
  30. case 1:
  31. do{
  32. System.out.println("MENU");
  33. System.out.println("1.Agregar Venta");
  34. System.out.println("2.Mostrar Ventas");
  35. System.out.println("3.Regresar");
  36. o=Leer.nextInt();
  37. switch(o)
  38. {
  39. case 1:
  40. if(n<5)
  41. {
  42. x[n].Capturar();
  43. n++;
  44. }
  45. else
  46. {
  47. System.out.println("Memoria llena");
  48. }
  49. break;
  50. case 2:
  51. if(n>0){
  52. for(i=0;i<n; i++)
  53. {
  54. x[i].Mostrar();
  55. }
  56. }
  57. else{
  58. System.out.println("No hay datos");
  59. }
  60.  
  61. break;
  62. case 3:
  63. break;
  64. }
  65. }while(o!=3);
  66. break;
  67. case 2:
  68. do{
  69.  
  70. System.out.println("MENU");
  71. System.out.println("1.Agregar Venta");
  72. System.out.println("2.Mostrar Ventas");
  73. System.out.println("3.Regresar");
  74. p=Leer.nextInt();
  75. switch(p)
  76. {
  77. case 1:
  78. if(a<5)
  79. {
  80. y[a].Capturar();
  81. a++;
  82. }
  83. else
  84. {
  85. System.out.println("Memoria llena");
  86. }
  87. break;
  88. case 2:
  89. if(a>0){
  90. for(i=0;i<a;i++)
  91. {
  92. y[i].Mostrar();
  93.  
  94. }
  95. }
  96. else{
  97. System.out.println("No hay datos");
  98. }
  99.  
  100. break;
  101. }
  102. }while(p!=3);
  103. break;
  104. case 3:
  105. System.out.println("Ingrese nombre del cliente a buscar");
  106. temp=Leer.nextLine();
  107. temp=Leer.nextLine();
  108. for(i=0;i<n||i<a;i++)
  109. {
  110.  
  111. if(x[i].nombre.equals(temp))
  112. {e=1;  
  113.  
  114. }
  115. if(y[i].nombre.equals(temp)){u=1;
  116.  
  117. }
  118. }
  119.  
  120. if(e==1){
  121.             System.out.println("Existe! ");
  122.             x[i].Modificar();
  123.            }
  124. if(u==1)
  125. {
  126. System.out.println("Existe! ");
  127. y[i].Modificar();
  128. }
  129.  
  130.  
  131. else{
  132.  
  133. System.out.println("No tengo ese dato");
  134. }
  135.  
  136.  
  137. break;
  138.  
  139. case 4:
  140. System.out.println("Ingrese nombre del cliente a buscar");
  141. temp=Leer.nextLine();
  142. temp=Leer.nextLine();
  143. for(i=0;i<n||i<a;i++)
  144. {
  145.  
  146. if(x[i].nombre.equals(temp)) e=1;
  147.  
  148.  
  149.       if(y[i].nombre.equals(temp))u=1;
  150.  
  151. }
  152.  
  153. if(e==1)
  154.             System.out.println("Eliminado! ");
  155.            n--;
  156. if(u==1)
  157. System.out.println("Eliminado! ");
  158. a--;
  159.  
  160.  
  161. /*else{
  162.  
  163. System.out.println("No tengo ese dato");
  164. }*/
  165. }
  166.  
  167.  
  168.  
  169.  
  170. }while(op!=5);
  171.  
  172. }
  173. }
  174.  
El programa me crashea a la hora de entrar en el caso 3 o 4 con el error java.lang.NulPointerExceptionl
4  Programación / Java / Arreglo de objetos en: 16 Marzo 2014, 06:29 am
Hola que tal estoy haciendo un programa donde tengo que realizar una busqueda en dos arreglos diferentes de objetos pero me esta marcando error no se si tengan alguna sugerencia
Aqui el codigo
Código
  1. [code=java]
  2. System.out.println("Ingrese nombre del cliente a buscar");
  3. temp=Leer.nextLine();
  4. temp=Leer.nextLine();
  5. for(i=0;i<n||i<a;i++)
  6. {
  7.  
  8. if(x[i].nombre.equals(temp)){
  9. e=1;
  10. }
  11. else if(y[i].nombre.equals(temp))
  12. {
  13. u=1;
  14. }
  15. if(e==1){System.out.println("Eliminado! ");
  16.                             n--;}
  17.                         else if(u==1)
  18. {
  19. System.out.println("Eliminado! ");
  20. a--;
  21. }
  22.  
[/code]
no me quiere entrar a ninguno de los else if solo me busca en el objeto "x"
Páginas: [1]
WAP2 - Aviso Legal - Powered by SMF 1.1.21 | SMF © 2006-2008, Simple Machines