Menú

Mostrar Mensajes

Esta sección te permite ver todos los mensajes escritos por este usuario. Ten en cuenta que sólo puedes ver los mensajes escritos en zonas a las que tienes acceso en este momento.

Mostrar Mensajes Menú

Mensajes - Omar_2013

#21
El codigo compila pero el ejecutable no funciona tal como la imagen de el link

Código (cpp) [Seleccionar]
#include <cstdlib>
#include <iostream>

using namespace std;

struct Item{
      int Peso;
      int Volumen;
      string Nombre;
};

struct Maleta{
      int Peso;
      int Volumen;
      int Cantidad_Items;
      Item *Items;
};

int main(int argc, char *argv[])
{
   Maleta *Mi_Maleta=new Maleta[10];
   Mi_Maleta->Items=new Item[10];
   
   Mi_Maleta[1].Items[0].Nombre="Peras";
   Mi_Maleta[1].Items[0].Volumen=12;
   Mi_Maleta[1].Items[0].Peso=16;

     
   system("PAUSE");
   return EXIT_SUCCESS;
}

http://www.subirimagenes.com/imagen-imagen1-8658261.html
#22
 :huh:  de todas maneras gracias.  :huh:
#23
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
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...


#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


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?
#26
#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