Advertisement
mbojmaliev

Пицерија

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