Advertisement
Guest User

Untitled

a guest
Nov 28th, 2014
153
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.36 KB | None | 0 0
  1. #include<iostream>
  2. #include<map>
  3. #include<string>
  4. #include<conio.h>
  5. #include<cstring>
  6. using namespace std ;
  7. class event  
  8. {
  9.     private :
  10.     map <int,string> e ;
  11.     public :
  12.                 void add_event()
  13.                 {
  14.                         string ch ;
  15.                         int a , test= 0;                      
  16.                         cout<<"Donner l'annee de l'evenement : " ;
  17.                         cin>>a ;
  18.                         cout<<"Donner l'evenement : " ;
  19.                         cin>>ch;
  20.                         for (std::map<int,string>::iterator it=e.begin(); it!=e.end(); ++it)
  21.                 if(it->first==a)
  22.                         {  
  23.                                 it->second = it->second + ch + "#" ;
  24.                                 test = 1;
  25.                         }
  26.                        
  27.                         if(test == 0)
  28.             {
  29.                     e.insert(map<int,string>::value_type(a,ch+"#"));
  30.             }
  31.                 }
  32.                 void afficher ()
  33.                 {
  34.                         for (std::map<int,string>::iterator it=e.begin(); it!=e.end(); ++it)
  35.                                 std::cout << it->first << " : " << it->second << '\n';    
  36.                 }
  37.                 void find_event_by_date(int x)
  38.                 {
  39.                         if(e.empty())
  40.                                 cout<<"Empty map \n" ;
  41.                         else
  42.                         {
  43.                  for (std::map<int,string>::iterator it=e.begin(); it!=e.end(); ++it)
  44.                      if(it->first==x)
  45.                                         {  
  46.                             string subevent ="";
  47.                             for(int i = 0; i < (it->second).length(); i++)
  48.                             {
  49.                                 if(it->second.at(i) != '#')
  50.                                 {
  51.                                     subevent = subevent + it->second.at(i);
  52.                                 }
  53.                                 else
  54.                                 {
  55.                                     cout<<x<<" : "<<subevent<<"\n" ;
  56.                                     subevent = "";
  57.                                 }
  58.                             }
  59.                                         }
  60.                         }
  61.                 }
  62.                 void modify_event(int x)
  63.                 {      
  64.                         string ch ;
  65.                         if(e.empty())
  66.                                 cout<<"Empty map \n" ;
  67.                         else
  68.                         {
  69.                  for (std::map<int,string>::iterator it=e.begin(); it!=e.end(); ++it)
  70.                      if(it->first==x)
  71.                                         {                  
  72.                                         cout<<"Donner l'evenement : " ;
  73.                                         cin>>it->second ;
  74.                                         }
  75.                         }
  76.     }
  77.  
  78. };
  79. main()
  80. {
  81.     event a ;
  82.     char x='o';
  83.     int annee;
  84.     while(x == 'o')
  85.     {
  86.         a.add_event() ;    
  87.         cout<<"Voulez vous ajouter un autre evenement ? (o/n)\n";
  88.         x = getch();
  89.     }
  90.     cout<<"La liste des evenemements :\n";
  91.     a.afficher();
  92.     a.find_event_by_date(2003);
  93.     cout<<"Donner l'annee a modifier : "; cin>>annee;
  94.     a.modify_event(annee);
  95.    
  96.      
  97. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement