Advertisement
Mastercpp

Registro ,usando vector.

Jun 30th, 2016
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.59 KB | None | 0 0
  1. #include <iostream>
  2. #include <cstdlib>
  3. #include <algorithm>
  4. #include <deque>
  5. #include <vector>
  6.  
  7. using namespace std;
  8.  
  9. class Motocicleta{
  10.  
  11.     private:
  12.         string marca;
  13.         string placa;
  14.         int modelo;
  15.         string color;
  16.         string tipo_de_moto;
  17.     public:
  18.         Motocicleta(string marca,string placa,int modelo,string color,string tipo_de_moto){
  19.            this->marca = marca;
  20.            this->placa = placa;
  21.            this->modelo=modelo;
  22.            this->color = color;
  23.            this->tipo_de_moto = tipo_de_moto;
  24.         }
  25.  
  26.         void setmarca(string m){
  27.             marca = m;
  28.         }
  29.  
  30.         void setplaca(string p){
  31.             placa = p;
  32.         }
  33.  
  34.         void setcolor(string c){
  35.             color = c;
  36.         }
  37.  
  38.         void settipodemoto(string tm){
  39.             tipo_de_moto = tm;
  40.         }
  41.  
  42.         void setmodelo(int md){
  43.             modelo = md;
  44.         }
  45.  
  46.         string getmarca (){
  47.             return marca;
  48.         }
  49.  
  50.         string getplaca (){
  51.             return placa;
  52.         }
  53.  
  54.         string getcolor (){
  55.             return color;
  56.         }
  57.  
  58.         string gettipodemoto (){
  59.             return tipo_de_moto;
  60.         }
  61.  
  62.         int getmodelo (){
  63.             return modelo;
  64.         }
  65. };
  66.  
  67. int main(){
  68.     string marca,placa;
  69.     int modelo;
  70.     string color,tipo_de_moto;
  71.     int op;
  72.     vector <Motocicleta>moto;
  73.     int aux; //para eliminar los elementos
  74.     bool existe=false;
  75.     do{
  76.         cout<<"BIENVENIDOS A LA EMPRESA DE MOTOCICLETAS "<<endl;
  77.         cout << "1. agregar"<<endl;
  78.         cout << "2. ver todos"<<endl;
  79.         //cout << "3. consultar" <<endl;
  80.         cout << "4. eliminar " <<endl;
  81.     //  cout << "5. editar" << endl;
  82.         cout << "6. salir..."<<endl;
  83.         cout << "ingrese una opcion :"<<endl;
  84.         cin >> op;
  85.         vector <Motocicleta>::iterator it =moto.begin();
  86.         system ("CLS");
  87.         switch (op){
  88.             case 1:
  89.  
  90.                 //Motocicleta(string marca,string placa,int modelo,string color,string tipo_de_moto)
  91.                 cout << "Marca"<<endl;
  92.                 cin>>marca;
  93.                 cout<<"Placa"<<endl;
  94.                 cin>>placa;
  95.  
  96.                 cout<<"Modelo"<<endl;
  97.                 cin>>modelo;
  98.                 cout<<"Color "<<endl;
  99.                 cin>>color;
  100.                 cout<<"tipo de moto"<<endl;
  101.                 cin>>tipo_de_moto;
  102.                 moto.push_back(Motocicleta(marca,placa,modelo,color,tipo_de_moto));
  103.                 system ("PAUSE");
  104.                 system ("CLS");
  105.                 break;
  106.  
  107.             case 2:
  108.                 for(int i=0; i<moto.size(); i++){
  109.                     cout << " MARCA"<<"\t";
  110.                     cout <<"PLACA" <<"\t";
  111.                     cout<<"COLOR"<<"\t";
  112.                     cout<<"TIPO DE MOTO"<<"\t";//string marca,string placa,int modelo,string color,string tipo_de_moto
  113.                     cout<<"MODELO"<<"\n";
  114.                     cout << moto[i].getmarca () <<"\t";
  115.                     cout<< moto[i].getplaca () <<"\t";
  116.                     cout<< moto[i].getcolor () <<"\t";
  117.                     cout<< moto[i].gettipodemoto () <<"\t \t";
  118.                     cout<< moto[i].getmodelo () <<"\t \t";
  119.                     cout << endl;
  120.                 }
  121.                 system ("PAUSE");
  122.                 system ("CLS");
  123.                 break;
  124.  
  125.             case 3:
  126.                 cout << "ingrese placa";
  127.                 //cin >> p;
  128.                 //cl.consultar(p);
  129.                 system ("PAUSE");
  130.                 system ("CLS");
  131.                 break;
  132.  
  133.             case 4:
  134.                 cout << "ingrese placa ";
  135.                 cin>>placa;
  136.                 cout << "Espere.....";
  137.                 for(int i=0; i<moto.size(); i++){
  138.                     if(placa == moto[i].getplaca()){
  139.                         aux = i;
  140.                         existe=true;
  141.                     }
  142.                 }
  143.                 if(existe){
  144.                     moto.erase(moto.begin()+aux);
  145.                 }
  146.  
  147.                 system ("PAUSE");
  148.                 system ("CLS");
  149.                 break;
  150.  
  151.         }
  152.     }while(op!=6);
  153.  
  154.  
  155.     return 0;
  156. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement