Advertisement
AnaGocevska

Untitled

Apr 7th, 2015
187
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 4.82 KB | None | 0 0
  1. #include <iostream>
  2. #include <cstring>
  3.  
  4. using namespace std;
  5.  
  6. class Pica
  7. {
  8.     private:
  9.    
  10.     char ime[15];
  11.     int cena;
  12.     char *sostojki;
  13.     int namaluvanje;
  14.    
  15.     public:
  16.    
  17.     Pica(char *ime="", int cena=0, char *sostojki="", int namaluvanje=0)
  18.     {
  19.         strcpy(this->ime, ime);
  20.         this->cena = cena;
  21.         this->sostojki = new char[strlen(sostojki)+1];
  22.         strcpy(this->sostojki, sostojki);
  23.         this->namaluvanje = namaluvanje;
  24.     }
  25.    
  26.     Pica(const Pica &p)
  27.     {
  28.         strcpy(this->ime, p.ime);
  29.         this->cena = p.cena;
  30.         this->sostojki = new char[strlen(p.sostojki)+1];
  31.         strcpy(this->sostojki, p.sostojki);
  32.         this->namaluvanje = p.namaluvanje;
  33.     }
  34.    
  35.     char *getSostojki()
  36.     {
  37.         return this->sostojki;
  38.     }
  39.    
  40.     char *getIme()
  41.     {
  42.         return this->ime;
  43.     }
  44.    
  45.     int getNamaluvanje()
  46.     {
  47.         return this->namaluvanje;
  48.     }
  49.    
  50.     void setIme(char *ime)
  51.     {
  52.         strcpy(this->ime, ime);
  53.     }
  54.    
  55.     int getCena()
  56.     {
  57.         return this->cena;
  58.     }
  59.    
  60.     void setCena(int cena)
  61.     {
  62.         this->cena=cena;
  63.     }
  64.    
  65.     ~Pica()
  66.     {
  67.         delete[]this->sostojki;
  68.     }
  69.    
  70.     void pecati()
  71.     {
  72.          cout<<ime<<" - "<<sostojki<<", "<<cena<<" "<<cena - (cena*namaluvanje)/100;
  73.     }
  74.    
  75.    
  76.    
  77.     bool istiSe(Pica p)
  78.     {
  79.         if(strcmp(this->sostojki, p.sostojki)==0)
  80.             return true;
  81.         return false;
  82.     }
  83.    
  84.     Pica &operator = (Pica &p)
  85.     {
  86.         if(this!=&p)
  87.         {
  88.         strcpy(this->ime, p.ime);
  89.         this->cena = p.cena;
  90.         delete[]this->sostojki;
  91.         this->sostojki = new char[strlen(p.sostojki)+1];
  92.         strcpy(this->sostojki, p.sostojki);
  93.        
  94.         }
  95.         return *this;
  96.     }
  97.    
  98. };
  99.  
  100. class Picerija
  101. {
  102.     private:
  103.    
  104.     char ime[15];
  105.     Pica *pici;
  106.     int brPici;
  107.    
  108.     public:
  109.    
  110.     Picerija(char *ime="", Pica *pici=0, int brPici=0)
  111.     {
  112.         strcpy(this->ime, ime);
  113.         this->brPici = brPici;
  114.         this->pici = new Pica[brPici];
  115.         for(int i=0; i<brPici; i++)
  116.         {
  117.             this->pici[i] = pici[i];
  118.         }
  119.        
  120.     }
  121.    
  122.     Picerija(const Picerija &p)
  123.     {
  124.         strcpy(this->ime, p.ime);
  125.         this->brPici = p.brPici;
  126.         this->pici = new Pica[p.brPici];
  127.         for(int i=0; i<p.brPici; i++)
  128.         {
  129.             this->pici[i] = p.pici[i];
  130.         }
  131.     }
  132.    
  133.     char *getIme()
  134.     {
  135.         return this->ime;
  136.     }
  137.    
  138.     void setIme(char *ime)
  139.     {
  140.         strcpy(this->ime, ime);
  141.     }
  142.    
  143.    
  144.     ~Picerija()
  145.     {
  146.         delete[]this->pici;
  147.     }
  148.    
  149.     bool proverka(Pica t)
  150.     {
  151.         for(int i=0; i<this->brPici; i++)
  152.         {
  153.             if(strcmp(pici[i].getSostojki(), t.getSostojki())==0)
  154.             {
  155.                 return false;
  156.             }
  157.         }
  158.         return true;
  159.     }
  160.    
  161.     void dodadi(Pica p)
  162.     {
  163.         Pica t=p;
  164.         if(proverka(t))
  165.         {
  166.    
  167.         Pica *tmp;
  168.         tmp = new Pica[this->brPici];
  169.         for(int i=0; i<this->brPici; i++)
  170.         {
  171.             tmp[i] =this->pici[i];
  172.         }
  173.         delete[]this->pici;
  174.         this->pici = new Pica[this->brPici+1];
  175.         for(int i=0; i<brPici+1; i++)
  176.         {
  177.             this->pici[i]=tmp[i];
  178.         }
  179.         delete[]tmp;
  180.         this->pici[this->brPici] = p;
  181.         this->brPici++;
  182.         }
  183.     }
  184.    
  185.     void piciNaPromocija()
  186.     {
  187.         for(int i=0; i<this->brPici; i++)
  188.         {
  189.             if(this->pici[i].getNamaluvanje()>0&&this->pici[i].getNamaluvanje()<100)
  190.             {
  191.                 this->pici[i].pecati();
  192.                
  193.                 //cout<<" ,"<<this->pici[i].getCena() - this->pici[i].getCena()*(this->pici[i].getNamaluvanje())/100;
  194.             }
  195.            
  196.         }
  197.     }
  198.            
  199. };
  200.  
  201. //Vasiot kod tuka
  202.  
  203. int main () {
  204.  
  205.     int n;
  206.     char ime[15];
  207.     cin >> ime;
  208.     cin >> n;
  209.  
  210.     Picerija p1(ime);
  211.     for(int i = 0; i < n; i++){
  212.         char imp[100];
  213.         cin.get();
  214.         cin.getline(imp,100);
  215.         int cena;
  216.         cin >> cena;
  217.         char sostojki[100];
  218.         cin.get();
  219.         cin.getline(sostojki,100);
  220.         int popust;
  221.         cin >> popust;
  222.         Pica p(imp,cena,sostojki,popust);
  223.         p1.dodadi(p);
  224.     }
  225.  
  226.     Picerija p2 = p1;
  227.     cin >> ime;
  228.     p2.setIme(ime);
  229.     char imp[100];
  230.     cin.get();
  231.     cin.getline(imp,100);
  232.     int cena;
  233.     cin >> cena;
  234.     char sostojki[100];
  235.     cin.get();
  236.     cin.getline(sostojki,100);
  237.     int popust;
  238.     cin >> popust;
  239.     Pica p(imp,cena,sostojki,popust);
  240.     p2.dodadi(p);
  241.  
  242.     cout<<p1.getIme()<<endl;
  243.     cout<<"Pici na promocija:"<<endl;
  244.     p1.piciNaPromocija();
  245.  
  246.     cout<<p2.getIme()<<endl;
  247.     cout<<"Pici na promocija:"<<endl;
  248.     p2.piciNaPromocija();
  249.  
  250.     return 0;
  251. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement