Mastercpp

Registro ,usando vector2.

Jun 30th, 2016
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.35 KB | None | 0 0
  1. #include <vector>
  2. #include <iostream>
  3. #include <string>
  4. using namespace std;
  5.  
  6. int ID=0;
  7.  
  8. class Estudiante{
  9. private:
  10.     string nombre;
  11.     int edad;
  12.     int id;
  13. public:
  14.     Estudiante(string nombre,int edad){
  15.         this->nombre = nombre;
  16.         this->edad = edad;
  17.         ID++;
  18.         this->id = ID;
  19.     }
  20.     int getEdad(){
  21.         return edad;
  22.     }
  23.  
  24.     string getNombre(){
  25.         return nombre;
  26.     }
  27.  
  28.     int getId(){
  29.         return id;
  30.     }
  31. };
  32.  
  33.  
  34. class Registro{
  35. private:
  36.     vector <Estudiante> estudiantes;
  37. public:
  38.     void agregar(Estudiante a){
  39.         estudiantes.push_back(a);
  40.     }
  41.     void verRegistros(){
  42.         cout << "Nombre\t\tEdad\t\tID" << endl;
  43.         for(int i=0; i<estudiantes.size(); i++){
  44.             cout << estudiantes[i].getNombre() << "\t\t" << estudiantes[i].getEdad() <<"\t\t" << estudiantes[i].getId() << endl;
  45.         }
  46.     }
  47.     bool Eliminar(int i){
  48.         if(i !=1)i-=1;
  49.         else i+=1;
  50.         for(int x=0; x<estudiantes.size(); x++){
  51.             if(i == estudiantes[x].getId()){
  52.                 estudiantes.erase(estudiantes.begin()+i);
  53.                 return true;
  54.             }
  55.         }
  56.         return false;
  57.     }
  58.  
  59.  
  60. };
  61.  
  62.  
  63.  
  64. int main(){
  65.  
  66.     Registro r;
  67.  
  68.     r.agregar(Estudiante("tito",17));
  69.     r.agregar(Estudiante("flower",58));
  70.     r.agregar(Estudiante("call",20));
  71.     r.agregar(Estudiante("perr",18));
  72.     r.agregar(Estudiante("lol",45));
  73.     r.agregar(Estudiante("fuck",458));
  74.     r.verRegistros();
  75.     cout << "\n\n" << endl;
  76.     r.Eliminar(2);
  77.     r.verRegistros();
  78.  
  79.     return 0;
  80. }
Add Comment
Please, Sign In to add comment