Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class App {
- public:
- Magazyn m;
- Koszyk k;
- bool akcja(string s)
- {
- if(s.find("koszyk") != string::npos)
- {
- this -> handle_koszyk(s);
- } else if(s.find("magazyn") != string::npos) {
- this -> handle_magazyn(s);
- } else if(s.find("produkt") != string::npos) {
- this -> handle_produkt(s);
- } else if(s.find("info") != string::npos) {
- this -> print_info();
- } else {
- cout << "Niepoprawna akcja: \"" << s << "\"" << endl;
- this -> print_info();
- }
- return true;
- }
- void print_info()
- {
- cout << "Dostepne akcje: " << endl;
- cout << "koszyk dodaj nr_prod <- dodaje produkt do koszyka" << endl;
- cout << "koszyk usun nr_prod <- usuwa produkt z koszyka" << endl;
- cout << "magazyn <- pokazuje magazyn" << endl;
- cout << "info <- pokazuje te informacje" << endl;
- }
- void handle_magazyn(string s)
- {
- this->m.listuj();
- }
- void handle_koszyk(string s)
- {
- if(s.find("dodaj") != string::npos)
- {
- int product_id = 0;
- int quantity = 0;
- int pos = (int)s.find("dodaj");
- if(s.length() > pos + 6)
- {
- product_id = strtoint(s.substr(pos+6));
- }
- if(!product_id)
- {
- cout << "Podaj numer produktu (0 - wraca do głównego menu): ";
- cin >> product_id;
- }
- Kontener *kontener;
- if(product_id < 1) {
- return;
- } else if(product_id > this->m.getKontenery()->size())
- {
- cout << "Nie ma produktu o takim numerze w magazynie." << endl;
- } else {
- kontener = this->m.getContainer(product_id);
- cout << "---- Wybrany produkt: ---- " << endl;
- kontener->towar->podsumuj();
- cout << "---- Dostepna liczba sztuk: " << kontener->getIlosc() << " ---- " << endl;
- }
- cout << "Podaj liczbe sztuk do zamowenia: ";
- cin >> quantity;
- // this->k->dodajTowar(kontener->towar, quantity);
- // kontener->decreaseQuantity(quantity);
- this->k += kontener->towar;
- cout << "Koszyk: pomyslnie dodano " << kontener->towar->getNazwa() << " w ilosci sztuk: " << quantity << endl;
- cout << "Pozostalo " << kontener->getIlosc() << " tego produktu. " << endl;
- cout << "Aby wyswietlic zawartosc koszyka, wpisz polecenie 'koszyk'. " << endl;
- } else if(s.find("usun") != string::npos) {
- int index;
- int pos = (int)s.find("usun");
- if(s.length() > pos + 4)
- {
- index = strtoint(s.substr(pos+4));
- }
- if(!index)
- {
- cout << "Ktory element chcesz usunac? Wprowdz: ";
- cin >> index;
- }
- Towar *t = this->k.getTowar(index);
- if(t != NULL)
- {
- Kontener *kontener = this->m.getContainer(t);
- if(kontener != NULL)
- {
- kontener->increaseQuantity(1);
- this->k.usunTowar(index);
- } else {
- cout << "BLAD: nie udalo sie odnalezc tego produktu w magazynie!" << endl;
- exit(0);
- }
- } else {
- cout << "Nie ma towaru o takim indeksie w koszyku." << endl;
- }
- cout << k;
- } else {
- cout << k;
- }
- }
- void handle_produkt(string s)
- {
- int product_id = 0;
- int pos = (int)s.find("produkt");
- if(s.length() > pos + 7)
- {
- product_id = strtoint(s.substr(pos+7));
- }
- if(!product_id)
- {
- cout << "Podaj numer produktu do wyswietlenia szczegolow (1-" << this->m.getKontenery()->size() << "): ";
- cin >> product_id;
- }
- if(this->m.containerExists(product_id))
- {
- this->m.getContainer(product_id)->towar->podsumuj();
- } else {
- cout << "Nie ma produktu z takim indeksem w magazynie." << endl;
- }
- }
- };
- int main(int argc, const char * argv[]) {
- App app;
- app.m = createMagazyn();
- bool working = true;
- while(working)
- {
- cout << "Wykonaj akcje: ";
- string action = "";
- getline(cin, action);
- if(action.length())
- {
- working = app.akcja(action);
- }
- }
- cout << "Dziekujemy za zakupy." << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement