Advertisement
Guest User

Untitled

a guest
Nov 17th, 2013
244
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.87 KB | None | 0 0
  1.         Iterator<Regate> it;
  2.         Liste<Regate> lreg;
  3.         ......
  4.         cout << "Choix: ";
  5.         scanf ("%d",&choix);
  6.         switch (choix)
  7.         {
  8.             case 1: Ajout(&lreg);
  9.             break;
  10.             case 2: Affich(lreg, it);
  11.         // ERREUR : JE NE PEUX PASSER QU UNE FOIS DS CASE 2 OU CASE 3.
  12.             break;
  13.             case 3: Sauvegarde (lreg, it);
  14.             break;
  15.             default : cout << "Vous devez faire un choix correcte ! 1 - 2 - 3." << endl;
  16.         }
  17.  
  18. void Ajout(Liste<Regate> *lreg)
  19. {
  20.     Regate r;
  21.     cout << "   Ajout d'une regate" << endl;
  22.     cin >> r;
  23.     lreg->add(r);
  24.     cout << "Verification d'ajout: ";
  25.         if(lreg->contains(r)) // Vérification d'ajout.
  26.         {
  27.                 cout << "SUCCESS" << endl;
  28.         }
  29.     else
  30.     {
  31.         cout << "FAILED" << endl;
  32.     }
  33. }
  34. void Affich(Liste<Regate> lreg, Iterator<Regate> it)
  35. {
  36.     cout << "affich";
  37.     Regate r;
  38.     it = lreg.getIterator();
  39.         while(it.hasNext())
  40.         {
  41.                 std::cout << it.next() << std::endl;
  42.         }
  43. }
  44.  
  45. void Sauvegarde (Liste<Regate> lreg, Iterator<Regate> it)
  46. {
  47.     cout << "save!";
  48.     fstream f;
  49.     Regate r;
  50.     it = lreg.getIterator();
  51.  
  52.     f.open("Regate.txt",ios::trunc|ios::out);
  53.         while(it.hasNext())
  54.     {
  55.         f << it.next();
  56.         i++;
  57.         }
  58.     f.close();
  59. }
  60.  
  61.  
  62.  
  63. // Iterator.h
  64. template <class E>
  65. class Iterator
  66. {
  67.     private:
  68.          Cellule<E>* curCell;
  69.  
  70.     public:
  71.         Iterator()
  72.         {
  73.             curCell = NULL;
  74.         }
  75.             Iterator(Cellule<E>* cell)
  76.             {
  77.                     curCell = cell;
  78.             }
  79.             ~Iterator()
  80.             {
  81.             };
  82.             bool hasNext()
  83.             {
  84.                     return curCell != NULL;
  85.             }
  86.             E next()
  87.             {
  88.                     E ret = curCell->data;
  89.                     curCell = curCell->next;
  90.                     return ret;
  91.             }
  92. };
  93.  
  94. // Dans liste.h :
  95.         Iterator<E> getIterator()
  96.     {
  97.                 Iterator<E> it(firstCell);
  98.                 return it;
  99.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement