Advertisement
AnaGocevska

Untitled

Apr 7th, 2015
230
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 4.45 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<<this->ime<<" - ";
  73.         cout<<this->sostojki<<", ";
  74.         cout<<this->cena<<", ";
  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.         strcpy(this->ime, p.ime);
  87.         this->cena = p.cena;
  88.         delete[]this->sostojki;
  89.         this->sostojki = new char[strlen(p.sostojki)+1];
  90.         strcpy(this->sostojki, p.sostojki);
  91.        
  92.         return *this;
  93.     }
  94.    
  95. };
  96.  
  97. class Picerija
  98. {
  99.     private:
  100.    
  101.     char ime[15];
  102.     Pica *pici;
  103.     int brPici;
  104.    
  105.     public:
  106.    
  107.     Picerija(char *ime="", Pica *pici=0, int brPici=0)
  108.     {
  109.         strcpy(this->ime, ime);
  110.         this->brPici = brPici;
  111.         this->pici = new Pica[brPici];
  112.         for(int i=0; i<brPici; i++)
  113.         {
  114.             this->pici[i] = pici[i];
  115.         }
  116.        
  117.     }
  118.    
  119.     Picerija(const Picerija &p)
  120.     {
  121.         strcpy(this->ime, p.ime);
  122.         this->brPici = p.brPici;
  123.         this->pici = new Pica[brPici];
  124.         for(int i=0; i<brPici; i++)
  125.         {
  126.             this->pici[i] = p.pici[i];
  127.         }
  128.     }
  129.    
  130.     char *getIme()
  131.     {
  132.         return this->ime;
  133.     }
  134.    
  135.     void setIme(char *ime)
  136.     {
  137.         strcpy(this->ime, ime);
  138.     }
  139.    
  140.    
  141.     ~Picerija()
  142.     {
  143.         delete[]this->pici;
  144.     }
  145.    
  146.     void dodadi(Pica p)
  147.     {
  148.         Pica *tmp;
  149.         tmp = new Pica[this->brPici+1];
  150.         for(int i=0; i<this->brPici; i++)
  151.         {
  152.             tmp[i] = pici[i];
  153.         }
  154.         delete[]this->pici;
  155.         this->pici = new Pica[this->brPici+1];
  156.         for(int i=0; i<brPici; i++)
  157.         {
  158.             this->pici[i]=tmp[i];
  159.         }
  160.         delete[]tmp;
  161.         this->pici[this->brPici] = p;
  162.         this->brPici++;
  163.     }
  164.    
  165.     void piciNaPromocija()
  166.     {
  167.         for(int i=0; i<brPici; i++)
  168.         {
  169.             if(this->pici[i].getNamaluvanje()>0&&this->pici[i].getNamaluvanje()<100)
  170.             {
  171.                 this->pici[i].pecati();
  172.                
  173.                 cout<<" ,"<<this->pici[i].getCena() - this->pici[i].getCena()*(this->pici[i].getNamaluvanje())/100;
  174.             }
  175.            
  176.         }
  177.     }
  178.            
  179. };
  180.  
  181. //Vasiot kod tuka
  182.  
  183. int main () {
  184.  
  185.     int n;
  186.     char ime[15];
  187.     cin >> ime;
  188.     cin >> n;
  189.  
  190.     Picerija p1(ime);
  191.     for(int i = 0; i < n; i++){
  192.         char imp[100];
  193.         cin.get();
  194.         cin.getline(imp,100);
  195.         int cena;
  196.         cin >> cena;
  197.         char sostojki[100];
  198.         cin.get();
  199.         cin.getline(sostojki,100);
  200.         int popust;
  201.         cin >> popust;
  202.         Pica p(imp,cena,sostojki,popust);
  203.         p1.dodadi(p);
  204.     }
  205.  
  206.     Picerija p2 = p1;
  207.     cin >> ime;
  208.     p2.setIme(ime);
  209.     char imp[100];
  210.     cin.get();
  211.     cin.getline(imp,100);
  212.     int cena;
  213.     cin >> cena;
  214.     char sostojki[100];
  215.     cin.get();
  216.     cin.getline(sostojki,100);
  217.     int popust;
  218.     cin >> popust;
  219.     Pica p(imp,cena,sostojki,popust);
  220.     p2.dodadi(p);
  221.  
  222.     cout<<p1.getIme()<<endl;
  223.     cout<<"Pici na promocija:"<<endl;
  224.     p1.piciNaPromocija();
  225.  
  226.     cout<<p2.getIme()<<endl;
  227.     cout<<"Pici na promocija:"<<endl;
  228.     p2.piciNaPromocija();
  229.  
  230.     return 0;
  231. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement