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

 

 


Tema destacado: Trabajando con las ramas de git (tercera parte)


  Mostrar Mensajes
Páginas: 1 2 [3]
21  Programación / Programación C/C++ / Problema Con Un Arreglo Dinamico [?] en: 16 Octubre 2013, 01:31 am
El codigo compila pero el ejecutable no funciona tal como la imagen de el link

Código
  1. #include <cstdlib>
  2. #include <iostream>
  3.  
  4. using namespace std;
  5.  
  6. struct Item{
  7.       int Peso;
  8.       int Volumen;
  9.       string Nombre;
  10. };
  11.  
  12. struct Maleta{
  13.       int Peso;
  14.       int Volumen;
  15.       int Cantidad_Items;
  16.       Item *Items;
  17. };
  18.  
  19. int main(int argc, char *argv[])
  20. {
  21.    Maleta *Mi_Maleta=new Maleta[10];
  22.    Mi_Maleta->Items=new Item[10];
  23.  
  24.    Mi_Maleta[1].Items[0].Nombre="Peras";
  25.    Mi_Maleta[1].Items[0].Volumen=12;
  26.    Mi_Maleta[1].Items[0].Peso=16;
  27.  
  28.  
  29.    system("PAUSE");
  30.    return EXIT_SUCCESS;
  31. }
http://www.subirimagenes.com/imagen-imagen1-8658261.html
22  Programación / Programación C/C++ / Re: Asignar Mas Memoria A Un Arreglo Dinamico en: 2 Septiembre 2013, 23:26 pm
 :huh:  de todas maneras gracias.  :huh:
23  Programación / Programación C/C++ / Re: Asignar Mas Memoria A Un Arreglo Dinamico en: 2 Septiembre 2013, 23:15 pm
soy un novato ... por eso necesitaba saber como se hacia de la forma innecesaria ...por que la verdad no te entendi eso de las clases...
24  Programación / Programación C/C++ / Asignar Mas Memoria A Un Arreglo Dinamico en: 2 Septiembre 2013, 22:36 pm
En el main tengo un arreglo de tamaño 1 pero necesito que este incremente su tamaño a medida que el usuario digite mas y mas datos...

Código:
#include <cstdlib>
#include <iostream>
#include <string>
#include <conio.h>

using namespace std;

struct Datos {
       string Nombre;
       int Edad;
};

struct Categorias {
       string Deporte;
       int Atletas;
       Datos Informacion;
};

void Ingresar_Deportista ( Categorias *Deportes, int Cant_Deportes );

int main(int argc, char *argv[])
{   
    int Num_Deportes=1; //Tamaño Variable - Cambia En Tiempo De Ejecucion
    Categorias *Deportes= new Categorias[Num_Deportes];

    Ingresar_Deportista( Deportes, Num_Deportes );
   
    system("PAUSE");
    return EXIT_SUCCESS;
}

Ese incremento de tamaño lo implemente en la funcion Ingresar_Deportista justo al final

Código:
void Ingresar_Deportista ( Categorias *Deportes, int Cant_Deportes ){
     
     int i=0, Aux=0;
     char Opcion='s';
     
     while(Opcion=='s'){
     cout<<"Deporte: ";
     cin>>Deportes[i].Deporte;
     cout<<"\nNombre: ";
     cin>>Deportes[i].Informacion.Nombre;
     cout<<"Edad: ";
     cin>>Deportes[i].Informacion.Edad;
     cout<<"\nIngresar Mas? Si(s) ";
     Opcion=getch();
     i+=1;
     system("cls");
     
//Si Supera El Tamaño Maximo (Darle Mas Memoria Al Arreglo Dinamico)

     if( i>=Cant_Deportes ){
         Categorias *Agrandar= new Categorias[Cant_Deportes+1];
         for(Aux=0; Aux<Cant_Deportes; Aux++)
         Agrandar[Aux]=Deportes[Aux];
         Deportes=Agrandar;}
     }
}

El codigo compila pero despues de ingresar el tercer deporte el ejecutable se totea, a que se debe esto?
25  Programación / Programación C/C++ / Re: Problema Con Un Arreglo Dinamico De Estructuras [?] en: 2 Septiembre 2013, 19:21 pm
Gracias.
26  Programación / Programación C/C++ / Problema Con Un Arreglo Dinamico De Estructuras [?] en: 2 Septiembre 2013, 18:56 pm
#include <cstdlib>
#include <iostream>


using namespace std;

struct Datos {
       char *Nombre;
       int Edad;
};

struct Categorias {
       char *Deporte;
       int Atletas;
       Datos *Informacion;
};

int main(int argc, char *argv[])
{  
    Categorias *Otro= new Categorias[10];
    
    Otro[0].Informacion->Nombre="Oscar";
        
    system("PAUSE");
    return EXIT_SUCCESS;
}


Pordrian por favor ayudarme .. el codigo compila pero el ejecutable se totea
Páginas: 1 2 [3]
WAP2 - Aviso Legal - Powered by SMF 1.1.21 | SMF © 2006-2008, Simple Machines