Foro de elhacker.net

Programaci๓n => Programaci๓n C/C++ => Mensaje iniciado por: mapers en 11 Marzo 2011, 07:56 am



Título: arreglo de estructuras
Publicado por: mapers en 11 Marzo 2011, 07:56 am
se๑ores del foro les pido que me ayuden tengo este problema necesito guardar en dos arreglos de estructuras 3 notas un nombre y un cnombre del curso y debo unir estos dos arreglos de estructuras en uno solo en la que se deve mostrar aquelos que llevan 2 cursos pero que tiene igual nombre y aquellos que llevan 1 solo curso y que tienen un solo nombre hay esta mi avance me falta para poder almacenar aquellos que solo tiene un solo  nombre y lleven un solo curso
Código
  1. //----------------------------------------------------------------//  
  2. //----------------------------------------------------------------//
  3. #include <iostream.h>
  4. #include <conio.h>
  5. #include <string.h>
  6. #include <iomanip.h>
  7. #define MAX 50
  8.  
  9. int s=0;
  10. int s1=0;
  11. int arreglox[100];
  12. int arregloy[100];
  13. int arrex[100];
  14. int arrey[100];
  15. int n=0;
  16. int m=0;
  17. //----------------------------------------------------------------//  
  18. //----------------------------------------------------------------//  
  19.  
  20. struct Alumno1{
  21.       char Nombre[MAX ];
  22.       char Curso [MAX];
  23.       int  nota1;
  24.       int  nota2;
  25.       int  nota3;
  26.  
  27.       };
  28.  
  29. struct Alumno2{
  30.       char Nombre[MAX ];
  31.        char Curso [MAX];
  32.       int  nota1;
  33.       int  nota2;
  34.       int  nota3;
  35.  
  36.       };  
  37.  
  38. struct Alumno1_unido_Alumno2{
  39.       char Nombre[MAX ];
  40.       char Curso [MAX];
  41.       char Curso1 [MAX];
  42.       int  nota1;
  43.       int  nota2;
  44.       int  nota3;
  45.       int  nota4;
  46.       int  nota5;
  47.       int  nota6;
  48.  
  49.       };  
  50.  
  51. //----------------------------------------------------------------//  
  52. //----------------------------------------------------------------//  
  53.  
  54. void Reguistro_Alumnos1(struct Alumno1 x[MAX],int numero_alumnos)
  55. {
  56.  
  57.     for(int i=0;i<numero_alumnos;i++)
  58.        {
  59.        getch();
  60.        cout<<endl;
  61.        cout<<"\t\t ศออออออออออออออออออออออออออออออออออออออออออผ\n";
  62.        cout<<"\t\tNombre ";
  63.        cin>>x[i].Nombre;
  64.        cout<<"\t\tMateria ";
  65.        cin>>x[i].Curso;
  66.        cout<<"\t\tIngrese Nota 1  ";
  67.        cin>>x[i].nota1;
  68.        cout<<"\t\tIngrese Nota 2  ";
  69.        cin>>x[i].nota2;
  70.        cout<<"\t\tIngrese Nota 3  ";
  71.        cin>>x[i].nota3;
  72.        }    
  73. }
  74.  
  75. //----------------------------------------------------------------//  
  76. //----------------------------------------------------------------//  
  77.  
  78. void  Leer_Reguistro(struct Alumno1 x[MAX],int numero_alumnos)
  79. {
  80.   cout<<"Listado del los primerol Alumnos"<<endl;
  81.   cout<<" ศออออออออออออออออออออออออออออออออออออออออออออออออออออออออออผ\n";
  82.   cout<<setw (25)<<" \t"<<"Nota 1 "<<"Nota 2 "<<"Nota 1 "<<endl;
  83.   for(int i=0;i<numero_alumnos;i++ )
  84.   {
  85.    cout<<" ศออออออออออออออออออออออออออออออออออออออออออออออออออออออออออผ\n";  
  86.    cout<<x[i].Nombre<<endl;
  87.    cout<<x[i].Curso<<endl;
  88.    cout<<setw (25)<<" \t"<< x[i].nota1<<" \t"<<x[i].nota2<<" \t"<<x[i].nota3<<endl;    
  89.   }
  90.   cout<<" ศออออออออออออออออออออออออออออออออออออออออออออออออออออออออออผ\n";
  91.   cout<<endl;  
  92. }
  93.  
  94. //----------------------------------------------------------------//  
  95. //----------------------------------------------------------------//  
  96.  
  97. void Reguistro_Alumnos11(struct Alumno2 y[MAX],int numero_alumnos1)
  98. {    system("color a");
  99.     for(int i=0;i<numero_alumnos1;i++)
  100.        {
  101.        getch();
  102.        cout<<endl;
  103.        cout<<"\t\t ศออออออออออออออออออออออออออออออออออออออออออผ\n";
  104.        cout<<"\t\t Nombre ";
  105.        cin>>y[i].Nombre;
  106.        cout<<"\t\t Materia ";
  107.        cin>>y[i].Curso;
  108.        cout<<"\t\t Ingrese Nota 1  ";
  109.        cin>>y[i].nota1;
  110.        cout<<"\t\t Ingrese Nota 2  ";
  111.        cin>>y[i].nota2;
  112.        cout<<"\t\t Ingrese Nota 3  ";
  113.        cin>>y[i].nota3;
  114.        }    
  115. }
  116.  
  117. //----------------------------------------------------------------//  
  118. //----------------------------------------------------------------//  
  119.  
  120. void  Leer_Reguistro1(struct Alumno2 y[MAX],int numero_alumnos1)
  121. {
  122.   cout<<"Listado del los primerol Alumnos"<<endl;
  123.   cout<<" ศออออออออออออออออออออออออออออออออออออออออออออออออออออออออออผ\n";
  124.   cout<<setw (25)<<" \t"<<"Nota 1 "<<"Nota 2 "<<"Nota 3 "<<endl;
  125.   for(int i=0;i<numero_alumnos1;i++ )
  126.   {
  127.    cout<<" ศออออออออออออออออออออออออออออออออออออออออออออออออออออออออออผ\n";
  128.    cout<<y[i].Nombre<<endl;
  129.    cout<<y[i].Curso<<endl;
  130.    cout<<setw (25)<< " \t"<< y[i].nota1<<" \t"<<y[i].nota2<<" \t"<<y[i].nota3<<endl;
  131.   }
  132.   cout<<" ศออออออออออออออออออออออออออออออออออออออออออออออออออออออออออผ\n";
  133.   cout<<endl;  
  134. }
  135.  
  136. //----------------------------------------------------------------//  
  137. //----------------------------------------------------------------//  
  138.  
  139. void Unir_Reguistros_Alumnos(struct Alumno1_unido_Alumno2 z[MAX],
  140. struct Alumno1 x[MAX],struct Alumno2 y[MAX],int numero_alumnos,int numero_alumnos1)
  141. {
  142.  
  143. //---------------------------------------------------------------//      
  144. for(int i=0;i<numero_alumnos;i++)
  145. {
  146.        for(int j=0;j<numero_alumnos1;j++)
  147.        {
  148.                if(strcmp(x[i].Nombre,y[j].Nombre)==0 && strcmp(x[i].Curso,y[j].Curso)!=0)
  149.                {          
  150.                      strcpy( z[ s ].Nombre, x[ i ].Nombre );
  151.                      strcpy( z[ s ].Curso, x[ i ].Curso );
  152.                      strcpy( z[ s ].Curso1, y[ j ].Curso );
  153.                      z[ s ].nota1=x[i].nota1;
  154.                      z[ s ].nota2=x[i].nota2;
  155.                      z[ s ].nota3=x[i].nota3;
  156.                      z[ s ].nota4=y[j].nota1;
  157.                      z[ s ].nota5=y[j].nota2;
  158.                      z[ s ].nota6=y[j].nota3;
  159.  
  160.                 s++;
  161.               }
  162.  
  163.  
  164.        }
  165.  
  166. }
  167.  
  168. }
  169. //----------------------------------------------------------------//  
  170. //----------------------------------------------------------------//
  171. void Unir_Reguistros_Alumnos1(struct Alumno1_unido_Alumno2 z[MAX],
  172. struct Alumno1 x[MAX],struct Alumno2 y[MAX],int numero_alumnos,int numero_alumnos1)
  173. {
  174. //---------------------------------------------------------------//    
  175.  
  176. for(int j=0;j<s+1;j++)
  177. {
  178.        for(int i=0;i<numero_alumnos;i++)
  179.        {              
  180.                if(strcmp(x[i].Nombre,z[j].Nombre)==0)
  181.                {          
  182.  
  183.               }    
  184.        }
  185.  
  186. }
  187. /*
  188. //---------------------------------------------------------------//  
  189. for(int j=0;j<s+1;j++)
  190.  {
  191.         for(int i=0;i<numero_alumnos1;i++)
  192.         {              
  193.                 if(strcmp(y[i].Nombre,z[j].Nombre)!=0)
  194.                 {          
  195.                       strcpy( z[ s1 ].Nombre, y[ i ].Nombre );
  196.                       strcpy( z[ s1 ].Curso, y[ i ].Curso );
  197.                       z[ s1 ].nota1=y[i].nota1;
  198.                       z[ s1 ].nota2=y[i].nota2;
  199.                       z[ s1 ].nota3=y[i].nota3;
  200. //----------------------------------------------------------------//
  201.                  
  202.                  s1++;
  203.                }
  204.                
  205.              
  206.         }
  207.      
  208.  }
  209.  
  210.    */
  211. cout<<"mira -------->"<<s1<<endl;
  212. }
  213. //----------------------------------------------------------------//  
  214. //----------------------------------------------------------------//
  215.  
  216. void Leer_Reguistro2(struct Alumno1_unido_Alumno2 z[MAX],int s)
  217. {
  218.   cout<<"Listado de la Union de los Alumnos que llevan 2 cursos diferentes "<<endl;
  219.   cout<<" ศออออออออออออออออออออออออออออออออออออออออออออออออออออออออออผ\n";
  220.   cout<<setw (25)<<" \t"<<"Nota 1 "<<"Nota 2 "<<"Nota 3 "<<endl;
  221.   for(int i=0;i<s;i++ )
  222.   {
  223.    cout<<" ศออออออออออออออออออออออออออออออออออออออออออออออออออออออออออผ\n";
  224.    cout<<z[i].Nombre<<endl;
  225.    cout<<z[i].Curso<<endl;
  226.    cout<<setw(25)<<" \t"<<z[i].nota1<<" \t"<<z[i].nota2<<" \t"<<z[i].nota3<<endl;
  227.    cout<<z[i].Curso1<<endl;
  228.    cout<<setw(25)<<" \t"<<z[i].nota4<<" \t"<<z[i].nota5<<" \t"<<z[i].nota6<<endl;
  229.  
  230.    }
  231.    cout<<endl;
  232.    cout<<" ศออออออออออออออออออออออออออออออออออออออออออออออออออออออออออผ\n";
  233.     cout<<"Listado de la Union de los Alumnos que llevan 1 solo curso "<<endl;
  234.    for(int i=s;i<s1;i++ )
  235.   {
  236.      cout<<" ศออออออออออออออออออออออออออออออออออออออออออออออออออออออออออผ\n";
  237.      cout<<z[i].Nombre<<endl;
  238.      cout<<z[i].Curso<<endl;
  239.      cout<<setw(25)<<" \t"<<z[i].nota1<<" \t"<<z[i].nota2<<" \t"<<z[i].nota3<<endl;
  240.    }
  241.   cout<<endl;  
  242. }
  243.  
  244. //----------------------------------------------------------------//  
  245. //----------------------------------------------------------------//
  246.  
  247. int main()
  248. {
  249.  struct Alumno1 x[MAX];
  250.  struct Alumno2 y[MAX];
  251.  struct Alumno1_unido_Alumno2 z[MAX];
  252.  int numero_alumnos,numero_alumnos1;
  253.  system("color 4");
  254.  cout<<"Ingrese el numero de Alumnos"<<endl;
  255.  cin>>numero_alumnos;
  256.  Reguistro_Alumnos1(x,numero_alumnos);
  257.  Leer_Reguistro(x,numero_alumnos);
  258.  cout<<"Ingrese el numero de Alumnos 2"<<endl;
  259.  cin>>numero_alumnos1;
  260.  Reguistro_Alumnos11(y,numero_alumnos1);
  261.  Leer_Reguistro1(y,numero_alumnos1);
  262.  Unir_Reguistros_Alumnos(z,x,y,numero_alumnos,numero_alumnos1);
  263.  Unir_Reguistros_Alumnos1(z,x,y,numero_alumnos,numero_alumnos1);
  264.  Leer_Reguistro2(z,s);
  265.  system("pause");
  266. }
  267. //----------------------------------------------------------------//  
  268. //----------------------------------------------------------------//  
  269.  
  270.