Advertisement
frusso1337

picerija

Mar 19th, 2018
150
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.96 KB | None | 0 0
  1. #include <iostream>
  2. #include <cstring>
  3. using namespace std;
  4. //Vasiot kod tuka
  5. class Pica
  6. {
  7. private:
  8.     char name[15];
  9.     char *ing;
  10.     int price, dis;
  11. public:
  12.     Pica(const char *name="", const int price=0, const char *ing="", const int dis=0)
  13.     {
  14.         strcpy(this->name, name);
  15.         this->price=price;
  16.         this->ing=new char[strlen(ing)+1];
  17.         strcpy(this->ing, ing);
  18.         this->dis=dis;
  19.     }
  20.     Pica(const Pica &p)
  21.     {
  22.         strcpy(name, p.name);
  23.         price=p.price;
  24.         ing=new char[strlen(p.ing)+1];
  25.         strcpy(ing, p.ing);
  26.         dis=p.dis;
  27.     }
  28.     Pica &operator=(const Pica &p)
  29.     {
  30.         if(this!=&p)
  31.         {
  32.             strcpy(name, p.name);
  33.             price=p.price;
  34.             delete [] ing;
  35.             ing=new char[strlen(p.ing)+1];
  36.             strcpy(ing, p.ing);
  37.             dis=p.dis;
  38.         }
  39.         return *this;
  40.     }
  41.     ~Pica()
  42.     {
  43.         delete [] ing;
  44.     }
  45.     void pecati()
  46.     {
  47.         cout<<name<<" - "<<ing<<", "<<price;
  48.     }
  49.     bool istiSe(Pica p)
  50.     {
  51.         return strcmp(ing, p.ing)==0;
  52.     }
  53.     const int getPrice()
  54.     {
  55.         return price;
  56.     }
  57.     const int getDis()
  58.     {
  59.         return dis;
  60.     }
  61. };
  62. class Picerija
  63. {
  64. private:
  65.     char name[15];
  66.     Pica *pc;
  67.     int countP;
  68. public:
  69.     Picerija(const char *name)
  70.     {
  71.         strcpy(this->name, name);
  72.         countP=0;
  73.     }
  74.     Picerija(const Picerija &p)
  75.     {
  76.         strcpy(name, p.name);
  77.         countP=p.countP;
  78.         pc=new Pica[countP];
  79.         for(int i=0; i<countP; i++)
  80.         {
  81.             pc[i]=p.pc[i];
  82.         }
  83.     }
  84.     Picerija &operator=(const Picerija &p)
  85.     {
  86.         if(this!=&p)
  87.         {
  88.             strcpy(name, p.name);
  89.             countP=p.countP;
  90.             delete [] pc;
  91.             pc=new Pica[countP];
  92.             for(int i=0; i<countP; i++)
  93.             {
  94.                 pc[i]=p.pc[i];
  95.             }
  96.         }
  97.         return *this;
  98.     }
  99.     ~Picerija()
  100.     {
  101.         delete [] pc;
  102.     }
  103.     void dodadi(Pica p)
  104.     {
  105.         bool notSame=true;
  106.         for(int i=0; i<countP; i++)
  107.         {
  108.             if(pc[i].istiSe(p))
  109.             {
  110.                 notSame=false;
  111.                 break;
  112.             }
  113.         }
  114.         if(notSame)
  115.         {
  116.             Pica *tmp=new Pica[countP+1];
  117.             for(int i=0; i<countP; i++)
  118.             {
  119.                 tmp[i]=pc[i];
  120.             }
  121.             if(countP>0)
  122.                 delete [] pc;
  123.             pc=tmp;
  124.             pc[countP++]=p;
  125.         }
  126.     }
  127.     void setIme(const char *name)
  128.     {
  129.         strcpy(this->name, name);
  130.     }
  131.     const char *getIme()
  132.     {
  133.         return name;
  134.     }
  135.     void piciNaPromocija()
  136.     {
  137.         for(int i=0; i<countP; i++)
  138.         {
  139.             if(pc[i].getDis())
  140.             {
  141.                 pc[i].pecati();
  142.                 cout<<" "<<pc[i].getPrice()-(pc[i].getPrice()*pc[i].getDis())/100<<endl;
  143.             }
  144.         }
  145.     }
  146. };
  147. int main ()
  148. {
  149.     int n;
  150.     char ime[15];
  151.     cin >> ime;
  152.     cin >> n;
  153.     Picerija p1(ime);
  154.     for(int i = 0; i < n; i++)
  155.     {
  156.         char imp[100];
  157.         cin.get();
  158.         cin.getline(imp,100);
  159.         int cena;
  160.         cin >> cena;
  161.         char sostojki[100];
  162.         cin.get();
  163.         cin.getline(sostojki,100);
  164.         int popust;
  165.         cin >> popust;
  166.         Pica p(imp,cena,sostojki,popust);
  167.         p1.dodadi(p);
  168.     }
  169.     Picerija p2 = p1;
  170.     cin >> ime;
  171.     p2.setIme(ime);
  172.     char imp[100];
  173.     cin.get();
  174.     cin.getline(imp,100);
  175.     int cena;
  176.     cin >> cena;
  177.     char sostojki[100];
  178.     cin.get();
  179.     cin.getline(sostojki,100);
  180.     int popust;
  181.     cin >> popust;
  182.     Pica p(imp,cena,sostojki,popust);
  183.     p2.dodadi(p);
  184.     cout<<p1.getIme()<<endl;
  185.     cout<<"Pici na promocija:"<<endl;
  186.     p1.piciNaPromocija();
  187.     cout<<p2.getIme()<<endl;
  188.     cout<<"Pici na promocija:"<<endl;
  189.     p2.piciNaPromocija();
  190.     return 0;
  191. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement