Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cstring>
- #include <ctype.h>
- #include <string.h>
- #include <math.h>
- using namespace std;
- enum Kupuvac{standardni,lojlani,vip};
- class UserExistsException
- {
- public:
- void message()
- {
- cout<<"The user already exists in the list!"<<endl;
- }
- };
- class Customer
- {
- protected:
- char ime[51];
- char adresa[51];
- Kupuvac tip;
- static int osnovenPopust;
- static const int dopolnitelenPopust=20;
- int kupeniProizvodi;
- public:
- Customer(char *ime="" , char *adresa="", Kupuvac tip=standardni , int kupeniProizvodi=0)
- {
- strcpy(this->ime,ime);
- strcpy(this->adresa,adresa);
- this->tip=(Kupuvac)tip;
- this->kupeniProizvodi=kupeniProizvodi;
- }
- static void setPopust(int popust2)
- {
- osnovenPopust=popust2;
- }
- friend ostream &operator<<(ostream &out , Customer &c)
- {
- out<<c.ime<<endl;
- out<<c.adresa<<endl;
- out<<c.kupeniProizvodi<<endl;
- if(c.tip==0)
- {
- out<<"standard 0"<<endl;
- }
- if(c.tip==1)
- {
- out<<"loyal "<<c.osnovenPopust<<endl;
- }
- if(c.tip==2)
- {
- out<<"vip "<<c.dopolnitelenPopust + c.osnovenPopust<<endl;
- }
- return out;
- }
- bool operator==(const Customer &c)
- {
- return strcmp(adresa,c.adresa);
- }
- int getKupeni()
- {
- return kupeniProizvodi;
- }
- int typeKupuvac()
- {
- return tip;
- }
- void setKupuvac(Kupuvac k2)
- {
- tip=(Kupuvac)k2;
- }
- };
- int Customer::osnovenPopust=10;
- class FINKI_bookstore
- {
- private:
- Customer *kupuvaci;
- int brojKupuvaci;
- public:
- FINKI_bookstore()
- {
- kupuvaci=new Customer[0];
- brojKupuvaci=0;
- }
- FINKI_bookstore(const FINKI_bookstore &fb)
- {
- kupuvaci=new Customer[fb.brojKupuvaci+1];
- for(int i=0;i<fb.brojKupuvaci;i++)
- {
- kupuvaci[i]=fb.kupuvaci[i];
- }
- brojKupuvaci=fb.brojKupuvaci;
- }
- FINKI_bookstore &operator=(const FINKI_bookstore &fb)
- {
- if(this!=&fb)
- {
- delete[]kupuvaci;
- kupuvaci=new Customer[fb.brojKupuvaci+1];
- for(int i=0;i<fb.brojKupuvaci;i++)
- {
- kupuvaci[i]=fb.kupuvaci[i];
- }
- brojKupuvaci=fb.brojKupuvaci;
- }
- return *this;
- }
- ~FINKI_bookstore()
- {
- delete[]kupuvaci;
- }
- FINKI_bookstore &operator+=(const Customer &c)
- {
- for(int i=0;i<brojKupuvaci;i++)
- {
- if((kupuvaci[i]==c)==0)
- {
- throw UserExistsException();
- }
- }
- Customer *temp=new Customer[brojKupuvaci+1];
- for(int i=0;i<brojKupuvaci;i++)
- {
- temp[i]=kupuvaci[i];
- }
- temp[brojKupuvaci++]=c;
- delete[]kupuvaci;
- kupuvaci=temp;
- return *this;
- }
- void setCustomers(Customer *niza , int n)
- {
- delete[]kupuvaci;
- kupuvaci=new Customer[n];
- for(int i=0;i<n;i++)
- {
- kupuvaci[i]=niza[i];
- }
- brojKupuvaci=n;
- }
- void update()
- {
- for(int i=0;i<brojKupuvaci;i++)
- {
- if(kupuvaci[i].typeKupuvac()==0 && kupuvaci[i].getKupeni()>5)
- {
- kupuvaci[i].setKupuvac(Kupuvac(1));
- }
- else if(kupuvaci[i].typeKupuvac()==1 && kupuvaci[i].getKupeni()>10)
- {
- kupuvaci[i].setKupuvac(Kupuvac(2));
- }
- }
- }
- friend ostream &operator<<(ostream &out, const FINKI_bookstore &fe)
- {
- for(int i=0;i<fe.brojKupuvaci;i++)
- {
- out<<fe.kupuvaci[i];
- }
- return out;
- }
- };
Advertisement
Add Comment
Please, Sign In to add comment