Advertisement
cardel

Ejemplo mapas IPOO 22 Marzo

Mar 22nd, 2017
269
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.39 KB | None | 0 0
  1. /*
  2. * Autor: Carlos Andres Delgado
  3. * Descripción: Ejemplo mapas
  4. * Fecha: 22 de Marzo (Recuerden proxima seman parcial)
  5. */
  6.  
  7. #include <iostream>
  8. #include <string>
  9. #include <map>
  10.  
  11. using namespace std;
  12.  
  13. int main(){
  14.     map<int,string> datosPersonas;
  15.  
  16.     int numPersonas = 0;
  17.     cout << "Ingrese el número de personas"<<endl;
  18.     cin >> numPersonas;
  19.  
  20.     for(int i=0; i<numPersonas; i++){
  21.         string nombre;
  22.         int cedula;
  23.  
  24.         cout << "Ingrese la cédula de la persona "<<i<<endl;
  25.         cin >> cedula;
  26.         cout << "Ingrese el nombre de la persona "<<i<<endl;
  27.         cin >> nombre;
  28.  
  29.         datosPersonas[cedula] = nombre;
  30.     }
  31.  
  32.     for(map<int,string>::iterator it = datosPersonas.begin(); it!=datosPersonas.end(); it++){
  33.         cout << it->first << " : " << it->second << endl;
  34.     }
  35.  
  36.     map<string,double> datos;
  37.    
  38.     int numDatos = 0;
  39.     cout << "Ingrese el número de datos\n";
  40.  
  41.     cin >> numDatos;
  42.  
  43.     for(int i = 0; i<numDatos; i++){
  44.         string codigo;
  45.         double dato;
  46.  
  47.         cout << "Ingrese el código alfanumérico del dato "<<i<<endl;
  48.         cin >> codigo;
  49.         cout << "Ingrese el dato (double)"<<i<<endl;
  50.         cin >> dato;
  51.  
  52.         datos[codigo] = dato;
  53.     }
  54.     for(map<string,double>::iterator it = datos.begin(); it!=datos.end(); it++){
  55.         cout << it->first << " : " << it->second << endl;
  56.     }
  57. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement