Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cstring>
- using namespace std;
- class Pica
- {
- private:
- char ime[15];
- int cena;
- char *sostojki;
- int procent;
- public:
- Pica(char ime[]="",int cena=0,char *sostojki="",int procent=0)
- {
- strcpy(this->ime,ime);
- this->cena = cena;
- this->sostojki = new char [strlen(sostojki)+1];
- strcpy(this->sostojki,sostojki);
- this->procent = procent;
- }
- Pica(Pica &p)
- {
- strcpy(this->ime,p.ime);
- this->cena = p.cena;
- this->sostojki = new char [strlen(p.sostojki)+1];
- strcpy(this->sostojki,p.sostojki);
- this->procent = p.procent;
- }
- Pica& operator= (Pica &p)
- {
- if(this!=&p)
- {
- delete []this->sostojki;
- strcpy(this->ime,p.ime);
- this->cena = p.cena;
- this->sostojki = new char [strlen(p.sostojki)+1];
- strcpy(this->sostojki,p.sostojki);
- this->procent = p.procent;
- }
- return *this;
- }
- void pecati()
- {
- cout<<ime<<" - "<<sostojki<<", "<<cena<<" "<<cena - cena*procent/100<<endl;
- }
- bool istiSe(Pica &p)
- {
- return strcmp(this->sostojki, p.sostojki)==0;
- }
- int getPopust()
- {
- return procent;
- }
- ~Pica()
- {
- delete []sostojki;
- }
- };
- class Picerija
- {
- private:
- char ime[15];
- Pica *p;
- int brPici;
- public:
- Picerija(char ime[]="",Pica *p=NULL,int brPici=0)
- {
- strcpy(this->ime,ime);
- this->brPici = brPici;
- this->p = new Pica[brPici];
- for(int i=0;i<brPici;i++)
- {
- this->p[i] = p[i];
- }
- }
- Picerija(Picerija &pp)
- {
- strcpy(this->ime,pp.ime);
- this->brPici = pp.brPici;
- this->p = new Pica[pp.brPici];
- for(int i=0;i<brPici;i++)
- {
- this->p[i] = pp.p[i];
- }
- }
- Picerija& dodadi(Pica &nova)
- {
- bool najde=false;
- for(int i=0;i<brPici;i++)
- {
- if(p[i].istiSe(nova))
- {
- najde=true;
- break;
- }
- }
- if(najde==false)
- {
- Pica *temp;
- temp = new Pica[brPici + 1];
- for(int i=0;i<brPici;i++)
- {
- temp[i] = p[i];
- }
- temp[brPici] = nova;
- brPici++;
- delete []p;
- p = temp;
- }
- return *this;
- }
- void piciNaPromocija()
- {
- for(int i=0;i<brPici;i++)
- {
- if(p[i].getPopust()>0)
- {
- p[i].pecati();
- }
- }
- }
- void setIme(char ime[])
- {
- strcpy(this->ime,ime);
- }
- char* getIme()
- {
- return ime;
- }
- ~Picerija()
- {
- delete []p;
- }
- };
- 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