Advertisement
ewelina_r

2014/B/3

Jun 23rd, 2015
231
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.95 KB | None | 0 0
  1. using namespace std;
  2.  
  3. class Towar {
  4.     string nazwa;
  5.     string kategoria;
  6.     double cena;
  7.     string kod;
  8.  
  9.     friend class LT;
  10. };
  11.  
  12. class LT {
  13.     list <Towar> lista;
  14.  
  15. public:
  16.     void dodaj (const Towar &t) {
  17.          list <Towar> :: iterator it = lista.begin();
  18.          for ( ; it != lista.end(); ++it) {
  19.             if (t.kod == (*it).kod) {
  20.                 (*it).nazwa = t.nazwa;
  21.                 (*it).kategoria = t.kategoria;
  22.                 (*it).cena = t.cena;
  23.                 return;
  24.             }
  25.         }
  26.         lista.push_back(t);
  27.     }  
  28.    
  29.     bool usun (const char* kod) {
  30.         list <Towar> :: iterator it = lista.begin();
  31.          for ( ; it != lista.end(); ++it) {
  32.             if (kod == (*it).kod) {
  33.                 erase(it);
  34.                 return true;
  35.             }
  36.         }
  37.         return false;
  38.     }
  39.  
  40.     void szukaj (const char* txt, list <Towar> &result) {
  41.         list <Towar> :: iterator it = lista.begin();
  42.         for ( ; it != lista.end(); ++it) {
  43.             if ((*it).nazwa.find(txt) != string::npos || (*it).kategoria.find(txt) != string::npos)
  44.                 result.push_back(*it);
  45.         }
  46.     }
  47. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement