Advertisement
Guest User

Untitled

a guest
Mar 20th, 2014
137
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.89 KB | None | 0 0
  1. #include <iostream>
  2. #include <stdlib.h>
  3. using namespace std;
  4.  
  5. class jugador
  6. {
  7. private:
  8.  
  9.     int id;
  10.     short seleccion;
  11.     short edad;
  12.     short camiseta;
  13.  
  14. public:
  15.     jugador();
  16.     jugador(int ID, short SELECCION, short EDAD, short CAMISETA);
  17.     int obtener_id();
  18.     short obtener_seleccion();
  19.     short obtener_edad();
  20.     short obtener_camiseta();
  21.     void cambiar_id(int nueva_id);
  22.     void cambiar_seleccion(short nueva_seleccion);
  23.     void cambiar_edad(short nueva_edad);
  24.     void cambiar_camiseta(short nueva_edad);
  25.     void cambiar_todo(int nueva_ID, short nueva_SELECCION, short nueva_EDAD, short nueva_CAMISETA);
  26.     void mostrar_jugador();
  27. };
  28.  
  29. jugador::jugador()
  30. {
  31.  
  32.     id=999999;
  33.     seleccion=32;
  34.     edad=99;
  35.     camiseta=99;
  36.  
  37. }
  38.  
  39. jugador::jugador(int ID, short SELECCION, short EDAD, short CAMISETA)
  40. {
  41.  
  42.     id=ID;
  43.     seleccion=SELECCION;
  44.     edad=EDAD;
  45.     camiseta=CAMISETA;
  46.  
  47. }
  48.  
  49. int jugador::obtener_id()
  50. {
  51.  
  52.     return id;
  53.  
  54. }
  55.  
  56. short jugador::obtener_seleccion()
  57. {
  58.  
  59.     return seleccion;
  60.  
  61. }
  62.  
  63. short jugador::obtener_edad()
  64. {
  65.  
  66.     return edad;
  67.  
  68. }
  69.  
  70. short jugador::obtener_camiseta()
  71. {
  72.  
  73.     return camiseta;
  74.  
  75. }
  76.  
  77. void jugador::cambiar_id(int nueva_id)
  78. {
  79.  
  80.     id=nueva_id;
  81.  
  82. }
  83.  
  84. void jugador::cambiar_seleccion(short nueva_seleccion)
  85. {
  86.  
  87.     seleccion=nueva_seleccion;
  88.  
  89. }
  90.  
  91. void jugador::cambiar_edad(short nueva_edad)
  92. {
  93.  
  94.     edad=nueva_edad;
  95.  
  96. }
  97.  
  98. void jugador::cambiar_camiseta(short nueva_camiseta)
  99. {
  100.  
  101.     camiseta=nueva_camiseta;
  102.  
  103. }
  104.  
  105. void jugador::cambiar_todo(int nueva_ID, short nueva_SELECCION, short nueva_EDAD, short nueva_CAMISETA)
  106. {
  107.  
  108.     id=nueva_ID;
  109.     seleccion=nueva_SELECCION;
  110.     edad=nueva_EDAD;
  111.     camiseta=nueva_CAMISETA;
  112.  
  113. }
  114. void jugador::mostrar_jugador()
  115. {
  116.  
  117.     cout<<"ID\tSELECCION\tEDAD\tCAMISETA\n";
  118.     cout<<id<<"\t"<<seleccion<<"\t"<<edad<<"\t"<<camiseta<<"\t"<<endl;
  119.  
  120. }
  121.  
  122. void menu(short *AUX)
  123. {
  124.  
  125.     cout << "Que desea hacer?\n";
  126.     cout << "1. Ingresar un jugador\n";
  127.     cout << "2. Modificar un jugador\n";
  128.     cout << "3. Mostrar lista de jugadores\n";
  129.     cout << "4. Salir\n";
  130.     cin>>*AUX;
  131. }
  132.  
  133. int main()
  134. {
  135.     int id1;
  136.     short seleccion1, edad1, camiseta1;
  137.     jugador arreglo[5];
  138.     int n = 0, i;
  139.     char opcion = 's';
  140.     jugador *lista=NULL;
  141.    
  142.     while (opcion == 's')
  143.     {
  144.         lista = (jugador *)realloc(lista, (n+1)*sizeof(jugador));
  145.         cout<<"id: "<<endl;
  146.         cin>>id1;
  147.         cout<<"Seleccion: "<<endl;
  148.         cin>>seleccion1;
  149.         cout<<"Edad: "<<endl;
  150.         cin>>edad1;
  151.         cout<<"Camiseta: "<<endl;
  152.         cin>>camiseta1;
  153.  
  154.  
  155.         (*(lista+n))(id1,seleccion1,edad1,camiseta1);
  156.         n++;
  157.         cout << "Desea ingresar otro elemento? (s/n): ";
  158.         cin >> opcion;
  159.     }
  160.     cout << "\nArreglo completo\n";
  161.     for (i=0; i<n; i++)
  162.     {
  163.     (*(lista+n)).mostrar_jugador();
  164.     }
  165.  
  166.     return 0;
  167.  
  168. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement