Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cstring>
- using namespace std;
- //Vasiot kod tuka
- class Pica
- {
- private:
- char name[15];
- char *ing;
- int price, dis;
- public:
- Pica(const char *name="", const int price=0, const char *ing="", const int dis=0)
- {
- strcpy(this->name, name);
- this->price=price;
- this->ing=new char[strlen(ing)+1];
- strcpy(this->ing, ing);
- this->dis=dis;
- }
- Pica(const Pica &p)
- {
- strcpy(name, p.name);
- price=p.price;
- ing=new char[strlen(p.ing)+1];
- strcpy(ing, p.ing);
- dis=p.dis;
- }
- Pica &operator=(const Pica &p)
- {
- if(this!=&p)
- {
- strcpy(name, p.name);
- price=p.price;
- delete [] ing;
- ing=new char[strlen(p.ing)+1];
- strcpy(ing, p.ing);
- dis=p.dis;
- }
- return *this;
- }
- ~Pica()
- {
- delete [] ing;
- }
- void pecati()
- {
- cout<<name<<" - "<<ing<<", "<<price;
- }
- bool istiSe(Pica p)
- {
- return strcmp(ing, p.ing)==0;
- }
- const int getPrice()
- {
- return price;
- }
- const int getDis()
- {
- return dis;
- }
- };
- class Picerija
- {
- private:
- char name[15];
- Pica *pc;
- int countP;
- public:
- Picerija(const char *name)
- {
- strcpy(this->name, name);
- countP=0;
- }
- Picerija(const Picerija &p)
- {
- strcpy(name, p.name);
- countP=p.countP;
- pc=new Pica[countP];
- for(int i=0; i<countP; i++)
- {
- pc[i]=p.pc[i];
- }
- }
- Picerija &operator=(const Picerija &p)
- {
- if(this!=&p)
- {
- strcpy(name, p.name);
- countP=p.countP;
- delete [] pc;
- pc=new Pica[countP];
- for(int i=0; i<countP; i++)
- {
- pc[i]=p.pc[i];
- }
- }
- return *this;
- }
- ~Picerija()
- {
- delete [] pc;
- }
- void dodadi(Pica p)
- {
- bool notSame=true;
- for(int i=0; i<countP; i++)
- {
- if(pc[i].istiSe(p))
- {
- notSame=false;
- break;
- }
- }
- if(notSame)
- {
- Pica *tmp=new Pica[countP+1];
- for(int i=0; i<countP; i++)
- {
- tmp[i]=pc[i];
- }
- if(countP>0)
- delete [] pc;
- pc=tmp;
- pc[countP++]=p;
- }
- }
- void setIme(const char *name)
- {
- strcpy(this->name, name);
- }
- const char *getIme()
- {
- return name;
- }
- void piciNaPromocija()
- {
- for(int i=0; i<countP; i++)
- {
- if(pc[i].getDis())
- {
- pc[i].pecati();
- cout<<" "<<pc[i].getPrice()-(pc[i].getPrice()*pc[i].getDis())/100<<endl;
- }
- }
- }
- };
- int main ()
- {
- int n;
- char ime[15];
- cin >> ime;
- cin >> n;
- Picerija p1(ime);
- for(int i = 0; i < n; i++)
- {
- char imp[100];
- cin.get();
- cin.getline(imp,100);
- int cena;
- cin >> cena;
- char sostojki[100];
- cin.get();
- cin.getline(sostojki,100);
- int popust;
- cin >> popust;
- Pica p(imp,cena,sostojki,popust);
- p1.dodadi(p);
- }
- Picerija p2 = p1;
- cin >> ime;
- p2.setIme(ime);
- char imp[100];
- cin.get();
- cin.getline(imp,100);
- int cena;
- cin >> cena;
- char sostojki[100];
- cin.get();
- cin.getline(sostojki,100);
- int popust;
- cin >> popust;
- Pica p(imp,cena,sostojki,popust);
- p2.dodadi(p);
- cout<<p1.getIme()<<endl;
- cout<<"Pici na promocija:"<<endl;
- p1.piciNaPromocija();
- cout<<p2.getIme()<<endl;
- cout<<"Pici na promocija:"<<endl;
- p2.piciNaPromocija();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement