Advertisement
mujkic_n

Untitled

Dec 11th, 2016
807
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 19.15 KB | None | 0 0
  1. #include <iostream>
  2. #include <conio.h>
  3. using namespace std;
  4.  
  5. const char * crt = "\n------------------------------------------------------\n";
  6.  
  7. template<class T1, class T2>
  8. class Kolekcija
  9. {
  10.     T1* _elementi1;
  11.     T2* _elementi2;
  12.     int _trenutno;
  13. public:
  14.     Kolekcija()
  15.     {
  16.         _trenutno = 0;
  17.         _elementi1 = nullptr;
  18.         _elementi2 = nullptr;
  19.     }
  20.  
  21.     Kolekcija(const Kolekcija & obj) : _trenutno(obj._trenutno)
  22.     {
  23.         _elementi1 = new T1[_trenutno];
  24.         _elementi2 = new T2[_trenutno];
  25.  
  26.         for (size_t i = 0; i < _trenutno; i++)
  27.         {
  28.             _elementi1[i] = obj._elementi1[i];
  29.             _elementi2[i] = obj._elementi2[i];
  30.         }
  31.     }
  32.  
  33.     ~Kolekcija()
  34.     {
  35.         delete[] _elementi1;
  36.         delete[] _elementi2;
  37.         _elementi1 = nullptr;
  38.         _elementi2 = nullptr;
  39.     }
  40.  
  41.     void Reset()
  42.     {
  43.         _trenutno = 0;
  44.     }
  45.  
  46.     Kolekcija & operator = (const Kolekcija & right)
  47.     {
  48.         if (this != &right)
  49.         {
  50.             delete[] _elementi1;
  51.             delete[] _elementi2;
  52.  
  53.             _trenutno = right._trenutno;
  54.             _elementi1 = new T1[_trenutno];
  55.             _elementi2 = new T2[_trenutno];
  56.  
  57.             for (size_t i = 0; i < _trenutno; i++)
  58.             {
  59.                 _elementi1[i] = right._elementi1[i];
  60.                 _elementi2[i] = right._elementi2[i];
  61.             }
  62.         }
  63.         return *this;
  64.     }
  65.  
  66.     void DodajElemente(T1& el1, T2& el2)
  67.     {
  68.         T1* temp1 = new T1[_trenutno + 1];
  69.         T2* temp2 = new T2[_trenutno + 1];
  70.  
  71.         for (int i = 0; i < _trenutno; i++)
  72.         {
  73.             temp1[i] = _elementi1[i];
  74.             temp2[i] = _elementi2[i];
  75.         }
  76.  
  77.         delete[] _elementi1;
  78.         delete[] _elementi2;
  79.  
  80.         _elementi1 = temp1;
  81.         _elementi2 = temp2;
  82.  
  83.         _elementi1[_trenutno] = el1;
  84.         _elementi2[_trenutno] = el2;
  85.         _trenutno++;
  86.     }
  87.  
  88.     T1 & GetElement_1(int indeks)const
  89.     {
  90.         if (indeks >= 0 && indeks < _trenutno)
  91.             return _elementi1[indeks];
  92.     }
  93.  
  94.     T1 &operator[](int indeks)const
  95.     {
  96.         if (indeks >= 0 && indeks < _trenutno)
  97.             return _elementi1[indeks];
  98.     }
  99.  
  100.     T2 & GetElement_2(int indeks)const
  101.     {
  102.         if (indeks >= 0 && indeks < _trenutno)
  103.             return _elementi2[indeks];
  104.     }
  105.  
  106.     int GetTrenutno() const { return _trenutno; }
  107.  
  108.     friend ostream& operator<<<>(ostream&, const Kolekcija&);
  109. };
  110. template<class T1, class T2>
  111. ostream& operator<<<>(ostream& cout, const Kolekcija<T1, T2>& k)
  112. {
  113.     for (int i = 0; i < k._trenutno; i++)
  114.     {
  115.         cout << k._elementi1[i] << "\t" << k._elementi2[i] << endl;
  116.     }
  117.  
  118.     return cout;
  119. }
  120.  
  121. //U programu implementirati nasljeđivanje između odgovarajućih klasa
  122. //Klasu Osoba deklarisati kao apstraktnu.
  123. class Osoba
  124. {
  125. protected:
  126.     char* _ime;
  127.     char* _prezime;
  128.     char* _adresa;
  129.     char _telefon[15];
  130. public:
  131.  
  132.     Osoba(char* ime, char* prezime, char* adresa, char* telefon)
  133.     {
  134.         int vel = strlen(ime) + 1;
  135.         _ime = new char[vel];
  136.         strcpy_s(_ime, vel, ime);
  137.  
  138.         vel = strlen(prezime) + 1;
  139.         _prezime = new char[vel];
  140.         strcpy_s(_prezime, vel, prezime);
  141.  
  142.         vel = strlen(adresa) + 1;
  143.         _adresa = new char[vel];
  144.         strcpy_s(_adresa, vel, adresa);
  145.  
  146.         strcpy_s(_telefon, 15, telefon);
  147.     }
  148.     Osoba(const Osoba & obj)
  149.     {
  150.         int size = strlen(obj._ime) + 1;
  151.         _ime = new char[size];
  152.         strcpy_s(_ime, size, obj._ime);
  153.  
  154.         size = strlen(obj._prezime) + 1;
  155.         _prezime = new char[size];
  156.         strcpy_s(_prezime, size, obj._prezime);
  157.  
  158.         size = strlen(obj._adresa) + 1;
  159.         _adresa = new char[size];
  160.         strcpy_s(_adresa, size, obj._adresa);
  161.  
  162.         strcpy_s(_telefon, 15, obj._telefon);
  163.     }
  164.     virtual ~Osoba()
  165.     {
  166.         delete[] _ime;
  167.         delete[] _prezime;
  168.         delete[] _adresa;
  169.         _ime = nullptr;
  170.         _prezime = nullptr;
  171.         _adresa = nullptr;
  172.     }
  173.     Osoba & operator = (const Osoba & right)
  174.     {
  175.         if (this != &right)
  176.         {
  177.             delete[] _ime;
  178.             delete[] _prezime;
  179.             delete[] _adresa;
  180.  
  181.             int size = strlen(right._ime) + 1;
  182.             _ime = new char[size];
  183.             strcpy_s(_ime, size, right._ime);
  184.  
  185.             size = strlen(right._prezime) + 1;
  186.             _prezime = new char[size];
  187.             strcpy_s(_prezime, size, right._prezime);
  188.  
  189.             size = strlen(right._adresa) + 1;
  190.             _adresa = new char[size];
  191.             strcpy_s(_adresa, size, right._adresa);
  192.  
  193.             strcpy_s(_telefon, 15, right._telefon);
  194.         }
  195.         return *this;
  196.     }
  197.  
  198.     const char * GetIme()const
  199.     {
  200.         return _ime;
  201.     }
  202.     const char * GetPrezime()const
  203.     {
  204.         return _prezime;
  205.     }
  206.  
  207.     virtual void Info() = 0;
  208. };
  209.  
  210. class Proizvod
  211. {
  212.     char* _naziv;
  213.     char* _opis;
  214.     double _cijena;
  215. public:
  216.     Proizvod(char* naziv, char* opis, double cijena)
  217.     {
  218.         int vel = strlen(naziv) + 1;
  219.         _naziv = new char[vel];
  220.         strcpy_s(_naziv, vel, naziv);
  221.  
  222.         vel = strlen(opis) + 1;
  223.         _opis = new char[vel];
  224.         strcpy_s(_opis, vel, opis);
  225.  
  226.         _cijena = cijena;
  227.     }
  228.     Proizvod(const Proizvod & obj)
  229.     {
  230.         int size = strlen(obj._naziv) + 1;
  231.         _naziv = new char[size];
  232.         strcpy_s(_naziv, size, obj._naziv);
  233.  
  234.         size = strlen(obj._opis) + 1;
  235.         _opis = new char[size];
  236.         strcpy_s(_opis, size, obj._opis);
  237.  
  238.         _cijena = obj._cijena;
  239.     }
  240.     ~Proizvod()
  241.     {
  242.         delete[] _naziv;
  243.         delete[] _opis;
  244.  
  245.         _naziv = nullptr;
  246.         _opis = nullptr;
  247.     }
  248.  
  249.     const char * GetNaziv()const
  250.     {
  251.         return _naziv;
  252.     }
  253.     const char * GetOpis()const
  254.     {
  255.         return _opis;
  256.     }
  257.     double GetCijena()const
  258.     {
  259.         return _cijena;
  260.     }
  261.  
  262.     Proizvod & operator = (const Proizvod & right)
  263.     {
  264.         if (this != &right)
  265.         {
  266.             delete[] _naziv;
  267.             delete[] _opis;
  268.  
  269.             int size = strlen(right._naziv) + 1;
  270.             _naziv = new char[size];
  271.             strcpy_s(_naziv, size, right._naziv);
  272.  
  273.             size = strlen(right._opis) + 1;
  274.             _opis = new char[size];
  275.             strcpy_s(_opis, size, right._opis);
  276.  
  277.             _cijena = right._cijena;
  278.         }
  279.         return *this;
  280.     }
  281.  
  282.     friend ostream& operator<<(ostream&, const Proizvod&);
  283.     friend ostream& operator<<(ostream&, const Proizvod*);
  284.     friend bool operator ==(const Proizvod &, const Proizvod &);
  285. };
  286. ostream& operator<<(ostream& cout, const Proizvod& p)
  287. {
  288.     cout << "Naziv: " << p._naziv << endl;
  289.     cout << "Opis: " << p._opis << endl;
  290.     cout << "Cijena: " << p._cijena << "KM" << endl;
  291.  
  292.     return cout;
  293. }
  294. ostream& operator<<(ostream& cout, const Proizvod* p)
  295. {
  296.     cout << "Naziv: " << p->_naziv << endl;
  297.     cout << "Opis: " << p->_opis << endl;
  298.     cout << "Cijena: " << p->_cijena << "KM" << endl;
  299.  
  300.     return cout;
  301. }
  302. bool operator ==(const Proizvod & left, const Proizvod & right)
  303. {
  304.     if (strcmp(left._naziv, right._naziv) != 0)
  305.         return false;
  306.     else if (strcmp(left._opis, right._opis) != 0)
  307.         return false;
  308.     else if (left._cijena != right._cijena)
  309.         return false;
  310.     return true;
  311. }
  312.  
  313. class Narudzba
  314. {
  315.     char _datum[12]; //Format: dd.MM.yyyy.
  316.     Kolekcija<Proizvod*, int> _proizvodi; //Podaci o naručenim proizvodima i količinama
  317. public:
  318.     //Potrebne osnovne funkcije za rad sa klasom
  319.     Narudzba()
  320.     {
  321.         strcpy_s(_datum, "<N/A>");
  322.     }
  323.     Narudzba(char * datum)
  324.     {
  325.         strncpy_s(_datum, datum, _TRUNCATE);
  326.     }
  327.     Narudzba(const Narudzba & obj)
  328.     {
  329.         strcpy_s(_datum, obj._datum);
  330.         for (size_t i = 0; i < obj._proizvodi.GetTrenutno(); i++)
  331.         {
  332.             Proizvod * noviProizvod = new Proizvod(*obj._proizvodi.GetElement_1(i));
  333.             int kol = obj._proizvodi.GetElement_2(i);
  334.             _proizvodi.DodajElemente(noviProizvod, kol);
  335.         }
  336.     }
  337.     Narudzba & operator = (const Narudzba & right)
  338.     {
  339.         if (this != &right)
  340.         {
  341.             for (size_t i = 0; i < _proizvodi.GetTrenutno(); i++)
  342.             {
  343.                 delete _proizvodi.GetElement_1(i);
  344.             }
  345.  
  346.             strcpy_s(_datum, right._datum);
  347.  
  348.             _proizvodi.Reset();
  349.  
  350.             for (size_t i = 0; i < right._proizvodi.GetTrenutno(); i++)
  351.             {
  352.                 Proizvod * noviProizvod = new Proizvod(*right._proizvodi.GetElement_1(i));
  353.                 int kol = right._proizvodi.GetElement_2(i);
  354.                 _proizvodi.DodajElemente(noviProizvod, kol);
  355.             }
  356.         }
  357.         return *this;
  358.     }
  359.     ~Narudzba()
  360.     {
  361.         for (size_t i = 0; i < _proizvodi.GetTrenutno(); i++)
  362.         {
  363.             delete _proizvodi.GetElement_1(i);
  364.             _proizvodi.GetElement_1(i) = nullptr;
  365.         }
  366.     }
  367.     int GetMjesecNarudzbe()const
  368.     {
  369.         char datum[3] = { _datum[3], _datum[4], '\0' };
  370.         return atoi(datum);
  371.     }
  372.  
  373.     void DodajProizvod(const Proizvod & proizvod, int kolicina = 1)
  374.     {
  375.         for (size_t i = 0; i < _proizvodi.GetTrenutno(); i++)
  376.         {
  377.             if (*_proizvodi.GetElement_1(i) == proizvod)
  378.             {
  379.                 _proizvodi.GetElement_2(i)++; // povecaj kolicinu za jedan ako su proizvodi isti
  380.                 return;
  381.             }
  382.         }
  383.         Proizvod * proizvodPtr = new Proizvod(proizvod);
  384.         _proizvodi.DodajElemente(proizvodPtr, kolicina);
  385.     }
  386.     //Funkciju GetIznosNarudzbe koja vraća ukupan iznos narudžbe na osnovu
  387.     //podataka o cijenama proizvoda i naručenim količinama. Funkcija prima neobavezni parametar popust
  388.     //koji inicijalno ima vrijednost 0, što znači da ne postoji popust na postojeće cijene proizvoda.
  389.     double GetIznosNarudzbe(float popust = 0)const
  390.     {
  391.         if (popust >= 1) // ako se popust ne unese u decimali
  392.             popust /= 100;
  393.  
  394.         double suma = 0;
  395.         for (size_t i = 0; i < _proizvodi.GetTrenutno(); i++)
  396.             suma += _proizvodi.GetElement_1(i)->GetCijena() * _proizvodi.GetElement_2(i);
  397.         return suma -= (suma * popust);
  398.     }
  399.     //Funkciju za ispis svih vrijednosti atributa klase.
  400.     void Info()
  401.     {
  402.         cout << crt << "\t\tDatum narudzbe: " << _datum << crt;
  403.         if (_proizvodi.GetTrenutno() > 0)
  404.         {
  405.             cout << "Ukupno proizvoda: " << _proizvodi.GetTrenutno() << endl;
  406.             cout << "\n\t\t:::LISTA PROIZVODA:::\n\n";
  407.             for (size_t i = 0; i < _proizvodi.GetTrenutno(); i++)
  408.                 cout << _proizvodi.GetElement_1(i) << "Kolicina: " << _proizvodi.GetElement_2(i) << endl << endl;
  409.         }
  410.         else
  411.             cout << "Narudzba trenutno nema proizvoda";
  412.         cout << "------------------------------------------------------\n";
  413.     }
  414. };
  415.  
  416. class Klijent : public Osoba
  417. {
  418. protected:
  419.     int _id;
  420.     char* _email;
  421.     static int BROJ_ID;
  422.     Kolekcija<Narudzba, double> _narudzbe; //Podaci o narudžbama sa ukupnim utrošenim iznosom u KM
  423. public:
  424.     //Potrebne konstruktor i destruktor funkcije.
  425.     Klijent(char* ime, char* prezime, char* adresa, char* telefon, char * email) : Osoba(ime, prezime, adresa, telefon), _id(BROJ_ID++)
  426.     {
  427.         int size = strlen(email) + 1;
  428.         _email = new char[size];
  429.         strcpy_s(_email, size, email);
  430.     }
  431.     Klijent(const Klijent & obj) : Osoba(obj), _id(obj._id)
  432.     {
  433.         int size = strlen(obj._email) + 1;
  434.         _email = new char[size];
  435.         strcpy_s(_email, size, obj._email);
  436.  
  437.         _narudzbe = obj._narudzbe;
  438.     }
  439.     ~Klijent()
  440.     {
  441.         delete[]_email;
  442.         _email = nullptr;
  443.     }
  444.     Klijent & operator= (const Klijent & right)
  445.     {
  446.         if (this != &right)
  447.         {
  448.             delete[] _email;
  449.  
  450.             Osoba::operator=(right);
  451.  
  452.             _id = right._id;
  453.  
  454.             int size = strlen(right._email) + 1;
  455.             _email = new char[size];
  456.             strcpy_s(_email, size, right._email);
  457.  
  458.             _narudzbe = right._narudzbe;
  459.         }
  460.         return *this;
  461.     }
  462.     //Funkciju za evidenciju nove narudžbe.
  463.     virtual void EvidentirajNarudzbu(const Narudzba & narudzba)
  464.     {
  465.         Narudzba order(narudzba);
  466.         double ukupnoPotroseno = narudzba.GetIznosNarudzbe();
  467.         _narudzbe.DodajElemente(order, ukupnoPotroseno);
  468.     }
  469.     //Funkciju koja vraća logičku vrijednost true ukoliko je klijent za odabrani mjesec u godini imao
  470.     //potrošnju veću od zadate. Prototip funkcije: bool IsPotrosnjaVeca(int mjesec, double potrosnja);
  471.     //Za pronalazak potrosnje po mjesecima koristiti podatak o datumu narudžbe.
  472.     bool IsPotrosnjaVeca(int mjesec, double potrosnja)
  473.     {
  474.         for (size_t i = 0; i < _narudzbe.GetTrenutno(); i++)
  475.         {
  476.             if (mjesec == _narudzbe.GetElement_1(i).GetMjesecNarudzbe())
  477.                 if (_narudzbe.GetElement_2(i) >= potrosnja)
  478.                     return true;
  479.         }
  480.         return false;
  481.     }
  482.     //Funkciju za izmjenu e-mail adrese.
  483.     bool SetEmail(const char * email)
  484.     {
  485.         if (email != nullptr)
  486.         {
  487.             delete[]_email;
  488.  
  489.             int size = strlen(email) + 1;
  490.             _email = new char[size];
  491.             strcpy_s(_email, size, email);
  492.             return true;
  493.         }
  494.         return false;
  495.     }
  496.  
  497.     //Funkciju za ispis svih vrijednosti atributa klase.
  498.     void Info()
  499.     {
  500.         cout << "ID: " << _id << endl;
  501.         cout << "Ime i prezime: " << _ime << " " << _prezime << endl;
  502.         cout << "Adresa: " << _adresa << endl;
  503.         cout << "Telefon: " << _telefon << endl;
  504.         cout << "E-mail: " << _email;
  505.         cout << crt << "\t:::PODACI O NARUDZBAMA:::\n";
  506.         if (_narudzbe.GetTrenutno() > 0)
  507.         {
  508.             cout << "Broj evidentiranih narudzbi: " << _narudzbe.GetTrenutno() << endl;
  509.             for (size_t i = 0; i < _narudzbe.GetTrenutno(); i++)
  510.             {
  511.                 cout << "\t\t>> Narudzba [" << i + 1 << "/" << _narudzbe.GetTrenutno() << "] <<";
  512.                 _narudzbe.GetElement_1(i).Info();
  513.                 cout << "Ukupno potroseno: " << _narudzbe.GetElement_2(i) << "KM";
  514.             }
  515.         }
  516.         else
  517.             cout << "Klijent [" << _ime << " " << _prezime << "] nema evidentiranih narudzbi" << endl;
  518.     }
  519. };
  520.  
  521. int Klijent::BROJ_ID = 1;
  522.  
  523. class VIPKlijent : public Klijent
  524. {
  525.     char* _parkingOznaka;
  526.     double _popust;
  527. public:
  528.     //Potrebne konstruktor i destruktor funkcije
  529.     VIPKlijent(char* ime, char* prezime, char* adresa, char* telefon, char * email, char * parkingOznaka, double popust) : Klijent(ime, prezime, adresa, telefon, email)
  530.     {
  531.         int size = strlen(parkingOznaka) + 1;
  532.         _parkingOznaka = new char[size];
  533.         strcpy_s(_parkingOznaka, size, parkingOznaka);
  534.  
  535.         _popust = popust;
  536.     }
  537.     VIPKlijent(const VIPKlijent & obj) : Klijent(obj)
  538.     {
  539.         int size = strlen(obj._parkingOznaka) + 1;
  540.         _parkingOznaka = new char[size];
  541.         strcpy_s(_parkingOznaka, size, obj._parkingOznaka);
  542.  
  543.         _popust = obj._popust;
  544.     }
  545.     ~VIPKlijent()
  546.     {
  547.         delete[]_parkingOznaka;
  548.         _parkingOznaka = nullptr;
  549.     }
  550.     VIPKlijent & operator = (const VIPKlijent & right)
  551.     {
  552.         if (this != &right)
  553.         {
  554.             delete[]_parkingOznaka;
  555.  
  556.             Klijent::operator=(right);
  557.  
  558.             int size = strlen(right._parkingOznaka) + 1;
  559.             _parkingOznaka = new char[size];
  560.             strcpy_s(_parkingOznaka, size, right._parkingOznaka);
  561.  
  562.             _popust = right._popust;
  563.         }
  564.         return *this;
  565.     }
  566.     //Funkciju za evidenciju nove narudžbe sa zaračunatim popustom na sve proizvode.
  567.     void EvidentirajNarudzbu(const Narudzba & narudzba)
  568.     {
  569.         Narudzba order(narudzba);
  570.         double ukupnoPotroseno = narudzba.GetIznosNarudzbe(_popust);
  571.         _narudzbe.DodajElemente(order, ukupnoPotroseno);
  572.     }
  573.     //Funkciju koja posljednjoj narudžbi klijenta dodaje gratis proizvod proslijeđen kao parametar.
  574.     bool DodajGratisProizvod(const Proizvod & proizvod)
  575.     {
  576.         if (_narudzbe.GetTrenutno() == 0)
  577.         {
  578.             cout << "Ne postoji nijedna evidentirana narudzba" << endl;
  579.             return false;
  580.         }
  581.         _narudzbe[_narudzbe.GetTrenutno() - 1].DodajProizvod(proizvod);
  582.         return true;
  583.     }
  584.     //Funkciju za ispis svih vrijednosti atributa klase
  585.     void Info()
  586.     {
  587.         cout << "ID: " << _id << endl;
  588.         cout << "Ime i prezime: " << _ime << " " << _prezime << endl;
  589.         cout << "Adresa: " << _adresa << endl;
  590.         cout << "Telefon: " << _telefon << endl;
  591.         cout << "E-mail: " << _email << endl;
  592.         cout << "Parking oznaka: " << _parkingOznaka << endl;
  593.         cout << "Popust: " << _popust << "%";
  594.         cout << crt << "\t:::PODACI O NARUDZBAMA:::\n";
  595.         if (_narudzbe.GetTrenutno() > 0)
  596.         {
  597.             cout << "Broj evidentiranih narudzbi: " << _narudzbe.GetTrenutno() << endl;
  598.             for (size_t i = 0; i < _narudzbe.GetTrenutno(); i++)
  599.             {
  600.                 cout << "\t\t>> Narudzba [" << i + 1 << "/" << _narudzbe.GetTrenutno() << "] <<";
  601.                 _narudzbe.GetElement_1(i).Info();
  602.                 cout << "Ukupno potroseno: " << _narudzbe.GetElement_2(i) << "KM\n";
  603.             }
  604.         }
  605.         else
  606.             cout << "Klijent [" << _ime << " " << _prezime << "] nema evidentiranih narudzbi" << endl;
  607.  
  608.     }
  609. };
  610.  
  611. const char * sastaviMail(const char * ime, const char * prezime)
  612. {
  613.     int size = strlen(ime) + 1;
  614.     char * temp_ime = new char[size];
  615.     strcpy_s(temp_ime, size, ime);
  616.  
  617.     size = strlen(prezime) + 1;
  618.     char * temp_prezime = new char[size];
  619.     strcpy_s(temp_prezime, size, prezime);
  620.  
  621.     for (size_t i = 0; i < strlen(ime); i++)
  622.     {
  623.         temp_ime[i] = tolower(ime[i]);
  624.         for (size_t j = 0; j < prezime[j]; j++)
  625.             temp_prezime[j] = tolower(prezime[j]);
  626.     }
  627.  
  628.     char temp[100];
  629.     strcpy_s(temp, temp_ime);
  630.     strcat_s(temp, ".");
  631.     strcat_s(temp, temp_prezime);
  632.     strcat_s(temp, "@firma.ba");
  633.  
  634.     size = strlen(temp) + 1;
  635.     char * email = new char[size];
  636.     strcpy_s(email, size, temp);
  637.  
  638.     return email;
  639. }
  640.  
  641.  
  642. //Funkcija treba da pronađe sve one klijente koji su za odabrani mjesec ostvarili potrošnju veću
  643. //od zadate. Ispisati njihove podatke i vratiti ukupan broj pronađenih klijenata.
  644. int PronadjiKlijentePoPotrosnji(Osoba* niz[], int length)
  645. {
  646.     int mjesec = 0;
  647.     int brojacKlijenata = 0;
  648.     double potrosnja = 0;
  649.     Klijent * klijent = nullptr;
  650.  
  651.     cout << "Unesite mjesec: ";
  652.     cin >> mjesec;
  653.     cin.ignore();
  654.  
  655.     cout << "Unesite potrosnju: ";
  656.     cin >> potrosnja;
  657.     cin.ignore();
  658.  
  659.     for (size_t i = 0; i < length; i++)
  660.     {
  661.         klijent = dynamic_cast<Klijent*>(niz[i]);
  662.         if (klijent != nullptr)
  663.         {
  664.             if (klijent->IsPotrosnjaVeca(mjesec, potrosnja))
  665.             {
  666.                 klijent->Info();
  667.                 brojacKlijenata++;
  668.             }
  669.  
  670.         }
  671.     }
  672.  
  673.     return brojacKlijenata;
  674. }
  675.  
  676. //Pronaći sve VIP klijente, te im dodati gratis proizvod proslijeđen kao parametar.
  677. void UkljuciGratisProizvodVIPKlijentima(Osoba* niz[], int length, const Proizvod& proizvod)
  678. {
  679.     VIPKlijent * vip_klijent = nullptr;
  680.     for (size_t i = 0; i < length; i++)
  681.     {
  682.         vip_klijent = dynamic_cast<VIPKlijent *>(niz[i]);
  683.         if (vip_klijent != nullptr)
  684.             vip_klijent->DodajGratisProizvod(proizvod);
  685.     }
  686. }
  687.  
  688. //Svim klijentima postaviti mail adresu u formatu: ime.prezime@firma.ba.
  689. void GenerisiMailAdreseKlijentima(Osoba* niz[], int length)
  690. {
  691.     Klijent * klijent = nullptr;
  692.     for (size_t i = 0; i < length; i++)
  693.     {
  694.         klijent = dynamic_cast<Klijent *>(niz[i]);
  695.         if (klijent != nullptr)
  696.         {
  697.             if (typeid(Klijent) == typeid(*klijent))
  698.                 klijent->SetEmail(sastaviMail(klijent->GetIme(), klijent->GetPrezime()));
  699.         }
  700.  
  701.     }
  702. }
  703.  
  704. //Omogućiti pretragu klijenata po imenu ili prezimenu (ispisati informacije
  705. //o svim klijentima koji sadrže uneseni tekst u dijelu imena ili prezimena.
  706. void PronadjiKlijentePoImenuPrezimenu(Osoba* niz[], int length)
  707. {
  708.     Klijent * klijent = nullptr;
  709.     char temp[50];
  710.     cout << "Unesite ime ili prezime klijenta: ";
  711.     cin.getline(temp, 50);
  712.  
  713.     for (size_t i = 0; i < length; i++)
  714.     {
  715.         klijent = dynamic_cast<Klijent*>(niz[i]);
  716.         if (klijent != nullptr)
  717.         {
  718.             if (strstr(klijent->GetIme(), temp) != 0 || strstr(klijent->GetPrezime(), temp) != 0)
  719.                 klijent->Info();
  720.         }
  721.     }
  722. }
  723.  
  724. void main()
  725. {
  726.     const int length = 5;
  727.     Osoba * niz[length];
  728.     niz[0] = new Klijent("Nisvet", "Mujkic", "Ahmeta Fetahagica bb", "060/302-5434", "nisvet.mujkic@edu.fit.ba");
  729.     niz[1] = new Klijent("Eman", "Basic", "Ulica Marsala Tita 14", "061/551-3421", "eman.basic@tu.au");
  730.     niz[2] = new Klijent("Johnny", "Bravo", "Ulica Dzemala Bijedica", "065/652-5984", "johnny.bravo@gov.us");
  731.     niz[3] = new VIPKlijent("Mirnes", "Cerimovic", "Tuzlanska bb", "061/777-3333", "mirnes.cerimovic@untz.ba", "MC_1", 50);
  732.     niz[4] = new VIPKlijent("Haris", "Kudic", "Ilidza 12", "062/919-8732", "haris.kudic@edu.burch.ba", "HK_2", 0.1);
  733.  
  734.     Proizvod sok("Cappy", "Tropsko voce", 1.3);
  735.     Proizvod cokolada("Milka", "Cokolada sa nougatom", 1.7);
  736.     Proizvod cips("Frank Chips XXL", "Slani cips", 2.4);
  737.     Proizvod sladoled("Macho", "Vanilija", 1.5);
  738.  
  739.     Narudzba order_1("11/12/2016");
  740.  
  741.     order_1.DodajProizvod(sok, 10);
  742.     order_1.DodajProizvod(cokolada);
  743.     order_1.DodajProizvod(cokolada);
  744.  
  745.     Narudzba order_2("04/7/2016");
  746.  
  747.     order_2.DodajProizvod(cips, 15);
  748.     order_2.DodajProizvod(sok, 4);
  749.  
  750.     Klijent * k1 = dynamic_cast<Klijent*>(niz[0]);
  751.     if (k1 != nullptr)
  752.         k1->EvidentirajNarudzbu(order_1);
  753.  
  754.     VIPKlijent * k2 = dynamic_cast<VIPKlijent*>(niz[3]);
  755.     if (k2 != nullptr)
  756.         k2->EvidentirajNarudzbu(order_1);
  757.  
  758.     GenerisiMailAdreseKlijentima(niz, length);
  759.  
  760.     UkljuciGratisProizvodVIPKlijentima(niz, length, cips);
  761.  
  762.     PronadjiKlijentePoImenuPrezimenu(niz, length);
  763.  
  764.     PronadjiKlijentePoPotrosnji(niz, length);
  765.  
  766.     _getch();
  767. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement