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

 

 


Tema destacado: Recopilación Tutoriales y Manuales Hacking, Seguridad, Privacidad, Hardware, etc


  Mostrar Mensajes
Páginas: 1 2 [3] 4
21  Programación / Programación C/C++ / Re: Inserción de datos ABB con archivos en: 27 Octubre 2016, 21:52 pm
Código
  1. using namespace std;
  2.  
  3. typedef struct arbol{
  4.    int id;
  5.    char nombre[20];
  6.    char fecha[10];
  7.    int existencia;
  8.    struct arbol *izquierda,*derecha;
  9. };
  10.  
  11.  
  12. arbol* insercion(arbol*,int,char[],char[],int);
  13. char menu();
  14. void captura(arbol*);
  15. void inOrder(arbol *);
  16. void mostrar(arbol*,int,char[],char[],int);
  17. void validar_letras (char *p);
  18. char getchass ();
  19. void insert(int key, struct node **leaf);
  20. main(){
  21. arbol *raiz=NULL;
  22. char op;
  23. do{
  24. op=menu();
  25. switch(op){
  26. case '1':captura(raiz);break;
  27. case '2':
  28.        printf("Inorden: ");
  29.                    printf("%d",raiz->id);
  30. //inOrder(raiz);
  31. break;
  32. case '3':break;
  33. case '4':break;
  34.  
  35. }
  36.  
  37. }while(op!='5');
  38. return 0;
  39. }
  40.  
  41. char menu(){
  42. char op;
  43. system("cls");
  44. printf("1.- Capturar arbol\n");
  45. printf("2.- Imprimir arbol\n");
  46. printf("3.- Actualizar existencias\n");
  47. printf("4.- Status del producto\n");
  48. printf("5.- Salir\n");
  49. printf("Opcion: ");fflush(stdin);
  50.  
  51.  
  52. op=getch();
  53. printf("\n");
  54. return op;
  55.  
  56.  
  57. }
  58.  
  59. void captura(arbol *r){
  60. arbol *raiz=NULL;
  61. int i=1;
  62.    int idd;
  63.    char nombree[20];
  64.    char fechaa[10];
  65.    int existenciaa;
  66.  
  67. FILE *ptr;
  68. ptr = fopen("150941_Aguilar_Av1-2.txt", "r");
  69.  
  70.  
  71.   do{
  72. fscanf(ptr,"%d",&idd);
  73.   fscanf(ptr,"%s",nombree);
  74.   fscanf(ptr,"%s",fechaa);
  75.   fscanf(ptr,"%d",&existenciaa);
  76.  
  77. i++;      
  78. insercion(raiz,idd,nombree,fechaa,existenciaa);
  79.   }while(!feof(ptr));
  80. fclose(ptr);  
  81. printf("Registros guardados %d\n",i);
  82.  
  83. getchar();
  84.  
  85.  
  86.  
  87.  
  88.   /*
  89.    while(!feof(fichero)) fputc(fgetc(fichero), stdout);
  90.  
  91.    fclose(fichero);
  92.    getchar();*/
  93.  
  94. }
  95. arbol* insercion(arbol *r,int id,char nombre[20],char fecha[10],int existencia){    
  96.  
  97.    if(r==NULL)
  98.    {
  99.        r=(arbol*)malloc(sizeof(arbol));
  100.        r->id=id;
  101.        strcpy(r->nombre,nombre);
  102.        strcpy(r->fecha,fecha);
  103.        r->existencia=existencia;
  104.        r->izquierda=NULL;
  105.        r->derecha=NULL;
  106.        return r;
  107.    }
  108.    else
  109.    {
  110.        if(r->id > id)
  111.            r->izquierda = insercion(r->izquierda,id,nombre,fecha,existencia);
  112.        else
  113.            r->derecha = insercion(r->derecha,id,nombre,fecha,existencia);
  114.  
  115.  
  116. }
  117. }
  118.  
  119. void inOrder(arbol *r){
  120.    if(r!=NULL){
  121.        inOrder(r->izquierda);
  122.        printf("%d -> ",r->id);
  123.        inOrder(r->derecha);
  124.    }
  125.    getch();
  126.  
  127. }

Trate de hacer distinto el codigo, se supone que ya esta dentro del arbol, pero a la hora de mostrar lo que hay en el no me corre, alguien puede detectar mi error?
O la manera en que estoy guardando los datos en el arbol es incorrecto y en lugar de hacerlo mediante fichero, hacerlo manualmente?
22  Programación / Programación C/C++ / Inserción de datos ABB con archivos en: 26 Octubre 2016, 23:11 pm
Tengo una duda al querer capturar los datos de un archivo y a la vez guardarlos en el árbol como podría hacerlo?
Código:
1
leche
20-12-2016
10
2
arroz
22/02/2017
8
3
Huevos
25/11/2016
8
4
frijoles
29/12/2017
12
5
maiz
31/03/2017
8
6
papas
20/03/2017
8
7
caramelos
08/09/2022
15
9
refresco
09/09/2019
18
10
harina
22/05/2018
11
Carne
10/04/2017
Esos son mis datos y mi código es:
Código
  1. typedef struct arbol{
  2.    int id;
  3.    char nombre;
  4.    char fecha;
  5.    int existencia;
  6.    struct arbol *izquierda,*derecha;
  7. }arbol;
  8.  
  9.  
  10. int menu();
  11. void captura();
  12. main(){
  13. arbol *raiz=NULL;
  14. char op;
  15. do{
  16. op=menu();
  17. switch(op){
  18. case 1:captura();break;
  19. case 2:printf("b");
  20. case 3:break;
  21. case 4:break;
  22. case 5:break;
  23. default:printf("Opcion invalida\n");system("pause");break;
  24.  
  25. }
  26.  
  27. }while(op!=5);
  28.  
  29.  
  30. getch();
  31. }
  32.  
  33. int menu(){
  34. char op[2];
  35. int opp;
  36. system("cls");
  37. printf("1.- Capturar arbol\n");
  38. printf("2.- Imprimir arbol\n");
  39. printf("3.- Actualizar existencias\n");
  40. printf("4.- Status del producto\n");
  41. printf("5.- Salir\n");
  42. printf("Opcion: ");
  43.  
  44.  
  45. validar_letras (op);
  46. opp=atoi(op);
  47. return opp;
  48.  
  49.  
  50. }
  51.  
  52. void captura(){
  53. FILE *fichero;
  54.   fichero = fopen("150941_Aguilar_Av1-2.txt", "r");
  55.   while(!feof(fichero)) fputc(fgetc(fichero), stdout);
  56.   rewind(fichero);
  57.   while(!feof(fichero)) fputc(fgetc(fichero), stdout);
  58.   fclose(fichero);
  59.   getchar();
  60.  
  61. }
23  Programación / Programación C/C++ / Imprimir metodos en C++ en: 26 Octubre 2016, 03:14 am
Tengo esta duda a la hora de hacer el .cpp de Imprimir y a la hora de crear el main.cpp , no logro entenderlo del todo y no puedo.

Registro.hpp
Código
  1. #include<iostream>
  2. using namespace std;
  3.  
  4. class Registro{
  5.  
  6. private:
  7. string **nombres;
  8. int fila;
  9.  
  10. public:
  11. Registro();
  12. ~Registro();
  13.  
  14. void setFila(int);
  15. int getFila();
  16. void setNombres(string **,int);
  17. string** getNombres();
  18.  
  19. };

Registro.cpp
Código
  1. #include "Registro.hpp"
  2.  
  3. Registro::Registro(){
  4. cout<<endl<<"Filas: ";
  5. cin>>fila;
  6.  
  7. nombres = new string*[fila];
  8. for(int i=0;i<fila;i++){
  9. *(nombres+i)=new string[3];
  10. }
  11. setNombres(nombres,fila);
  12. }
  13.  
  14. Registro::~Registro(){
  15. delete []nombres;
  16. }
  17.  
  18. void Registro::setFila(int fila){
  19. this->fila=fila;
  20. }
  21.  
  22. int Registro::getFila(){
  23. return fila;
  24. }
  25.  
  26. void Registro::setNombres(string **nombres,int fila){
  27. for(int i=0;i<fila;i++){
  28. cin.ignore(256,'\n');
  29. cout<<"Nombre: ";
  30. getline(cin, *(*(nombres+i)+0));
  31. cout<<"Apellido: ";
  32. getline(cin, *(*(nombres+i)+1));
  33. cout<<"Edad: ";
  34. getline(cin,*(*(nombres+i)+2));
  35. }
  36. this->nombres=nombres;
  37. }
  38.  
  39. string ** Registro::getNombres(){
  40. return nombres;
  41. }

Imprimir.hpp
Código
  1. #include<iomanip>
  2. using namespace std;
  3.  
  4. class Imprimir{
  5. public:
  6. void imprime(string **,int);
  7. };

Hasta ahora llevo eso, y no logro llevar al main todo eso.
24  Programación / Programación C/C++ / Re: Problema con registro y funciones en: 20 Octubre 2016, 04:09 am
Código
  1. #include<stdlib.h>
  2. #include<iomanip>
  3. #include<iostream>
  4.  
  5. using namespace std;
  6. typedef struct{
  7. char nombre[20];
  8. int notas;
  9. }Dato;
  10.  
  11. int main(){
  12. int n;
  13. Dato *_dato;
  14. cout<<"Cuantos estudiantes ingresaras: ";
  15. cin>>n;
  16. _dato=(Dato *)malloc(n*sizeof(Dato));
  17.  
  18. for(int i=0; i<n; i++){
  19. cout<<"Nombre del estudiante:";
  20. fflush(stdin);
  21. cin.getline((_dato+i)->nombre,20, '\n');
  22. //gets(_dato[i].nombre);
  23. cout<<endl<<"Nota: ";
  24. cin>>(_dato+i)->notas;
  25. //scanf("%d",&_dato[i].edad);
  26. }
  27.  
  28. for(int i=0; i<n; i++){
  29. cout<<endl<<(*(_dato+i)).nombre;
  30. cout<<endl<<(*(_dato+i)).notas;
  31. }
  32.  
  33. free(_dato);
  34.  
  35. }

Se me borro todo lo que escribi ,pero te dejo el código mas simple, para que puedas analizarlo, cualquier cosa mándame mensaje.
Elimina cosas al código, modifícalo para que veas como funciona.
25  Programación / Programación C/C++ / Re: Problema con registro y funciones en: 20 Octubre 2016, 02:17 am
Código
  1.  
  2. _dato=(Dato *)malloc(n*sizeof(Dato));
  3. /*al ser una estructura dinámica, tu tienes que reservar memoria para esta es lo mismo que con los arrays tu tienes un int[5]; declarado, pero esto tu lo defines, no el usuario al reservar memoria es algo similar a int[n], con malloc y realloc asignas la memoria dinámica, no se si me entidas?*/
  4.  
  5. recibe(_dato,n);
  6. /*Esta es una función, que puedes invocar en el main, La función recibe la cantidad de estudiantes a registrar y los registra.*/
  7.  
  8. free(_dato);
  9. /*asi como reservas memoria, la tienes que liberar, y el usuario reservo memoria dinámica para la estructura*/
  10.  
  11. /*Forma parte de la librería conio.h */
  12.  
  13. fflush(stdin);
  14. /*limpia el buffer, para cuando reciba los nombres */
  15.  
  16. cin.getline((_dato+i)->nombre,20, '\n');
  17. /*escaneas nombre la posición de i
  18. es lo mismo que escribir //gets(_dato[i].nombre);*/
  19.  
  20. cin>>(_dato+i)->notas;
  21. /*es lo mismo escaneas notas en la posición de i
  22. es lo mismo que escribir //scanf("%d",&_dato[i].edad); */

No se si me entiendas? Puedo explicarlo mejor si deseas, tu pregunta con confianza.
26  Programación / Programación C/C++ / Re: Problema con registro y funciones en: 20 Octubre 2016, 00:31 am
Código
  1. #include<stdlib.h>
  2. #include<iomanip>
  3. #include<iostream>
  4. #include<conio.h>
  5. using namespace std;
  6. typedef struct{
  7. char nombre[20];
  8. int notas;
  9. }Dato;
  10. void recibe(Dato *,int);
  11. void imprime(Dato *,int);
  12.  
  13. int main(){
  14. int n;
  15. Dato *_dato;
  16. printf("Cantidad de estudiantes: ");
  17. cin>>n;
  18. _dato=(Dato *)malloc(n*sizeof(Dato));
  19. recibe(_dato,n);
  20. imprime(_dato,n);
  21. free(_dato);
  22. getch();
  23. }
  24.  
  25. void recibe(Dato *_dato,int n){
  26. for(int i=0; i<n; i++){
  27.  
  28. cout<<"Nombre del estudiante:";
  29. fflush(stdin);
  30. cin.getline((_dato+i)->nombre,20, '\n');
  31. //gets(_dato[i].nombre);
  32.  
  33. cout<<endl<<"Nota: ";
  34. cin>>(_dato+i)->notas;
  35. //scanf("%d",&_dato[i].edad);
  36. }
  37.  
  38.  
  39. }
  40.  
  41. void imprime(Dato *_dato,int n){
  42. for(int i=0; i<n; i++){
  43. cout<<endl<<(*(_dato+i)).nombre;
  44. cout<<endl<<(*(_dato+i)).notas;
  45. }
  46. }

Buscas hacer es algo asi no?
27  Programación / Programación C/C++ / Re: [Ayuda] Cajero automatico en C++ en: 17 Octubre 2016, 19:48 pm
Deberias empezar por hacer paso por paso.
Por cierto el else va fuera del switch.
Mas tarde lo veo
28  Programación / Programación C/C++ / Re: Ayuda para generar un ID automatico en: 13 Octubre 2016, 06:12 am
En tu estructura solo defines artista, albulm y genero, el id lo declaras como variable local, y cada vez que preguntas la música aumentas en 1 el id.
Y al imprimir muestras id, artista,albulm y genero.
Tengo un código parecido por si ocupas mas ayuda
29  Programación / Programación C/C++ / Re: Puzzle 8 en C en: 26 Abril 2016, 05:26 am
uy te falto las etiquetas geshi!!!

Me funciona pero al momento de cambiar los numeros por el 0, no lo hace en el orden que deberia lo hace cruzado y asi. Alguna ayuda?
30  Programación / Programación C/C++ / Re: Puzzle 8 en C en: 26 Abril 2016, 03:57 am
Cambie el codigo y lo hice 3 x 3, pero al momento de validar los movimientos no logro hacer que se muevan correctamente.

Código:
#include <stdio.h>
#include <stdlib.h>
#include <conio.h>
#include <windows.h>
#include <time.h>
 
void gotoxy(short x, short y){
    COORD pos = {x , y};
    SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE),pos);}
 
main()
{
    int r, x, y, j, vm, k, v,i;
    int a[9], b[3][3],c[3][3];
 
    srand (time(NULL));
     for (i=0; i<=7; i++) {
        a[i] = rand()%(7+1);
    }
    r = 1;
 
    while (r == 1) {
        r = 0;
        for (i=0; i<=7; i++) {
            if (a[i]==0)
        a[i]++;
            for (j=i+1; j<=7; j++)
{
 
                if (a[i] == a[j] && a[i] !=8) {
                    a[i] = a[i] +1;
                    r = 1;
 
                }
                if (a[i] == a[j] && a[i] ==8) {
                    a[i] = a[i] -rand()%(7+1);
                    r = 1; }
            }}}
 
            j=0;
    for (x=0; x<=2; x++) {
    for(y=0; y<=2; y++)
{b[x][y]=a[j];j++;
         }}
  x=2;
  y=2;
  fflush(stdin);
 
b[2][2]=0;
c[0][0]=1;
         c[0][1]=2;
         c[0][2]=3;
         c[1][0]=4;
         c[1][1]=5;
         c[1][2]=6;
         c[2][0]=7;
         c[2][1]=8;
         c[2][2]=0;
       
 
 
    do{
  ///////////////////IZQ////////////////////
gotoxy(1,2);printf("%c",201); 
        gotoxy(1,3);printf("%c",186);
        gotoxy(1,4);printf("%c",204);
        gotoxy(1,5);printf("%c",186);
        gotoxy(1,6);printf("%c",204);
        gotoxy(1,7);printf("%c",186);
        gotoxy(1,8);printf("%c",200);

///////////////////Arriba////////////////////
gotoxy(2,2);printf("%c",205);   
        gotoxy(3,2);printf("%c",205); 
        gotoxy(4,2);printf("%c",203);
        gotoxy(5,2);printf("%c",205);
        gotoxy(6,2);printf("%c",205);
        gotoxy(7,2);printf("%c",203);
        gotoxy(8,2);printf("%c",205); 
gotoxy(9,2);printf("%c",205);
gotoxy(10,2);printf("%c",187);



/////////////////linea 1///////////////////   
 
        gotoxy(4,3);printf("%c",186);
        gotoxy(4,5);printf("%c",186);
        gotoxy(4,7);printf("%c",186); 

 
 /////////////////linea 2///////////////////   
 
        gotoxy(7,3);printf("%c",186);
        gotoxy(7,5);printf("%c",186);
        gotoxy(7,7);printf("%c",186); 

 /////////////////linea 3///////////////////   
 
        gotoxy(10,3);printf("%c",186);
        gotoxy(10,5);printf("%c",186);
        gotoxy(10,7);printf("%c",186); 
   
//////////////////ABAJO 1/////////////////////
gotoxy(2,4);printf("%c",205);   
        gotoxy(3,4);printf("%c",205); 
        gotoxy(4,4);printf("%c",206);
        gotoxy(5,4);printf("%c",205);
        gotoxy(6,4);printf("%c",205);
        gotoxy(7,4);printf("%c",206);
        gotoxy(8,4);printf("%c",205); 
gotoxy(9,4);printf("%c",205);
gotoxy(10,4);printf("%c",185);

 
//////////////////ABAJO 1/////////////////////
gotoxy(2,6);printf("%c",205);   
        gotoxy(3,6);printf("%c",205); 
        gotoxy(4,6);printf("%c",206);
        gotoxy(5,6);printf("%c",205);
        gotoxy(6,6);printf("%c",205);
        gotoxy(7,6);printf("%c",206);
        gotoxy(8,6);printf("%c",205); 
gotoxy(9,6);printf("%c",205);
gotoxy(10,6);printf("%c",185);


//////////////////ABAJO 1/////////////////////
gotoxy(2,8);printf("%c",205);   
        gotoxy(3,8);printf("%c",205); 
        gotoxy(4,8);printf("%c",202);
        gotoxy(5,8);printf("%c",205);
        gotoxy(6,8);printf("%c",205);
        gotoxy(7,8);printf("%c",202);
        gotoxy(8,8);printf("%c",205); 
gotoxy(9,8);printf("%c",205);
gotoxy(10,8);printf("%c",188);
 
////////////////////////////////////////////
  /////////////////////////
 
  gotoxy(2,3);printf("%d",b[0][0]);
   gotoxy(5,3);printf("%d",b[0][1]);
   gotoxy(8,3);printf("%d",b[0][2]);
   gotoxy(2,7);printf("%d",b[1][0]);
   gotoxy(2,5);printf("%d",b[1][1]);
   gotoxy(5,5);printf("%d",b[1][2]);
   gotoxy(8,5);printf("%d",b[2][0]);
   gotoxy(5,7);printf("%d",b[2][1]);
   gotoxy(8,7);printf("%d",b[2][2]);
 
   //////////////////////////////////////
 
 
    vm=getch();
    system("cls");
 
 //////////////////////////////////////
 
 
    vm=getch();
    system("cls");
 
    switch(vm)
    {
    case 80: //FLECHA DERECHA
    if(x <= 2){
 
v=b[x+1][y];
b[x][y]=v;
b[x+1][y]=0;
x++;
}   
 
    break;
    case 72: //FLECHA IZQUIERDA
    if(x>0)
{
 
v=b[x-1][y];
b[x-1][y]=0;
b[x][y]=v;
    x--;
}
 
    break;
    case 77:   //FLECHA ABAJO
    if(y <= 2)
    {
    v=b[x][y+1];
    b[x][y+1]=0;
    b[x][y]=v;
    y++;
}
 
    break;
    case 75:    //FLECHA ARRIBA
    if(y > 0)
    {
    v=b[x][y-1];
    b[x][y-1]=0;
    b[x][y]=v;
    y--;
}
 
    break;
 
   } }while(vm!=13);
 
}
Páginas: 1 2 [3] 4
WAP2 - Aviso Legal - Powered by SMF 1.1.21 | SMF © 2006-2008, Simple Machines