ivana_andreevska

Zadaca 5

Jun 20th, 2021
234
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.91 KB | None | 0 0
  1. #include <iostream>
  2. #include <cstring>
  3. #include <ctype.h>
  4. #include <string.h>
  5. #include <math.h>
  6. using namespace std;
  7.  
  8. enum Kupuvac{standardni,lojlani,vip};
  9.  
  10. class UserExistsException
  11. {
  12. public:
  13.     void message()
  14.     {
  15.         cout<<"The user already exists in the list!"<<endl;
  16.     }
  17. };
  18.  
  19. class Customer
  20. {
  21. protected:
  22.     char ime[51];
  23.     char adresa[51];
  24.     Kupuvac tip;
  25.     static int osnovenPopust;
  26.     static const int dopolnitelenPopust=20;
  27.     int kupeniProizvodi;
  28. public:
  29.     Customer(char *ime="" , char *adresa="", Kupuvac tip=standardni , int kupeniProizvodi=0)
  30.     {
  31.         strcpy(this->ime,ime);
  32.         strcpy(this->adresa,adresa);
  33.         this->tip=(Kupuvac)tip;
  34.         this->kupeniProizvodi=kupeniProizvodi;
  35.     }
  36.  
  37.     static void setPopust(int popust2)
  38.     {
  39.         osnovenPopust=popust2;
  40.     }
  41.  
  42.     friend ostream &operator<<(ostream &out , Customer &c)
  43.     {
  44.         out<<c.ime<<endl;
  45.         out<<c.adresa<<endl;
  46.         out<<c.kupeniProizvodi<<endl;
  47.  
  48.         if(c.tip==0)
  49.         {
  50.             out<<"standard 0"<<endl;
  51.         }
  52.         if(c.tip==1)
  53.         {
  54.             out<<"loyal "<<c.osnovenPopust<<endl;
  55.         }
  56.         if(c.tip==2)
  57.         {
  58.             out<<"vip "<<c.dopolnitelenPopust + c.osnovenPopust<<endl;
  59.         }
  60.  
  61.         return out;
  62.     }
  63.  
  64.         bool operator==(const Customer &c)
  65.         {
  66.             return strcmp(adresa,c.adresa);
  67.         }
  68.  
  69.         int getKupeni()
  70.         {
  71.             return kupeniProizvodi;
  72.         }
  73.  
  74.         int typeKupuvac()
  75.         {
  76.             return tip;
  77.         }
  78.  
  79.         void setKupuvac(Kupuvac k2)
  80.         {
  81.             tip=(Kupuvac)k2;
  82.         }
  83. };
  84.  
  85. int Customer::osnovenPopust=10;
  86.  
  87. class FINKI_bookstore
  88. {
  89. private:
  90.     Customer *kupuvaci;
  91.     int brojKupuvaci;
  92. public:
  93.     FINKI_bookstore()
  94.     {
  95.         kupuvaci=new Customer[0];
  96.         brojKupuvaci=0;
  97.     }
  98.     FINKI_bookstore(const FINKI_bookstore &fb)
  99.     {
  100.         kupuvaci=new Customer[fb.brojKupuvaci+1];
  101.         for(int i=0;i<fb.brojKupuvaci;i++)
  102.         {
  103.             kupuvaci[i]=fb.kupuvaci[i];
  104.         }
  105.         brojKupuvaci=fb.brojKupuvaci;
  106.     }
  107.     FINKI_bookstore &operator=(const FINKI_bookstore &fb)
  108.     {
  109.         if(this!=&fb)
  110.         {
  111.         delete[]kupuvaci;
  112.         kupuvaci=new Customer[fb.brojKupuvaci+1];
  113.         for(int i=0;i<fb.brojKupuvaci;i++)
  114.         {
  115.             kupuvaci[i]=fb.kupuvaci[i];
  116.         }
  117.         brojKupuvaci=fb.brojKupuvaci;
  118.         }
  119.         return *this;
  120.     }
  121.     ~FINKI_bookstore()
  122.     {
  123.         delete[]kupuvaci;
  124.     }
  125.  
  126.     FINKI_bookstore &operator+=(const Customer &c)
  127.     {
  128.         for(int i=0;i<brojKupuvaci;i++)
  129.         {
  130.             if((kupuvaci[i]==c)==0)
  131.             {
  132.                 throw UserExistsException();
  133.             }
  134.         }
  135.  
  136.         Customer *temp=new Customer[brojKupuvaci+1];
  137.         for(int i=0;i<brojKupuvaci;i++)
  138.         {
  139.             temp[i]=kupuvaci[i];
  140.         }
  141.         temp[brojKupuvaci++]=c;
  142.         delete[]kupuvaci;
  143.         kupuvaci=temp;
  144.         return *this;
  145.     }
  146.  
  147.     void setCustomers(Customer *niza , int n)
  148.     {
  149.         delete[]kupuvaci;
  150.         kupuvaci=new Customer[n];
  151.         for(int i=0;i<n;i++)
  152.         {
  153.             kupuvaci[i]=niza[i];
  154.         }
  155.         brojKupuvaci=n;
  156.     }
  157.  
  158.     void update()
  159.     {
  160.         for(int i=0;i<brojKupuvaci;i++)
  161.         {
  162.             if(kupuvaci[i].typeKupuvac()==0 && kupuvaci[i].getKupeni()>5)
  163.             {
  164.                 kupuvaci[i].setKupuvac(Kupuvac(1));
  165.             }
  166.             else if(kupuvaci[i].typeKupuvac()==1 && kupuvaci[i].getKupeni()>10)
  167.             {
  168.                 kupuvaci[i].setKupuvac(Kupuvac(2));
  169.             }
  170.         }
  171.     }
  172.  
  173.  
  174.     friend ostream &operator<<(ostream &out, const FINKI_bookstore &fe)
  175.     {
  176.         for(int i=0;i<fe.brojKupuvaci;i++)
  177.         {
  178.             out<<fe.kupuvaci[i];
  179.         }
  180.         return out;
  181.     }
  182.  
  183. };
  184.  
Advertisement
Add Comment
Please, Sign In to add comment