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 ime[15];
- int cena;
- char *sostojki;
- int namaluvanje;
- public:
- Pica(const char *ime="", int cena=0, const char *sostojki="", int namaluvanje=0){
- strcpy(this->ime, ime);
- this->cena = cena;
- this->sostojki = new char[strlen(sostojki)+1];
- strcpy(this->sostojki, sostojki);
- this->namaluvanje = namaluvanje;
- }
- ~Pica(){ }
- void pecati(){
- cout << this->ime << " - " << this->sostojki << " " << this->cena << "." << endl;
- }
- bool istiSe(Pica p){
- return strcmp(this->sostojki, p.sostojki)!=0;
- }
- char *getIme(){
- return this->ime;
- }
- int getCena(){
- return this->cena;
- }
- char *getSostojki(){
- return this->sostojki;
- }
- char getPopust(){
- return this->namaluvanje;
- }
- };
- class Picerija {
- private:
- char ime[15];
- Pica *pici;
- int brPici;
- public:
- Picerija(const char *ime=""){
- strcpy(this->ime, ime);
- brPici = 0;
- }
- Picerija &operator=(const Picerija &rhs){
- strcpy(this->ime, rhs.ime);
- this->brPici = rhs.brPici;
- this->pici = rhs.pici;
- return *this;
- }
- void dodadi(Pica rhs){
- Pica *temp = new Pica[brPici+1];
- for(int i=0; i<brPici; i++)
- if(pici[i].istiSe(rhs))
- temp[i] = pici[i];
- temp[brPici]=rhs;
- pici = temp;
- brPici++;
- }
- void piciNaPromocija(){
- for(int i=0; i<brPici; i++)
- if(this->pici[i].getPopust()>0)
- cout << pici[i].getIme() << " - " << pici[i].getSostojki() << ", " << pici[i].getCena() << " " <<
- (float)pici[i].getCena()-(pici[i].getCena()*(pici[i].getPopust()*0.01)) << endl;
- }
- char *setIme(const char *ime){
- return strcpy(this->ime, ime);
- }
- char *getIme(){
- return this->ime;
- }
- };
- 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