Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- #include<stdio.h>
- #include<stdlib.h>
- #include<list>
- #include<iterator>
- #include<string>
- #define _CRT_SECURE_NO_WARNING
- using namespace std;
- class masa {
- protected:
- int nr;
- public:
- masa(int nr) {
- this->nr = nr;
- }
- int get_nr() { return nr; }
- virtual void afisare() {
- cout << "Numarul mesei: " << nr << endl;
- }
- virtual int get_pret() = 0;
- };
- class pizza : public masa {
- protected:
- int pret;
- string nume;
- public:
- pizza(int nr, string nume, int pret) : masa(nr) {
- this->pret = pret;
- this->nume = nume;
- }
- void afisare() {
- masa::afisare();
- cout << "Tip comanda: Pizza" << endl;
- cout << " Numele pizzei: " << nume << endl;
- cout << "Pretul pizzei: " << pret << " ron" << endl;
- }
- string get_nume() { return nume; }
- int get_pret() { return pret; }
- };
- class paste :public masa {
- protected: int pret;
- string nume;
- public:
- paste(int nr, string nume, int pret) : masa(nr) {
- this->pret = pret;
- this->nume = nume;
- }
- void afisare() {
- masa::afisare();
- cout << "Tip comanda: Paste" << endl;
- cout << " Numele pastelor: " << nume << endl;
- cout << "Pretul pastelor: " << pret << " ron" << endl;
- }
- string get_nume() { return nume; }
- int get_pret() { return pret; }
- int get_nr() { return nr; }
- };
- class drink : public masa
- {
- protected: string brand, aroma; int pret;
- public:
- drink(int nr, string brand, string aroma, int pret) : masa(nr) {
- this->pret = pret;
- this->brand = brand;
- this->aroma = aroma;
- }
- void afisare() {
- masa::afisare();
- cout << "Tip comanda: Bautura" << endl;
- cout << " Brandul bauturii: " << brand << endl;
- cout << " Aroma bauturii: " << aroma << endl;
- cout << "Pretul bauturii: " << pret << " ron" << endl;
- }
- string get_brand() { return brand; }
- int get_pret() { return pret; }
- };
- list <masa*> l;
- list <masa*>::iterator it;
- void read()
- {
- int nr, pret, comanda;
- string nume, brand, aroma;
- cout << "Introduceti numarul mesei: ";
- cin >> nr;
- cout << "Ce doriti sa comandati? [1=Pizza; 2=Paste; 3=Bautura] : ";
- cin >> comanda;
- if (comanda == 1) {
- cout << "Nume pizza: "; cin >> nume;
- cout << "Pretul pentru pizza: ";
- cin >> pret;
- if (l.empty())
- l.push_back(new pizza(nr, nume, pret));
- else {
- it = l.begin();
- while (it != l.end() && (*it)->get_nr() < nr)
- advance(it, 1);
- l.emplace(it, new pizza(nr, nume, pret));
- }
- }
- else if (comanda == 2) {
- cout << "Nume paste: ";
- cin >> nume;
- cout << "Pretul pentru paste: ";
- cin >> pret;
- if (l.empty())
- l.push_back(new paste(nr, nume, pret));
- else {
- it = l.begin();
- while (it != l.end() && (*it)->get_nr() < nr)
- advance(it, 1);
- l.emplace(it, new paste(nr, nume, pret));
- }
- }
- else if (comanda == 3) {
- cout << "Brandul bauturii: ";
- cin >> brand;
- cout << "Aroma bauturii: ";
- cin >> aroma;
- cout << "Pretul pentru bautura: ";
- cin >> pret;
- if (l.empty())
- l.push_back(new drink(nr, brand, aroma, pret));
- else {
- it = l.begin();
- while (it != l.end() && (*it)->get_nr() < nr)
- advance(it, 1);
- l.emplace(it, new drink(nr, brand, aroma, pret));
- }
- }
- }
- void show() {
- cout << "=============================" << endl;
- for (it = l.begin(); it != l.end(); it++) {
- (*it)->afisare();
- cout << "----------------------------- \n";
- }
- cout << "=============================" << endl;
- }
- int main() {
- int opt;
- do {
- cout << "\n\n";
- cout << "1.Adaugare comanda \n";
- cout << "2.Afis comenzi \n";
- cout << "0.Iesire \n";
- cout << "Dati optiunea dvs: ";
- cin >> opt;
- switch (opt) {
- case 1:
- read();
- break;
- case 2:
- show();
- break;
- case 3:
- break;
- case 0:
- break;
- }
- } while (opt != 0);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement