Advertisement
Guest User

Untitled

a guest
Sep 18th, 2019
580
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 186.65 KB | None | 0 0
  1. //1. Транспорт
  2. #include<iostream>
  3. #include<cstring>
  4.  
  5. using namespace std;
  6.  
  7. class Transport
  8. {
  9. protected:
  10.     char destinacija [50];
  11.     int osnovnaCena;
  12.     int rastojanie;
  13. public:
  14.     Transport(){}
  15.     Transport(const char *dest, int oc, int ras)
  16.     {
  17.         strcpy(destinacija, dest);
  18.         osnovnaCena=oc;
  19.         rastojanie=ras;
  20.     }
  21.     virtual double cenaTransport()=0;
  22.     virtual char* getDestinacija()
  23.     {
  24.         return destinacija;
  25.     }
  26.     int getRastojanie()
  27.     {
  28.         return rastojanie;
  29.     }
  30.     virtual ~Transport(){}
  31. };
  32.  
  33. bool operator < (Transport &t1, Transport *t2)
  34. {
  35.     return t1.getRastojanie()>t2->getRastojanie();
  36. }
  37.  
  38. class AvtomobilTransport: public Transport
  39. {
  40. private:
  41.     bool shofer;
  42. public:
  43.     AvtomobilTransport():Transport(){}
  44.     AvtomobilTransport(const char *dest, int oc, int ras, bool s):Transport(dest, oc, ras)
  45.     {
  46.         shofer=s;
  47.     }
  48.     char* getDestinacija()
  49.     {
  50.         return destinacija;
  51.     }
  52.     double cenaTransport()
  53.     {
  54.         if(shofer)
  55.         {
  56.             //osnovnaCena*=1.2;
  57.             return osnovnaCena*1.2;
  58.         }
  59.         else return osnovnaCena;
  60.        
  61.     }
  62. };
  63.  
  64. class KombeTransport: public Transport
  65. {
  66. private:
  67.     int patnici;
  68. public:
  69.     KombeTransport():Transport(){}
  70.     KombeTransport(const char *dest, int oc, int ras, int pat):Transport(dest, oc, ras)
  71.     {
  72.         patnici=pat;
  73.     }
  74.     char* getDestinacija()
  75.     {
  76.         return destinacija;
  77.     }
  78.     double cenaTransport()
  79.     {
  80.         return osnovnaCena-patnici*200.0;
  81.     }
  82.  
  83. };
  84.  
  85. void pecatiPoloshiPonudi(Transport **t, int n, AvtomobilTransport &pon)
  86. {
  87.     Transport *pom;
  88.     for(int i=0; i<n-1; i++)
  89.     {
  90.         for(int j=i+1; j<n; j++)
  91.         {
  92.             if(*t[i]<t[j])
  93.             {
  94.                 pom=t[j];
  95.                 t[j]=t[i];
  96.                 t[i]=pom;
  97.             }
  98.         }
  99.     }
  100.     for(int i=0; i<n; i++)
  101.     {
  102.         if(t[i]->cenaTransport()>=pon.cenaTransport())
  103.             cout<<t[i]->getDestinacija()<<" "<<t[i]->getRastojanie()<<" "<<t[i]->cenaTransport()<<endl;
  104.     }
  105.  
  106. }
  107.  
  108. int main(){
  109.  
  110. char destinacija[20];
  111. int tip,cena,rastojanie,lugje;
  112. bool shofer;
  113. int n;
  114. cin>>n;
  115. Transport  **ponudi;
  116. ponudi=new Transport *[n];
  117.  
  118. for (int i=0;i<n;i++){
  119.  
  120.     cin>>tip>>destinacija>>cena>>rastojanie;
  121.     if (tip==1) {
  122.         cin>>shofer;
  123.         ponudi[i]=new AvtomobilTransport(destinacija,cena,rastojanie,shofer);
  124.  
  125.     }
  126.     else {
  127.         cin>>lugje;
  128.         ponudi[i]=new KombeTransport(destinacija,cena,rastojanie,lugje);
  129.     }
  130.  
  131.  
  132. }
  133.  
  134. AvtomobilTransport nov("Ohrid",2000,600,false);
  135. pecatiPoloshiPonudi(ponudi,n,nov);
  136.  
  137. for (int i=0;i<n;i++) delete ponudi[i];
  138. delete [] ponudi;
  139. return 0;
  140. }
  141.  
  142. //2. Демонстратор 1
  143. #include<iostream>
  144. #include<string.h>
  145. using namespace std;
  146.  
  147. class NoCourseException {
  148. private:
  149.     int index;
  150. public:
  151.     NoCourseException(int i) {
  152.         index=i;
  153.     }
  154.     void message() {
  155.         cout<<"Demonstratorot so indeks "<< index <<" ne drzi laboratoriski vezbi"<<endl;
  156.     }
  157. };
  158.  
  159. class Kurs {
  160. private:
  161.     char ime[20];
  162.     int krediti;
  163. public:
  164.     Kurs (char *ime, int krediti) {
  165.         strcpy(this->ime,ime);
  166.         this->krediti=krediti;
  167.     }
  168.     Kurs(const Kurs &k) {
  169.         strcpy(ime, k.ime);
  170.         krediti=k.krediti;
  171.     }
  172.     Kurs () {
  173.         strcpy(this->ime,"");
  174.         krediti=0;
  175.     }
  176.     bool operator==(const char *ime) const {
  177.         return strcmp(this->ime,ime)==0;
  178.     }
  179.     char const * getIme()const {
  180.         return ime;
  181.     }
  182.     void pecati ()const {
  183.         cout<<ime<<" "<<krediti<<"ECTS";
  184.     }
  185. };
  186.  
  187. class Student {
  188. private:
  189.     int *ocenki;
  190.     int brojOcenki;
  191.  
  192. protected:
  193.     int indeks;
  194.  
  195. public:
  196.     Student() {
  197.         ocenki=new int[0];
  198.         brojOcenki=0;
  199.     }
  200.     Student(int indeks,int *ocenki, int brojOcenki) {
  201.         this->indeks=indeks;
  202.         this->brojOcenki=brojOcenki;
  203.         this->ocenki=new int[brojOcenki];
  204.         for (int i=0; i<brojOcenki; i++) this->ocenki[i]=ocenki[i];
  205.     }
  206.     Student(const Student &k) {
  207.         this->indeks=k.indeks;
  208.         this->brojOcenki=k.brojOcenki;
  209.         this->ocenki=new int[k.brojOcenki];
  210.         for (int i=0; i<k.brojOcenki; i++) this->ocenki[i]=k.ocenki[i];
  211.     }
  212.     Student& operator=(const Student &k) {
  213.         if (&k==this) return *this;
  214.         this->indeks=k.indeks;
  215.         this->brojOcenki=k.brojOcenki;
  216.         delete [] ocenki;
  217.         this->ocenki=new int[k.brojOcenki];
  218.         for (int i=0; i<k.brojOcenki; i++) this->ocenki[i]=k.ocenki[i];
  219.         return *this;
  220.     }
  221.  
  222.     virtual ~Student() {
  223.         delete [] ocenki;
  224.     }
  225.  
  226.     virtual int getBodovi() {
  227.         int brojac=0;
  228.         for(int i=0; i<brojOcenki; i++) {
  229.             if(ocenki[i]>5)
  230.                 brojac++;
  231.         }
  232.         return brojac*100/brojOcenki;
  233.     }
  234.     virtual void pecati() {
  235.         cout<<indeks;
  236.     }
  237.  
  238. };
  239.  
  240. class Predavach {
  241. private:
  242.     Kurs kursevi[10];
  243.     int brojKursevi;
  244.  
  245. protected:
  246.     char *imeIPrezime;
  247.  
  248. public:
  249.     Predavach() {
  250.         imeIPrezime=new char[0];
  251.         brojKursevi=0;
  252.     }
  253.     Predavach(char *imeIPrezime, Kurs *kursevi, int brojKursevi) {
  254.         this->brojKursevi=brojKursevi;
  255.         for (int i=0; i<brojKursevi; i++) this->kursevi[i]=kursevi[i];
  256.         this->imeIPrezime=new char[strlen(imeIPrezime)+1];
  257.         strcpy(this->imeIPrezime,imeIPrezime);
  258.     }
  259.     Predavach(const Predavach &p) {
  260.         this->brojKursevi=p.brojKursevi;
  261.         for (int i=0; i<p.brojKursevi; i++) this->kursevi[i]=p.kursevi[i];
  262.         this->imeIPrezime=new char[strlen(p.imeIPrezime)+1];
  263.         strcpy(this->imeIPrezime,p.imeIPrezime);
  264.     }
  265.     Predavach &operator=(const Predavach &p) {
  266.         if (this==&p) return *this;
  267.         this->brojKursevi=p.brojKursevi;
  268.         for (int i=0; i<p.brojKursevi; i++) this->kursevi[i]=p.kursevi[i];
  269.         this->imeIPrezime=new char[strlen(p.imeIPrezime)+1];
  270.         delete [] imeIPrezime;
  271.         strcpy(this->imeIPrezime,p.imeIPrezime);
  272.         return *this;
  273.     }
  274.     virtual ~Predavach() {
  275.         delete [] imeIPrezime;
  276.     }
  277.  
  278.     int getBrojKursevi()const {
  279.         return brojKursevi;
  280.     }
  281.  
  282.     char * const getImeIPrezime()const {
  283.         return imeIPrezime;
  284.     }
  285.  
  286.     Kurs operator[](int i) const {
  287.         if (i<brojKursevi&&i>=0)
  288.             return kursevi[i];
  289.         else return Kurs();
  290.     }
  291.     Kurs* getKurs() {
  292.         return kursevi;
  293.     }
  294.     virtual void pecati() const {
  295.         cout<<imeIPrezime<<" (";
  296.         for (int i=0; i<brojKursevi; i++) {
  297.             kursevi[i].pecati();
  298.             if (i<brojKursevi-1) cout<<", ";
  299.             else cout<<")";
  300.         }
  301.     }
  302. };
  303.  
  304. class Demonstrator: public Student, public Predavach {
  305. private:
  306.     int brojChasovi;
  307. public:
  308.     Demonstrator() {}
  309.     Demonstrator(int indeks,int *ocenki, int brojOcenki, char *imeIPrezime, Kurs *kursevi, int brojKursevi, int brojCasovi): Student(indeks, ocenki, brojOcenki),
  310.         Predavach(imeIPrezime, kursevi, brojKursevi) {
  311.         this->brojChasovi=brojCasovi;
  312.     }
  313.     Demonstrator& operator = (const Demonstrator &d) {
  314.         (Student&)(*this)=d;
  315.         (Predavach&)(*this)=d;
  316.         brojChasovi=d.brojChasovi;
  317.         return *this;
  318.     }
  319.     virtual int getBodovi() {
  320.         return Student::getBodovi()+20.0*brojChasovi/getBrojKursevi();
  321.     }
  322.     virtual void pecati() {
  323.         int i;
  324.         Student::pecati();
  325.         cout<<": "<<imeIPrezime<<" (";
  326.         for(i=0; i<Predavach::getBrojKursevi()-1; i++) {
  327.             getKurs()[i].pecati();
  328.             cout<<", ";
  329.         }
  330.         getKurs()[i].pecati();
  331.         cout<<")";
  332.     }
  333.     int getBrojChasovi() {
  334.         return brojChasovi;
  335.     }
  336.     virtual ~Demonstrator() {}
  337. };
  338.  
  339. //mesto za vashiot kod
  340.  
  341. Student& vratiNajdobroRangiran(Student ** studenti, int n ) {
  342.     int maxbodovi=0;
  343.     Student *temp1;
  344.     for(int i=0; i<n; i++) {
  345.         if(maxbodovi<studenti[i]->getBodovi()) {
  346.             maxbodovi=studenti[i]->getBodovi();
  347.             temp1=studenti[i];
  348.         }
  349.     }
  350.     return *temp1;
  351. }
  352.  
  353. void pecatiDemonstratoriKurs (char* kurs, Student** studenti, int n) {
  354.     for(int i=0; i<n; i++) {
  355.         Predavach *temp=dynamic_cast<Predavach*>(studenti[i]);
  356.         for(int j=0; j<10; j++)
  357.         {
  358.             if(temp->getKurs()[j]==kurs)
  359.             {
  360.                 Demonstrator *temp1=dynamic_cast<Demonstrator*>(studenti[i]);
  361.                 temp1->pecati();
  362.                 cout<<endl;
  363.             }
  364.         }
  365.     }
  366. }
  367.  
  368.  
  369. int main() {
  370.  
  371.     Kurs kursevi[10];
  372.     int indeks,brojKursevi, ocenki[20],ocenka,brojOcenki,tip,brojCasovi,krediti;
  373.     char ime[20],imeIPrezime[50];
  374.  
  375.     cin>>tip;
  376.  
  377.     if (tip==1) { //test class Demonstrator
  378.         cout<<"-----TEST Demonstrator-----"<<endl;
  379.         cin>>indeks>>brojOcenki;
  380.         for (int i=0; i<brojOcenki; i++) {
  381.             cin>>ocenka;
  382.             ocenki[i]=ocenka;
  383.         }
  384.         cin>>imeIPrezime>>brojKursevi;
  385.         for (int i=0; i<brojKursevi; i++) {
  386.             cin>>ime>>krediti;
  387.             kursevi[i]=Kurs(ime,krediti);
  388.         }
  389.         cin>>brojCasovi;
  390.         try {
  391.             Demonstrator d(indeks,ocenki,brojOcenki,imeIPrezime,kursevi,brojKursevi,brojCasovi);
  392.         } catch (NoCourseException n) {
  393.             n.message();
  394.         }
  395.         cout<<"Objekt od klasata Demonstrator e kreiran";
  396.  
  397.     } else if (tip==2) { //funkcija pecati vo Student
  398.         cout<<"-----TEST pecati-----"<<endl;
  399.         cin>>indeks>>brojOcenki;
  400.         for (int i=0; i<brojOcenki; i++) {
  401.             cin>>ocenka;
  402.             ocenki[i]=ocenka;
  403.         }
  404.  
  405.         Student s(indeks,ocenki,brojOcenki);
  406.         s.pecati();
  407.  
  408.     } else if (tip==3) { //funkcija getVkupnaOcenka vo Student
  409.         cout<<"-----TEST getVkupnaOcenka-----"<<endl;
  410.         cin>>indeks>>brojOcenki;
  411.         for (int i=0; i<brojOcenki; i++) {
  412.             cin>>ocenka;
  413.             ocenki[i]=ocenka;
  414.         }
  415.         Student s(indeks,ocenki,brojOcenki);
  416.         cout<<"Broj na bodovi: "<<s.getBodovi()<<endl;
  417.  
  418.     } else if (tip==4) { //funkcija getVkupnaOcenka vo Demonstrator
  419.         cout<<"-----TEST getVkupnaOcenka-----"<<endl;
  420.         cin>>indeks>>brojOcenki;
  421.         for (int i=0; i<brojOcenki; i++) {
  422.             cin>>ocenka;
  423.             ocenki[i]=ocenka;
  424.         }
  425.  
  426.         cin>>imeIPrezime>>brojKursevi;
  427.         for (int i=0; i<brojKursevi; i++) {
  428.             cin>>ime>>krediti;
  429.             kursevi[i]=Kurs(ime,krediti);
  430.         }
  431.         cin>>brojCasovi;
  432.         Demonstrator d(indeks,ocenki,brojOcenki,imeIPrezime,kursevi,brojKursevi,brojCasovi);
  433.         try {
  434.             cout<<"Broj na bodovi: "<<d.getBodovi()<<endl;
  435.         } catch(NoCourseException n) {
  436.             n.message();
  437.         }
  438.  
  439.     } else if (tip==5) { //funkcija pecati vo Demonstrator
  440.         cout<<"-----TEST pecati -----"<<endl;
  441.         cin>>indeks>>brojOcenki;
  442.         for (int i=0; i<brojOcenki; i++) {
  443.             cin>>ocenka;
  444.             ocenki[i]=ocenka;
  445.         }
  446.         cin>>imeIPrezime>>brojKursevi;
  447.         for (int i=0; i<brojKursevi; i++) {
  448.             cin>>ime>>krediti;
  449.             kursevi[i]=Kurs(ime,krediti);
  450.         }
  451.         cin>>brojCasovi;
  452.  
  453.         Demonstrator d(indeks,ocenki,brojOcenki,imeIPrezime,kursevi,brojKursevi,brojCasovi);
  454.         d.pecati();
  455.  
  456.     } else if (tip==6) { //site klasi
  457.         cout<<"-----TEST Student i Demonstrator-----"<<endl;
  458.         cin>>indeks>>brojOcenki;
  459.         for (int i=0; i<brojOcenki; i++) {
  460.             cin>>ocenka;
  461.             ocenki[i]=ocenka;
  462.         }
  463.         cin>>imeIPrezime>>brojKursevi;
  464.         for (int i=0; i<brojKursevi; i++) {
  465.             cin>>ime>>krediti;
  466.             kursevi[i]=Kurs(ime,krediti);
  467.         }
  468.         cin>>brojCasovi;
  469.  
  470.         Student *s=new Demonstrator(indeks,ocenki,brojOcenki,imeIPrezime,kursevi,brojKursevi,brojCasovi);
  471.         s->pecati();
  472.         try {
  473.             cout<<"\nBroj na bodovi: "<<s->getBodovi()<<endl;
  474.         } catch(NoCourseException n) {
  475.             n.message();
  476.         }
  477.         delete s;
  478.  
  479.  
  480.     } else if (tip==7) { //funkcija vratiNajdobroRangiran
  481.         cout<<"-----TEST vratiNajdobroRangiran-----"<<endl;
  482.         int k, opt;
  483.         cin>>k;
  484.         Student **studenti=new Student*[k];
  485.         for (int j=0; j<k; j++) {
  486.             cin>>opt; //1 Student 2 Demonstrator
  487.             cin>>indeks>>brojOcenki;
  488.             for (int i=0; i<brojOcenki; i++) {
  489.                 cin>>ocenka;
  490.                 ocenki[i]=ocenka;
  491.             }
  492.             if (opt==1) {
  493.                 studenti[j]=new Student(indeks,ocenki,brojOcenki);
  494.             } else {
  495.                 cin>>imeIPrezime>>brojKursevi;
  496.                 for (int i=0; i<brojKursevi; i++) {
  497.                     cin>>ime>>krediti;
  498.                     kursevi[i]=Kurs(ime,krediti);
  499.                 }
  500.                 try {
  501.                     cin>>brojCasovi;
  502.                     if(brojCasovi==0)
  503.                         throw NoCourseException(indeks);
  504.                 } catch(NoCourseException n) {
  505.                     n.message();
  506.                 }
  507.                 studenti[j]=new Demonstrator(indeks,ocenki,brojOcenki,imeIPrezime,kursevi,brojKursevi,brojCasovi);
  508.             }
  509.         }
  510.         Student& najdobar=vratiNajdobroRangiran(studenti,k);
  511.         try {
  512.             cout<<"Maksimalniot broj na bodovi e:"<<najdobar.getBodovi();
  513.         } catch (NoCourseException n) {
  514.             n.message();
  515.         }
  516.         cout<<"\nNajdobro rangiran:";
  517.         najdobar.pecati();
  518.  
  519.         for (int j=0; j<k; j++) delete studenti[j];
  520.         delete [] studenti;
  521.     } else if (tip==8) { //funkcija pecatiDemonstratoriKurs
  522.         cout<<"-----TEST pecatiDemonstratoriKurs-----"<<endl;
  523.         int k, opt;
  524.         cin>>k;
  525.         Student **studenti=new Student*[k];
  526.         for (int j=0; j<k; j++) {
  527.             cin>>opt; //1 Student 2 Demonstrator
  528.             cin>>indeks>>brojOcenki;
  529.             for (int i=0; i<brojOcenki; i++) {
  530.                 cin>>ocenka;
  531.                 ocenki[i]=ocenka;
  532.             }
  533.             if (opt==1) {
  534.                 studenti[j]=new Student(indeks,ocenki,brojOcenki);
  535.             } else {
  536.                 cin>>imeIPrezime>>brojKursevi;
  537.                 for (int i=0; i<brojKursevi; i++) {
  538.                     cin>>ime>>krediti;
  539.                     kursevi[i]=Kurs(ime,krediti);
  540.                 }
  541.                 cin>>brojCasovi;
  542.                 studenti[j]=new Demonstrator(indeks,ocenki,brojOcenki,imeIPrezime,kursevi,brojKursevi,brojCasovi);
  543.             }
  544.         }
  545.         char kurs[20];
  546.         cin>>kurs;
  547.         cout<<"Demonstratori na "<<kurs<<" se:"<<endl;
  548.         pecatiDemonstratoriKurs (kurs,studenti,k);
  549.         for (int j=0; j<k; j++) delete studenti[j];
  550.         delete [] studenti;
  551.  
  552.     }
  553.  
  554.  
  555.     return 0;
  556. }
  557.  
  558.  
  559. //3. Возач
  560. #include<iostream>
  561. #include<cstring>
  562.  
  563. using namespace std;
  564.  
  565. class Vozac
  566. {
  567. protected:
  568.     char ime[100];
  569.     int vozrast;
  570.     int brojTrki;
  571.     bool veteran;
  572. public:
  573.     Vozac() {}
  574.     Vozac(char *i, int v, int br, bool vet)
  575.     {
  576.         strcpy(ime, i);
  577.         vozrast=v;
  578.         brojTrki=br;
  579.         veteran=vet;
  580.     }
  581.     friend ostream &operator << (ostream &os, Vozac &v)
  582.     {
  583.         os<<v.ime<<endl<<v.vozrast<<endl<<v.brojTrki<<endl;
  584.         if(v.veteran)
  585.             os<<"VETERAN"<<endl;
  586.         return os;
  587.     }
  588.     virtual double zarabotuvachka()=0;
  589.     virtual double danok()=0;
  590.     virtual ~Vozac(){}
  591. };
  592.  
  593. bool operator == (Vozac &v1, Vozac *v2)
  594. {
  595.     return v1.zarabotuvachka()==v2->zarabotuvachka();
  596. }
  597.  
  598. class Avtomobilist: public Vozac
  599. {
  600. private:
  601.     double cenaAvto;
  602. public:
  603.     Avtomobilist():Vozac(){}
  604.     Avtomobilist(char *i, int v, int br, bool vet, double c):Vozac(i, v, br, vet)
  605.     {
  606.         cenaAvto=c;
  607.     }
  608.     double zarabotuvachka()
  609.     {
  610.         return cenaAvto/5.0;
  611.     }
  612.     double danok()
  613.     {
  614.         if(brojTrki>10)
  615.             return zarabotuvachka()*0.15;
  616.         else
  617.             return zarabotuvachka()*0.1;
  618.     }
  619. };
  620.  
  621. class Motociklist: public Vozac
  622. {
  623. private:
  624.     int mokjnost;
  625. public:
  626.     Motociklist():Vozac(){}
  627.     Motociklist(char *i, int v, int br, bool vet, int m):Vozac(i, v, br, vet)
  628.     {
  629.         mokjnost=m;
  630.     }
  631.     double zarabotuvachka()
  632.     {
  633.         return mokjnost*20.0;
  634.     }
  635.     double danok()
  636.     {
  637.         if(veteran)
  638.             return zarabotuvachka()*0.25;
  639.         else
  640.             return zarabotuvachka()*0.2;
  641.     }
  642. };
  643.  
  644. int soIstaZarabotuvachka(Vozac **v, int n, Vozac *voz)
  645. {
  646.     int brojac=0;
  647.     for(int i=0; i<n; i++)
  648.     {
  649.         if(*v[i]==voz)
  650.             brojac++;
  651.     }
  652.     return brojac;
  653. }
  654. int main()
  655. {
  656.     int n, x;
  657.     cin >> n >> x;
  658.     Vozac **v = new Vozac*[n];
  659.     char ime[100];
  660.     int vozrast;
  661.     int trki;
  662.     bool vet;
  663.     for(int i = 0; i < n; ++i)
  664.     {
  665.         cin >> ime >> vozrast >> trki >> vet;
  666.         if(i < x)
  667.         {
  668.             float cena_avto;
  669.             cin >> cena_avto;
  670.             v[i] = new Avtomobilist(ime, vozrast, trki, vet, cena_avto);
  671.         }
  672.         else
  673.         {
  674.             int mokjnost;
  675.             cin >> mokjnost;
  676.             v[i] = new Motociklist(ime, vozrast, trki, vet, mokjnost);
  677.         }
  678.     }
  679.     cout << "=== DANOK ===" << endl;
  680.     for(int i = 0; i < n; ++i)
  681.     {
  682.         cout << *v[i];
  683.         cout << v[i]->danok() << endl;
  684.     }
  685.     cin >> ime >> vozrast >> trki >> vet;
  686.     int mokjnost;
  687.     cin >> mokjnost;
  688.     Vozac *vx = new Motociklist(ime, vozrast, trki, vet, mokjnost);
  689.     cout << "=== VOZAC X ===" << endl;
  690.     cout << *vx;
  691.     cout << "=== SO ISTA ZARABOTUVACKA KAKO VOZAC X ===" << endl;
  692.     cout << soIstaZarabotuvachka(v, n, vx);
  693.     for(int i = 0; i < n; ++i)
  694.     {
  695.         delete v[i];
  696.     }
  697.     delete [] v;
  698.     delete vx;
  699.     return 0;
  700. }
  701.  
  702. //4. Картичка
  703. #include<iostream>
  704. #include<string.h>
  705. using namespace std;
  706.  
  707. class OutOfBoundException {
  708. private:
  709.     char text[100];
  710. public:
  711.     OutOfBoundException(const char *t) {
  712.         strcpy(text, t);
  713.     }
  714.     void message() {
  715.         cout<<text<<endl;
  716.     }
  717. };
  718.  
  719. class Karticka {
  720. protected:
  721.     char smetka[16];
  722.     int pin;
  723.     bool povekjePin;
  724. public:
  725.     Karticka(){
  726.         povekjePin=false;
  727.     }
  728.     Karticka(const char* smetka,int pin) {
  729.         strcpy(this->smetka,smetka);
  730.         this->pin=pin;
  731.         this->povekjePin=false;
  732.     }
  733.     Karticka(const Karticka &k) {
  734.         strcpy(this->smetka,k.smetka);
  735.         this->pin=k.pin;
  736.         this->povekjePin=k.povekjePin;
  737.     }
  738.     char *getSmetka() {
  739.         return smetka;
  740.     }
  741.     virtual bool getDopolnitelenPin() {
  742.         return false;
  743.     }
  744.     virtual int tezhinaProbivanje() {
  745.         int brojac=0;
  746.         int a=pin;
  747.         while(a>0) {
  748.             a/=10;
  749.             brojac++;
  750.         }
  751.         return brojac;
  752.     }
  753.     virtual ~Karticka() {}
  754.  
  755. };
  756.  
  757. ostream &operator << (ostream &os, Karticka *k) {
  758.     os<<k->getSmetka()<<": "<<k->tezhinaProbivanje();
  759.     return os;
  760. }
  761.  
  762. class SpecijalnaKarticka: public Karticka {
  763. private:
  764.     int *pinovi;
  765.     int broj;
  766.     const int P;
  767. public:
  768.     SpecijalnaKarticka():P(4)
  769.     {
  770.         broj=0;
  771.         pinovi=new int[0];
  772.         povekjePin=true;
  773.     }
  774.     SpecijalnaKarticka(const char* smetka, int pin):Karticka(smetka,pin), P(4)  {
  775.         broj=0;
  776.         pinovi=new int[0];
  777.         povekjePin=true;
  778.     }
  779.     SpecijalnaKarticka(const SpecijalnaKarticka &k):Karticka(k), P(4)  {
  780.         broj=k.broj;
  781.         pinovi=new int[broj];
  782.         for(int i=0; i<broj; i++)
  783.             pinovi[i]=k.pinovi[i];
  784.     }
  785.     bool getDopolnitelenPin() {
  786.         return true;
  787.     }
  788.     int tezhinaProbivanje() {
  789.         return Karticka::tezhinaProbivanje()+broj;
  790.     }
  791.     SpecijalnaKarticka &operator += (int n) {
  792.         try {
  793.             if(broj+1>P)
  794.                 throw OutOfBoundException("Brojot na pin kodovi ne moze da go nadmine dozvolenoto");
  795.             int *temp = new int [broj];
  796.             for(int i=0; i<broj; i++)
  797.                 temp[i]=pinovi[i];
  798.             delete [] pinovi;
  799.             pinovi=new int[broj+1];
  800.             for(int i=0; i<broj; i++)
  801.                 pinovi[i]=temp[i];
  802.             pinovi[broj]=n;
  803.             broj++;
  804.             delete [] temp;
  805.         } catch(OutOfBoundException n) {
  806.             n.message();
  807.             return *this;
  808.         }
  809.         return *this;
  810.     }
  811.     ~SpecijalnaKarticka() {
  812.         delete [] pinovi;
  813.     }
  814. };
  815.  
  816.  
  817. class Banka {
  818. private:
  819.     char naziv[30];
  820.     Karticka *karticki[20];
  821.     int broj;
  822.     static int LIMIT;
  823. public:
  824.     Banka(const char *naziv, Karticka** karticki,int broj ) {
  825.         strcpy(this->naziv,naziv);
  826.         for (int i=0; i<broj; i++) {
  827.             //ako kartickata ima dopolnitelni pin kodovi
  828.             if (karticki[i]->getDopolnitelenPin()) {
  829.                 this->karticki[i]=new SpecijalnaKarticka(*dynamic_cast<SpecijalnaKarticka*>(karticki[i]));
  830.             } else this->karticki[i]=new Karticka(*karticki[i]);
  831.         }
  832.         this->broj=broj;
  833.     }
  834.     static void setLIMIT(int n) {
  835.         LIMIT=n;
  836.     }
  837.     void pecatiKarticki() {
  838.         cout<<"Vo bankata "<<naziv<<" moze da se probijat kartickite:"<<endl;
  839.         for(int i=0; i<broj; i++) {
  840.             if(karticki[i]->tezhinaProbivanje()<=LIMIT)
  841.                 cout<<karticki[i]<<endl;
  842.         }
  843.     }
  844.     void dodadiDopolnitelenPin(char * smetka, int novPin) {
  845.         for(int i=0; i<broj; i++) {
  846.             if(karticki[i]->getDopolnitelenPin()&&strcmp(karticki[i]->getSmetka(), smetka)==0)
  847.             {
  848.                 SpecijalnaKarticka *temp=dynamic_cast<SpecijalnaKarticka*>(karticki[i]);
  849.                 *temp+=novPin;
  850.             }
  851.                
  852.  
  853.         }
  854.     }
  855.     ~Banka() {
  856.         for (int i=0; i<broj; i++) delete karticki[i];
  857.     }
  858.  
  859.     //да се дополни класата
  860.  
  861. };
  862. int Banka::LIMIT=7;
  863.  
  864.  
  865. int main() {
  866.  
  867.     Karticka **niza;
  868.     int n,m,pin;
  869.     char smetka[16];
  870.     bool daliDopolnitelniPin;
  871.     cin>>n;
  872.     niza=new Karticka*[n];
  873.     for (int i=0; i<n; i++) {
  874.         cin>>smetka;
  875.         cin>>pin;
  876.         cin>>daliDopolnitelniPin;
  877.         if (!daliDopolnitelniPin)
  878.             niza[i]=new Karticka(smetka,pin);
  879.         else
  880.             niza[i]=new SpecijalnaKarticka(smetka,pin);
  881.     }
  882.  
  883.     Banka komercijalna("Komercijalna",niza,n);
  884.     for (int i=0; i<n; i++) delete niza[i];
  885.     delete [] niza;
  886.     cin>>m;
  887.     for (int i=0; i<m; i++) {
  888.         cin>>smetka>>pin;
  889.  
  890.         komercijalna.dodadiDopolnitelenPin(smetka,pin);
  891.  
  892.     }
  893.  
  894.     Banka::setLIMIT(5);
  895.  
  896.     komercijalna.pecatiKarticki();
  897.  
  898. }
  899.  
  900. //5. Опера и балет
  901. #include<iostream>
  902. #include<string.h>
  903. using namespace std;
  904. class Delo
  905. {
  906.     private:
  907.     char ime[50];
  908.     int godina;
  909.     char zemjaPoteklo[50];
  910.     public:
  911.     Delo(){}
  912.     Delo(char *i,int god,char *zemja)
  913.     {
  914.         strcpy(ime,i);
  915.         godina=god;
  916.         strcpy(zemjaPoteklo,zemja);
  917.        
  918.     }
  919.     Delo(const Delo &d)
  920.     {
  921.        strcpy(ime,d.ime);
  922.        godina=d.godina;
  923.        strcpy(zemjaPoteklo,d.zemjaPoteklo);
  924.     }
  925.     Delo &operator=(const Delo &d)
  926.     {
  927.        strcpy(ime,d.ime);
  928.        godina=d.godina;
  929.        strcpy(zemjaPoteklo,d.zemjaPoteklo);
  930.        return *this;
  931.     }
  932.     bool operator==(Delo &d)
  933.     {
  934.         if(strcmp(ime,d.ime)==0)
  935.         {
  936.             return true;
  937.         }else
  938.         {
  939.             return false;
  940.         }
  941.        
  942.     }
  943.     int getGodina()
  944.     {
  945.         return godina;
  946.     }
  947.     char *getIme()
  948.     {
  949.         return ime;
  950.     }
  951.     char *getZemjaP()
  952.     {
  953.         return zemjaPoteklo;
  954.     }
  955. };
  956.  
  957. class Pretstava
  958. {
  959.     protected:
  960.     Delo d;
  961.     int brojProdadeni;
  962.     char dataPrikaz[15];
  963.     public:
  964.     Pretstava(Delo d1,int broj,char *dataP)
  965.     {
  966.         d=d1;
  967.         brojProdadeni=broj;
  968.         strcpy(dataPrikaz,dataP);
  969.     }
  970.     virtual double cena()
  971.     {
  972.         int M;
  973.         int N;
  974.         if(d.getGodina()>=1900)
  975.         {
  976.             M=50;
  977.         }
  978.         else if(d.getGodina()<1800)
  979.         {
  980.             M=100;
  981.         }else
  982.         {
  983.             M=75;
  984.         }
  985.         if(strcmp(d.getZemjaP(),"Italija")==0)
  986.         {
  987.             N=100;
  988.         }
  989.         else if(strcmp(d.getZemjaP(),"Rusija")==0)
  990.         {
  991.             N=150;
  992.         }
  993.         else
  994.         {
  995.             N=80;
  996.         }
  997.        
  998.         return N+M;
  999.     }
  1000.     Delo getDelo()
  1001.     {
  1002.         return d;
  1003.     }
  1004.     int getProdadeni()
  1005.     {
  1006.         return brojProdadeni;
  1007.     }
  1008. };
  1009.  
  1010. class Balet: public Pretstava
  1011. {
  1012.     private:
  1013.     static int cenaBalet;
  1014.     public:
  1015.     Balet(Delo d1,int broj,char *dataP):Pretstava(d1,broj,dataP){}
  1016.     static void setCenaBalet(int cena)
  1017.     {
  1018.         cenaBalet=cena;
  1019.     }
  1020.     double cena()
  1021.     {
  1022.         return cenaBalet+Pretstava::cena();
  1023.     }
  1024. };
  1025. int Balet::cenaBalet=150;
  1026.  
  1027. class Opera:public Pretstava
  1028. {
  1029.     public:
  1030.     Opera(Delo d1,int broj,char *dataP):Pretstava(d1,broj,dataP){}
  1031.     double cena()
  1032.     {
  1033.         return Pretstava::cena();
  1034.     }
  1035.  
  1036.  
  1037. };
  1038.  
  1039. double prihod(Pretstava **pretstavi,int broj)
  1040. {
  1041.     double vkupenPrihod=0.0;
  1042.     for(int i=0;i<broj;i++)
  1043.     {
  1044.         vkupenPrihod=vkupenPrihod+pretstavi[i]->cena()*pretstavi[i]->getProdadeni();
  1045.     }
  1046.     return vkupenPrihod;
  1047. }
  1048. int brojPretstaviNaDelo(Pretstava **pretstavi,int broj,Delo &d2)
  1049. {
  1050.     int brojac=0;
  1051.     for(int i=0;i<broj;i++)
  1052.     {
  1053.         if(pretstavi[i]->getDelo()==d2)
  1054.         {
  1055.             brojac++;
  1056.         }
  1057.     }
  1058.    
  1059.     return brojac;
  1060. }
  1061.  
  1062. //????? ?? ?????? ???
  1063.  
  1064.  
  1065. //citanje na delo
  1066. Delo readDelo(){
  1067.     char ime[50];
  1068.     int godina;
  1069.     char zemja[50];
  1070.     cin>>ime>>godina>>zemja;
  1071.     return Delo(ime,godina,zemja);
  1072. }
  1073. //citanje na pretstava
  1074. Pretstava* readPretstava(){
  1075.     int tip; //0 za Balet , 1 za Opera
  1076.     cin>>tip;
  1077.     Delo d=readDelo();
  1078.     int brojProdadeni;
  1079.     char data[15];
  1080.     cin>>brojProdadeni>>data;
  1081.     if (tip==0)  return new Balet(d,brojProdadeni,data);
  1082.     else return new Opera(d,brojProdadeni,data);
  1083. }
  1084. int main(){
  1085.     int test_case;
  1086.     cin>>test_case;
  1087.    
  1088.     switch(test_case){
  1089.     case 1:
  1090.     //Testiranje na klasite Opera i Balet
  1091.     {
  1092.         cout<<"======TEST CASE 1======="<<endl;
  1093.         Pretstava* p1=readPretstava();
  1094.         cout<<p1->getDelo().getIme()<<endl;
  1095.         Pretstava* p2=readPretstava();
  1096.         cout<<p2->getDelo().getIme()<<endl;
  1097.     }break;
  1098.        
  1099.     case 2:
  1100.     //Testiranje na  klasite Opera i Balet so cena
  1101.     {
  1102.         cout<<"======TEST CASE 2======="<<endl;
  1103.         Pretstava* p1=readPretstava();
  1104.         cout<<p1->cena()<<endl;
  1105.         Pretstava* p2=readPretstava();
  1106.         cout<<p2->cena()<<endl;
  1107.     }break;
  1108.    
  1109.     case 3:
  1110.     //Testiranje na operator ==
  1111.     {
  1112.         cout<<"======TEST CASE 3======="<<endl;
  1113.         Delo f1=readDelo();
  1114.         Delo f2=readDelo();
  1115.         Delo f3=readDelo();
  1116.        
  1117.         if (f1==f2) cout<<"Isti se"<<endl; else cout<<"Ne se isti"<<endl;
  1118.         if (f1==f3) cout<<"Isti se"<<endl; else cout<<"Ne se isti"<<endl;
  1119.    
  1120.     }break;
  1121.    
  1122.     case 4:
  1123.     //testiranje na funkcijata prihod
  1124.     {
  1125.         cout<<"======TEST CASE 4======="<<endl;
  1126.         int n;
  1127.         cin>>n;
  1128.         Pretstava **pole=new Pretstava*[n];
  1129.         for (int i=0;i<n;i++){
  1130.             pole[i]=readPretstava();
  1131.        
  1132.         }
  1133.         cout<<prihod(pole,n);
  1134.     }break;
  1135.    
  1136.     case 5:
  1137.     //testiranje na prihod so izmena na cena za 3d proekcii
  1138.     {
  1139.         cout<<"======TEST CASE 5======="<<endl;
  1140.         int cenaBalet;
  1141.         cin>>cenaBalet;
  1142.         Balet::setCenaBalet(cenaBalet);
  1143.         int n;
  1144.         cin>>n;
  1145.         Pretstava **pole=new Pretstava*[n];
  1146.         for (int i=0;i<n;i++){
  1147.             pole[i]=readPretstava();
  1148.         }
  1149.         cout<<prihod(pole,n);
  1150.         }break;
  1151.        
  1152.     case 6:
  1153.     //testiranje na brojPretstaviNaDelo
  1154.     {
  1155.         cout<<"======TEST CASE 6======="<<endl;
  1156.         int n;
  1157.         cin>>n;
  1158.         Pretstava **pole=new Pretstava*[n];
  1159.         for (int i=0;i<n;i++){
  1160.             pole[i]=readPretstava();
  1161.         }
  1162.        
  1163.         Delo f=readDelo();
  1164.         cout<<brojPretstaviNaDelo(pole,n,f);
  1165.     }break;
  1166.    
  1167.     };
  1168.  
  1169.  
  1170. return 0;
  1171. }
  1172.  
  1173. //6. Студент
  1174. #include<iostream>
  1175. #include<string.h>
  1176. using namespace std;
  1177.  
  1178. class BadInputException {
  1179. private:
  1180.     char text[100];
  1181. public:
  1182.     BadInputException(const char *t) {
  1183.         strcpy(text, t);
  1184.     }
  1185.     void message() {
  1186.         cout<<text<<endl;
  1187.     }
  1188. };
  1189.  
  1190. class StudentKurs {
  1191. protected:
  1192.     char ime[30];
  1193.     int ocenka;
  1194.     bool daliUsno;
  1195.     static int MAX;
  1196.     const int MINOCENKA;
  1197. public:
  1198.     StudentKurs(char* ime,int finalenIspit):MINOCENKA(6) {
  1199.         strcpy(this->ime,ime);
  1200.         this->ocenka=finalenIspit;
  1201.         this->daliUsno=false;
  1202.     }
  1203.     const int getMIN() const {
  1204.         return MINOCENKA;
  1205.     }
  1206.     static void setMAX(int m) {
  1207.         MAX=m;
  1208.     }
  1209.     virtual bool getDaliUsno() {
  1210.         return daliUsno;
  1211.     }
  1212.     int fOcenka() {
  1213.         return ocenka;
  1214.     }
  1215.     char *getIme() {
  1216.         return ime;
  1217.     }
  1218.     virtual ~StudentKurs() {}
  1219. };
  1220. int StudentKurs::MAX=10;
  1221.  
  1222. ostream &operator << (ostream &os, StudentKurs *s) {
  1223.     os<<s->getIme()<<" --- "<<s->fOcenka();
  1224.     return os;
  1225. }
  1226.  
  1227. class StudentKursUsno: public StudentKurs {
  1228. private:
  1229.     char *opisnaOcenka;
  1230. public:
  1231.     StudentKursUsno(char *ime, int finalenIspit):StudentKurs(ime, finalenIspit) {
  1232.         daliUsno=true;
  1233.     }
  1234.     bool getDaliUsno() {
  1235.         return daliUsno;
  1236.     }
  1237.     StudentKursUsno& operator +=(char *oC) {
  1238.         try {
  1239.             for(int i=0; i<(int)strlen(oC); i++) {
  1240.                 if(!isalpha(oC[i]))
  1241.                     throw BadInputException("Greshna opisna ocenka");
  1242.             }
  1243.         } catch(BadInputException n) {
  1244.             n.message();
  1245.             char temp[100];
  1246.             int j=0;
  1247.             for(int i=0; i<(int)strlen(oC); i++) {
  1248.                 if(isalpha(oC[i]))
  1249.                     temp[j++]=oC[i];
  1250.             }
  1251.             temp[j]=0;
  1252.             if(strcmp(temp, "odlicen")==0&&ocenka<8) {
  1253.                 ocenka+=2;
  1254.             } else if(strcmp(temp, "dobro")==0&&ocenka<9) {
  1255.                 ocenka+=1;
  1256.             } else if(strcmp(temp, "losho")==0&&ocenka>1) {
  1257.                 ocenka-=1;
  1258.             }
  1259.             opisnaOcenka=new char[strlen(temp)+1];
  1260.             strcpy(opisnaOcenka, temp);
  1261.             return *this;
  1262.         }
  1263.         opisnaOcenka=new char[strlen(oC)+1];
  1264.         strcpy(opisnaOcenka, oC);
  1265.         if(strcmp(oC, "odlicen")==0&&ocenka<8) {
  1266.             ocenka+=2;
  1267.         } else if(strcmp(oC, "dobro")==0&&ocenka<9) {
  1268.             ocenka+=1;
  1269.         } else if(strcmp(oC, "losho")==0&&ocenka>1) {
  1270.             ocenka-=1;
  1271.         }
  1272.         return *this;
  1273.  
  1274.     }
  1275.     ~StudentKursUsno() {}
  1276. };
  1277.  
  1278. class KursFakultet {
  1279. private:
  1280.     char naziv[30];
  1281.     StudentKurs *studenti[20];
  1282.     int broj;
  1283.  
  1284. public:
  1285.     KursFakultet(const char *naziv, StudentKurs** studenti,int broj ) {
  1286.         strcpy(this->naziv,naziv);
  1287.         for (int i=0; i<broj; i++) {
  1288.             //ako studentot ima usno isprashuvanje
  1289.             if (studenti[i]->getDaliUsno()) {
  1290.                 this->studenti[i]=new StudentKursUsno(*dynamic_cast<StudentKursUsno*>(studenti[i]));
  1291.             } else
  1292.                 this->studenti[i]=new StudentKurs(*studenti[i]);
  1293.         }
  1294.         this->broj=broj;
  1295.     }
  1296.     void pecatiStudenti() {
  1297.         cout<<"Kursot "<<naziv<<" go polozile:"<<endl;
  1298.         for(int i=0; i<broj; i++) {
  1299.             if(studenti[i]->fOcenka()>=studenti[i]->getMIN())
  1300.                 cout<<studenti[i]<<endl;
  1301.         }
  1302.     }
  1303.     void postaviOpisnaOcenka(char * ime, char* opisnaOcenka) {
  1304.         for(int i=0; i<broj; i++) {
  1305.             StudentKursUsno *temp=dynamic_cast<StudentKursUsno*>(studenti[i]);
  1306.             if(temp!=0) {
  1307.                 if(strcmp(temp->getIme(),ime)==0) {
  1308.                     *temp+=opisnaOcenka;
  1309.                 }
  1310.             }
  1311.         }
  1312.  
  1313.     }
  1314.     ~KursFakultet() {
  1315.         for (int i=0; i<broj; i++)
  1316.             delete studenti[i];
  1317.     }
  1318.  
  1319.  
  1320. };
  1321.  
  1322. int main() {
  1323.  
  1324.     StudentKurs **niza;
  1325.     int n,m,ocenka;
  1326.     char ime[30],opisna[10];
  1327.     bool daliUsno;
  1328.     cin>>n;
  1329.     niza=new StudentKurs*[n];
  1330.     for (int i=0; i<n; i++) {
  1331.         cin>>ime;
  1332.         cin>>ocenka;
  1333.         cin>>daliUsno;
  1334.         if (!daliUsno)
  1335.             niza[i]=new StudentKurs(ime,ocenka);
  1336.         else
  1337.             niza[i]=new StudentKursUsno(ime,ocenka);
  1338.     }
  1339.  
  1340.     KursFakultet programiranje("OOP",niza,n);
  1341.     for (int i=0; i<n; i++)
  1342.         delete niza[i];
  1343.     delete [] niza;
  1344.     cin>>m;
  1345.  
  1346.     for (int i=0; i<m; i++) {
  1347.         cin>>ime>>opisna;
  1348.         programiranje.postaviOpisnaOcenka(ime,opisna);
  1349.     }
  1350.  
  1351.     StudentKurs::setMAX(9);
  1352.  
  1353.     programiranje.pecatiStudenti();
  1354.  
  1355. }
  1356.  
  1357. //7. Паркинг
  1358. #include<iostream>
  1359. #include<cstring>
  1360.  
  1361. using namespace std;
  1362.  
  1363. class Avtomobil
  1364. {
  1365. private:
  1366.     char color[50];
  1367.     char model[50];
  1368.     char brand [50];
  1369. public:
  1370.     Avtomobil(){}
  1371.     Avtomobil(const char *boja, const char *brend, const char *m)
  1372.     {
  1373.         strcpy(color, boja);
  1374.         strcpy(brand, brend);
  1375.         strcpy(model, m);
  1376.     }
  1377.     Avtomobil(const Avtomobil &a)
  1378.     {
  1379.         strcpy(color, a.color);
  1380.         strcpy(brand, a.brand);
  1381.         strcpy(model, a.model);
  1382.     }
  1383.     Avtomobil &operator = (const Avtomobil &a)
  1384.     {
  1385.         strcpy(color, a.color);
  1386.         strcpy(brand, a.brand);
  1387.         strcpy(model, a.model);
  1388.         return *this;
  1389.     }
  1390.     void print()
  1391.     {
  1392.         cout<<color<<" "<<brand<<" "<<model<<endl;
  1393.     }
  1394. };
  1395.  
  1396. class ParkingPlac
  1397. {
  1398. private:
  1399.     char adresa[20];
  1400.     char *ID;
  1401.     int cena;
  1402.     int zarabotka;
  1403.     int brojVozila;
  1404.     Avtomobil *avtomobili;
  1405. public:
  1406.     ParkingPlac()
  1407.     {
  1408.         ID=new char[0];
  1409.         cena=0;
  1410.         avtomobili=new Avtomobil[0];
  1411.         brojVozila=0;
  1412.         zarabotka=0;
  1413.     }
  1414.     ParkingPlac(const char *addr, const char *id, int c)
  1415.     {
  1416.         ID=new char[strlen(id)+1];
  1417.         strcpy(ID, id);
  1418.         strcpy(adresa, addr);
  1419.         cena=c;
  1420.         avtomobili=new Avtomobil[0];
  1421.         brojVozila=0;
  1422.         zarabotka=0;
  1423.     }
  1424.     ParkingPlac (const ParkingPlac &p)
  1425.     {
  1426.         ID=new char[strlen(p.ID)+1];
  1427.         strcpy(ID, p.ID);
  1428.         strcpy(adresa, p.adresa);
  1429.         cena=p.cena;
  1430.         avtomobili=new Avtomobil[p.brojVozila];
  1431.         brojVozila=p.brojVozila;
  1432.         for(int i=0; i<brojVozila; i++)
  1433.         {
  1434.             avtomobili[i]=p.avtomobili[i];
  1435.         }
  1436.         zarabotka=p.zarabotka;
  1437.  
  1438.     }
  1439.     ParkingPlac &operator = (const ParkingPlac &p)
  1440.     {
  1441.         delete [] ID;
  1442.         ID=new char[strlen(p.ID)+1];
  1443.         strcpy(ID, p.ID);
  1444.         strcpy(adresa, p.adresa);
  1445.         cena=p.cena;
  1446.         delete [] avtomobili;
  1447.         avtomobili=new Avtomobil[p.brojVozila];
  1448.         brojVozila=p.brojVozila;
  1449.         for(int i=0; i<brojVozila; i++)
  1450.         {
  1451.             avtomobili[i]=p.avtomobili[i];
  1452.         }
  1453.         zarabotka=p.zarabotka;
  1454.         return *this;
  1455.     }
  1456.     void parkirajVozilo(Avtomobil novoVozilo)
  1457.     {
  1458.         Avtomobil *temp=new Avtomobil[brojVozila];
  1459.         for(int i=0; i<brojVozila; i++)
  1460.         {
  1461.             temp[i]=avtomobili[i];
  1462.         }
  1463.         delete [] avtomobili;
  1464.         avtomobili=new Avtomobil[brojVozila+1];
  1465.         for(int i=0; i<brojVozila; i++)
  1466.         {
  1467.             avtomobili[i]=temp[i];
  1468.         }
  1469.         avtomobili[brojVozila++]=novoVozilo;
  1470.         delete [] temp;
  1471.     }
  1472.     char* getId()
  1473.     {
  1474.         return ID;
  1475.     }
  1476.     void pecati()
  1477.     {
  1478.         if(zarabotka!=0)
  1479.             cout<<ID<<" "<<adresa<<" - "<<zarabotka<<" denari"<<endl;
  1480.         else
  1481.             cout<<ID<<" "<<adresa<<" "<<endl;
  1482.     }
  1483.     void pecatiParkiraniVozila()
  1484.     {
  1485.         cout<<"Vo parkingot se parkirani slednite vozila: "<<endl;
  1486.         for(int i=0; i<brojVozila; i++)
  1487.         {
  1488.             cout<<i+1<<".";
  1489.             avtomobili[i].print();
  1490.         }
  1491.     }
  1492.     void platiCasovi(int casovi)
  1493.     {
  1494.         zarabotka+=casovi*cena;
  1495.     }
  1496.     bool daliIstaAdresa(ParkingPlac p)
  1497.     {
  1498.         return(strcmp(adresa, p.adresa)==0);
  1499.     }
  1500.     ~ParkingPlac()
  1501.     {
  1502.         delete [] ID;
  1503.         delete [] avtomobili;
  1504.     }
  1505. };
  1506.  
  1507. int main(){
  1508.  
  1509.     ParkingPlac p[100];
  1510.     int n,m;
  1511.     char adresa[50],id[50];
  1512.     int brojcasovi,cenacas;
  1513.     cin>>n;
  1514.     if(n > 0){
  1515.  
  1516.  
  1517.         for (int i=0;i<n;i++){
  1518.             cin.get();
  1519.             cin.getline(adresa,50);
  1520.             cin>>id>>cenacas;
  1521.  
  1522.             ParkingPlac edna(adresa,id,cenacas);
  1523.  
  1524.             //povik na operatorot =
  1525.             p[i]=edna;
  1526.         }
  1527.  
  1528.         //plakjanje
  1529.         cin>>m;
  1530.         for (int i=0;i<m;i++){
  1531.  
  1532.             cin>>id>>brojcasovi;
  1533.  
  1534.             int findId=false;
  1535.             for (int j=0;j<m;j++){
  1536.                 if (strcmp(p[j].getId(),id)==0){
  1537.                     p[j].platiCasovi(brojcasovi);
  1538.                     findId=true;
  1539.                 }
  1540.             }
  1541.             if (!findId)
  1542.             cout<<"Ne e platen parking. Greshen ID."<<endl;
  1543.         }
  1544.  
  1545.         cout<<"========="<<endl;
  1546.         ParkingPlac pCentar("Cvetan Dimov","C10",80);
  1547.         for (int i=0;i<n;i++)
  1548.             if (p[i].daliIstaAdresa(pCentar))
  1549.                 p[i].pecati();
  1550.     } else {
  1551.  
  1552.         ParkingPlac najdobarPlac("Mars", "1337", 1);
  1553.         int brVozila;
  1554.         cin >> brVozila;
  1555.         for(int i = 0; i < brVozila; ++i){
  1556.  
  1557.             char boja[20];
  1558.             char brend[20];
  1559.             char model[20];
  1560.  
  1561.             cin >> boja >> brend >> model;
  1562.             Avtomobil novAvtomobil(boja, brend, model);
  1563.             najdobarPlac.parkirajVozilo(novAvtomobil);
  1564.         }
  1565.         if(brVozila != 0)
  1566.         najdobarPlac.pecatiParkiraniVozila();
  1567.  
  1568.     }
  1569. }
  1570.  
  1571.  
  1572. //8. DVD
  1573. #include<iostream>
  1574. #include<cstring>
  1575.  
  1576. using namespace std;
  1577.  
  1578. enum zanr {
  1579.     akcija, komedija, drama
  1580. };
  1581.  
  1582. class Film {
  1583.     private:
  1584.     char * ime;
  1585.     int memorija;
  1586.     zanr zanrFilm;
  1587.    
  1588.     void copy(const Film &f){
  1589.         this->ime = new char [strlen(f.ime)+1];
  1590.         strcpy(this->ime,f.ime);
  1591.         this->memorija=f.memorija;
  1592.         this->zanrFilm=f.zanrFilm;
  1593.     }
  1594.    
  1595.     public:
  1596.     Film(char * ime = "", int memorija=0, zanr zanrFilm = akcija){
  1597.         this->ime = new char [strlen(ime)+1];
  1598.         strcpy(this->ime,ime);
  1599.         this->memorija=memorija;
  1600.         this->zanrFilm=zanrFilm;
  1601.     }
  1602.    
  1603.     Film(const Film &f){
  1604.         copy(f);
  1605.     }
  1606.    
  1607.     ~Film() {
  1608.         delete ime;
  1609.     }
  1610.    
  1611.     Film &operator = (const Film &f){
  1612.         if (this!=&f){
  1613.             delete ime;
  1614.             copy(f);
  1615.         }
  1616.         return *this;
  1617.     }
  1618.    
  1619.     void pecati() {
  1620.         cout<<memorija<<"MB-"<<"\""<<ime<<"\""<<endl;
  1621.     }
  1622.    
  1623.     int getMemorija() {
  1624.         return memorija;
  1625.     }
  1626.    
  1627.     zanr getZhanr() {
  1628.         return zanrFilm;
  1629.     }
  1630.    
  1631.    
  1632. };
  1633.  
  1634. class DVD {
  1635.     private:
  1636.     Film filmovi[5];
  1637.     int broj;
  1638.     int kapacitet;
  1639.     int momentalno;
  1640.    
  1641.     public:
  1642.     DVD(int kapacitet){
  1643.         this->kapacitet=kapacitet;
  1644.         broj=0;
  1645.         momentalno=0;
  1646.     }
  1647.    
  1648.     void dodadiFilm(Film f) {
  1649.         if (momentalno+f.getMemorija()<=kapacitet&&broj<5){
  1650.             filmovi[broj++]=f;
  1651.             momentalno+=f.getMemorija();
  1652.         }
  1653.     }
  1654.    
  1655.     void pecatiFilmoviDrugZanr(const zanr r){
  1656.         for (int i=0;i<broj;i++){
  1657.            // cout<<filmovi[i].pecati()<<" "<<r<<" "<<
  1658.             if (filmovi[i].getZhanr()!=r)
  1659.                 filmovi[i].pecati();
  1660.         }
  1661.     }
  1662.    
  1663.     int getBroj() {
  1664.         return broj;
  1665.     }
  1666.    
  1667.     Film getFilm (int i){
  1668.         return filmovi[i];
  1669.     }
  1670.    
  1671.     float procentNaMemorijaOdZanr(zanr r){
  1672.         float sum = 0.0;
  1673.         for (int i=0;i<broj;i++)
  1674.             if (filmovi[i].getZhanr()==r)
  1675.                 sum+=filmovi[i].getMemorija();
  1676.            
  1677.         return sum / momentalno * 100.0;
  1678.     }
  1679. };
  1680.  
  1681.  
  1682. int main() {
  1683.     // se testira zadacata modularno
  1684.     int testCase;
  1685.     cin >> testCase;
  1686.  
  1687.     int n, memorija, kojzanr;
  1688.     char ime[50];
  1689.  
  1690.     if (testCase == 1) {
  1691.         cout << "===== Testiranje na klasata Film ======" << endl;
  1692.         cin >> ime;
  1693.         cin >> memorija;
  1694.         cin >> kojzanr; //se vnesuva 0 za AKCIJA,1 za KOMEDIJA i 2 za DRAMA
  1695.         Film f(ime, memorija, (zanr) kojzanr);
  1696.         f.pecati();
  1697.     } else if (testCase == 2) {
  1698.         cout << "===== Testiranje na klasata DVD ======" << endl;
  1699.         DVD omileno(50);
  1700.         cin >> n;
  1701.         for (int i = 0; i < n; i++) {
  1702.             cin >> ime;
  1703.             cin >> memorija;
  1704.             cin >> kojzanr; //se vnesuva 0 za AKCIJA,1 za KOMEDIJA i 2 za DRAMA
  1705.             Film f(ime, memorija, (zanr) kojzanr);
  1706.             omileno.dodadiFilm(f);
  1707.         }
  1708.         for (int i = 0; i < n; i++)
  1709.             (omileno.getFilm(i)).pecati();
  1710.     } else if (testCase == 3) {
  1711.         cout << "===== Testiranje na metodot dodadiFilm() od klasata DVD ======" << endl;
  1712.         DVD omileno(50);
  1713.         cin >> n;
  1714.         for (int i = 0; i < n; i++) {
  1715.             cin >> ime;
  1716.             cin >> memorija;
  1717.             cin >> kojzanr; //se vnesuva 0 za AKCIJA,1 za KOMEDIJA i 2 za DRAMA
  1718.             Film f(ime, memorija, (zanr) kojzanr);
  1719.             omileno.dodadiFilm(f);
  1720.         }
  1721.         for (int i = 0; i < omileno.getBroj(); i++)
  1722.             (omileno.getFilm(i)).pecati();
  1723.     } else if (testCase == 4) {
  1724.         cout << "===== Testiranje na metodot pecatiFilmoviDrugZanr() od klasata DVD ======" << endl;
  1725.         DVD omileno(50);
  1726.         cin >> n;
  1727.         for (int i = 0; i < n; i++) {
  1728.             cin >> ime;
  1729.             cin >> memorija;
  1730.             cin >> kojzanr; //se vnesuva 0 za AKCIJA,1 za KOMEDIJA i 2 za DRAMA
  1731.             Film f(ime, memorija, (zanr) kojzanr);
  1732.             omileno.dodadiFilm(f);
  1733.         }
  1734.         cin >> kojzanr;
  1735.         omileno.pecatiFilmoviDrugZanr((zanr) kojzanr);
  1736.  
  1737.     } else if (testCase == 5) {
  1738.         cout << "===== Testiranje na metodot pecatiFilmoviDrugZanr() od klasata DVD ======" << endl;
  1739.         DVD omileno(50);
  1740.         cin >> n;
  1741.         for (int i = 0; i < n; i++) {
  1742.             cin >> ime;
  1743.             cin >> memorija;
  1744.             cin >> kojzanr; //se vnesuva 0 za AKCIJA,1 za KOMEDIJA i 2 za DRAMA
  1745.             Film f(ime, memorija, (zanr) kojzanr);
  1746.             omileno.dodadiFilm(f);
  1747.         }
  1748.         cin >> kojzanr;
  1749.         omileno.pecatiFilmoviDrugZanr((zanr) kojzanr);
  1750.  
  1751.     } else if (testCase == 6){
  1752.         cout<<"===== Testirawe na metodot procentNaMemorijaOdZanr() od klasata DVD =====" <<endl;
  1753.         DVD omileno(40);
  1754.         cin >> n;
  1755.         for (int i = 0; i < n; i++) {
  1756.             cin >> ime;
  1757.             cin >> memorija;
  1758.             cin >> kojzanr; //se vnesuva 0 za AKCIJA,1 za KOMEDIJA i 2 za DRAMA
  1759.             Film f(ime, memorija, (zanr) kojzanr);
  1760.             omileno.dodadiFilm(f);
  1761.         }
  1762.         cin >> kojzanr;
  1763.         cout<<"Procent na filmovi od dadeniot zanr iznesuva: "<<omileno.procentNaMemorijaOdZanr((zanr) kojzanr)<<"%\n";
  1764.        
  1765.     }
  1766.  
  1767.     return 0;
  1768. }
  1769. //9. Репозиториум на оперативни системи
  1770. #include <iostream>
  1771. #include <cstring>
  1772.  
  1773. using namespace std;
  1774.  
  1775. enum tip{LINUX, UNIX, WINDOWS};
  1776.  
  1777. class OperativenSistem
  1778. {
  1779.     char *ime;
  1780.     float verzija;
  1781.     tip t;
  1782.     float golemina;
  1783. public:
  1784.     OperativenSistem()
  1785.     {
  1786.         ime=new char[0];
  1787.     }
  1788.     OperativenSistem(char *i, float v, tip t1, float g)
  1789.     {
  1790.         ime=new char[strlen(i)+1];
  1791.         strcpy(ime,i);
  1792.         verzija=v;
  1793.         t=t1;
  1794.         golemina=g;
  1795.     }
  1796.     OperativenSistem(const OperativenSistem &o)
  1797.     {
  1798.         ime=new char[strlen(o.ime)+1];
  1799.         strcpy(ime,o.ime);
  1800.         verzija=o.verzija;
  1801.         t=o.t;
  1802.         golemina=o.golemina;
  1803.     }
  1804.     OperativenSistem& operator = (const OperativenSistem &o)
  1805.     {
  1806.         delete [] ime;
  1807.         ime=new char[strlen(o.ime)+1];
  1808.         strcpy(ime,o.ime);
  1809.         verzija=o.verzija;
  1810.         t=o.t;
  1811.         golemina=o.golemina;
  1812.         return *this;
  1813.     }
  1814.     void pecati()
  1815.     {
  1816.         cout<<"Ime: "<<ime<< " Verzija: "<<verzija<< " Tip: "<<t<< " Golemina:"<<golemina<<"GB"<<endl;
  1817.     }
  1818.     bool ednakviSe (const OperativenSistem &os)
  1819.     {
  1820.         return (strcmp(ime, os.ime)==0&&verzija==os.verzija&&t==os.t && golemina==os.golemina);
  1821.     }
  1822.     int sporediVerzija(const OperativenSistem &os)
  1823.     {
  1824.         if(verzija==os.verzija)
  1825.             return 0;
  1826.         else if(verzija<os.verzija)
  1827.             return -1;
  1828.         else return 1;
  1829.     }
  1830.     bool istaFamilija(const OperativenSistem &sporedba)
  1831.     {
  1832.         return (strcmp(ime, sporedba.ime)==0 && t==sporedba.t);
  1833.     }
  1834.     ~OperativenSistem()
  1835.     {
  1836.         delete[]ime;
  1837.     }
  1838.    
  1839. };
  1840.  
  1841. class Repozitorium
  1842. {
  1843.     char ime[20];
  1844.     OperativenSistem *os;
  1845.     int broj;
  1846. public:
  1847.     Repozitorium(const char *ime)
  1848.     {
  1849.         strcpy(this->ime, ime);
  1850.         os=new OperativenSistem[0];
  1851.         broj=0;
  1852.     }
  1853.     Repozitorium(const Repozitorium &r)
  1854.     {
  1855.         strcpy(ime, r.ime);
  1856.         os=new OperativenSistem[r.broj];
  1857.         for(int i=0; i<r.broj; i++)
  1858.         {
  1859.             os[i]=r.os[i];
  1860.         }
  1861.         broj=r.broj;
  1862.     }
  1863.     void pecatiOperativniSistemi()
  1864.     {  
  1865.         cout<<"Repozitorium: "<<ime<<endl;
  1866.         for(int i=0; i<broj; i++)
  1867.         {
  1868.             os[i].pecati();
  1869.         }
  1870.     }
  1871.     void izbrishi(const OperativenSistem &operativenSistem)
  1872.     {
  1873.         OperativenSistem *temp=new OperativenSistem[broj];
  1874.         int j=0;
  1875.         for(int i=0; i<broj; i++)
  1876.         {
  1877.             if(!os[i].ednakviSe(operativenSistem))
  1878.             {
  1879.                 temp[j]=os[i];
  1880.                 j++;
  1881.             }
  1882.         }
  1883.         delete [] os;
  1884.         os=new OperativenSistem[j];
  1885.         for(int i=0; i<j; i++)
  1886.         {
  1887.             os[i]=temp[i];
  1888.         }
  1889.         broj=j;
  1890.         delete [] temp;
  1891.     }
  1892.     void dodadi(const OperativenSistem &nov)
  1893.     {
  1894.         bool flag = true;
  1895.         for(int i=0; i<broj; i++)
  1896.         {
  1897.             if(os[i].istaFamilija(nov) && os[i].sporediVerzija(nov)==-1)
  1898.             {
  1899.                 os[i]=nov;
  1900.                 flag=false;
  1901.             }
  1902.         }
  1903.         if(flag)
  1904.         {
  1905.             OperativenSistem *temp=new OperativenSistem[broj];
  1906.             for(int i=0; i<broj; i++)
  1907.             {
  1908.                 temp[i]=os[i];
  1909.             }
  1910.             delete [] os;
  1911.             os=new OperativenSistem[broj+1];
  1912.             for(int i=0; i<broj; i++)
  1913.             {
  1914.                 os[i]=temp[i];
  1915.             }
  1916.             os[broj]=nov;
  1917.             broj++;
  1918.             delete [] temp;
  1919.            
  1920.         }
  1921.     }
  1922.     ~Repozitorium()
  1923.     {
  1924.         delete [] os;
  1925.     }
  1926. };
  1927.  
  1928. int main() {
  1929.     char repoName[20];
  1930.     cin>>repoName;
  1931.     Repozitorium repozitorium=Repozitorium(repoName);
  1932.     int brojOperativniSistemi = 0;
  1933.     cin>>brojOperativniSistemi;
  1934.     char ime[20];
  1935.     float verzija;
  1936.     int t;
  1937.     float golemina;
  1938.     for (int i = 0; i<brojOperativniSistemi; i++){
  1939.         cin>>ime;
  1940.         cin>>verzija;
  1941.         cin>>t;
  1942.         cin>>golemina;
  1943.         OperativenSistem os = OperativenSistem(ime, verzija, (tip)t, golemina);
  1944.         repozitorium.dodadi(os);
  1945.     }
  1946.  
  1947.     repozitorium.pecatiOperativniSistemi();
  1948.      cin>>ime;
  1949.     cin>>verzija;
  1950.     cin>>t;
  1951.     cin>>golemina;
  1952.     OperativenSistem os = OperativenSistem(ime, verzija, (tip)t, golemina);
  1953.     cout<<"=====Brishenje na operativen sistem====="<<endl;
  1954.     repozitorium.izbrishi(os);
  1955.     repozitorium.pecatiOperativniSistemi();
  1956.     return 0;
  1957. }
  1958. //10. ListContainer
  1959. #include<iostream>
  1960. using namespace std;
  1961.  
  1962. class List {
  1963.  
  1964. private:
  1965.  
  1966.   int * numbers;
  1967.   int numNumbers;
  1968.  
  1969.   void copy(const List& l) {
  1970.     numNumbers = l.numNumbers;
  1971.     numbers = new int[numNumbers];
  1972.     for (int i = 0; i < numNumbers; ++i) {
  1973.       numbers[i] = l.numbers[i];
  1974.     }
  1975.   }
  1976.  
  1977. public:
  1978.  
  1979.  
  1980.   List() {
  1981.     numbers = new int[0];
  1982.     numNumbers = 0;
  1983.   }
  1984.  
  1985.   List(int * lista, int broj) {
  1986.  
  1987.     numNumbers = broj;
  1988.     numbers = new int[numNumbers];
  1989.     for (int i = 0; i < numNumbers; ++i) {
  1990.       numbers[i] = lista[i];
  1991.     }
  1992.   }
  1993.  
  1994.   ~List() {
  1995.     delete [] numbers;
  1996.   }
  1997.  
  1998.   List(const List& l) {
  1999.     copy(l);
  2000.   }
  2001.  
  2002.   List & operator = (const List& l) {
  2003.     if (this != &l) {
  2004.       delete [] numbers;
  2005.       copy(l);
  2006.     }
  2007.     return *this;
  2008.   }
  2009.  
  2010.   int sum() {
  2011.     int suma = 0;
  2012.     for (int i=0; i < numNumbers; ++i) {
  2013.       suma += numbers[i];
  2014.     }
  2015.     return suma;
  2016.   }
  2017.  
  2018.   double average() {
  2019.     return sum() * 1.0 / numNumbers;
  2020.   }
  2021.  
  2022.   void pecati() {
  2023.     cout << numNumbers << ": ";
  2024.     for (int i=0; i < numNumbers; ++i) {
  2025.       cout << numbers[i] << " ";
  2026.     }
  2027.     cout << "sum: " << sum();
  2028.     cout << " average: " << average();
  2029.   }
  2030.  
  2031.   int getNumber() {
  2032.     return numNumbers;
  2033.   }
  2034. };
  2035.  
  2036. class ListContainer {
  2037.  
  2038. private:
  2039.   List * listi;
  2040.   int numListi;
  2041.   int attempts;
  2042.  
  2043.   void copy(const ListContainer &lc) {
  2044.  
  2045.     numListi = lc.numListi;
  2046.     attempts = lc.attempts;
  2047.     listi = new List[numListi];
  2048.     for (int i=0; i < numListi; ++i) {
  2049.       listi[i] = lc.listi[i];
  2050.     }
  2051.   }
  2052.  
  2053. public:
  2054.   ListContainer() {
  2055.     listi = new List[0];
  2056.     numListi = 0;
  2057.     attempts = 0;
  2058.   }
  2059.  
  2060.   ~ListContainer() {
  2061.     delete [] listi;
  2062.   }
  2063.  
  2064.   ListContainer(const ListContainer &lc) {
  2065.     copy(lc);
  2066.   }
  2067.  
  2068.   ListContainer & operator =(const ListContainer &lc) {
  2069.     if (this != &lc) {
  2070.       delete [] listi;
  2071.       copy(lc);
  2072.     }
  2073.     return *this;
  2074.   }
  2075.  
  2076.   int sum() {
  2077.     int suma = 0;
  2078.     for (int i=0; i < numListi; ++i){
  2079.       suma += listi[i].sum();
  2080.     }
  2081.     return suma;
  2082.   }
  2083.  
  2084.   double average() {
  2085.     int suma = sum();
  2086.     int numElements = 0;
  2087.     for (int i=0; i < numListi; ++i) {
  2088.       numElements += listi[i].getNumber();
  2089.     }
  2090.     return suma / (numElements * 1.0);
  2091.   }
  2092.  
  2093.   void addNewList(List l){
  2094.     ++attempts;
  2095.     for (int i=0; i < numListi; ++i) {
  2096.       if (l.sum() == listi[i].sum()){
  2097.         return;
  2098.       }
  2099.     }
  2100.  
  2101.     List * tmp = new List[numListi + 1];
  2102.     for (int i=0; i < numListi; ++i) {
  2103.       tmp[i] = listi[i];
  2104.     }
  2105.  
  2106.     tmp[numListi++] = l;
  2107.     delete [] listi;
  2108.     listi = tmp;
  2109.   }
  2110.  
  2111.   void print() {
  2112.     if (!numListi) {
  2113.       cout << "The list is empty\n";
  2114.         return;
  2115.     }
  2116.     else {
  2117.       for (int i = 0; i < numListi; ++i) {
  2118.         cout << "List number: " << i + 1 << " List info: ";
  2119.         listi[i].pecati();
  2120.         cout << endl;
  2121.       }
  2122.     }
  2123.     cout << "Sum: " << sum();
  2124.     cout << " Average: " << average() << endl;
  2125.     cout << "Successful attempts: " << numListi << " Failed attempts: " << attempts - numListi<< endl;
  2126.  
  2127.   }
  2128.  
  2129. };
  2130.  
  2131.  
  2132. int main() {
  2133.  
  2134.     ListContainer lc;
  2135.     int N;
  2136.     cin>>N;
  2137.  
  2138.     for (int i=0;i<N;i++) {
  2139.         int n;
  2140.         int niza[100];
  2141.  
  2142.         cin>>n;
  2143.  
  2144.         for (int j=0;j<n;j++){
  2145.             cin>>niza[j];
  2146.  
  2147.         }
  2148.  
  2149.         List l=List(niza,n);
  2150.  
  2151.         lc.addNewList(l);
  2152.     }
  2153.  
  2154.  
  2155.     int testCase;
  2156.     cin>>testCase;
  2157.  
  2158.     if (testCase==1) {
  2159.         cout<<"Test case for operator ="<<endl;
  2160.         ListContainer lc1;
  2161.         lc1.print();
  2162.         cout<<lc1.sum()<<" "<<lc.sum()<<endl;
  2163.         lc1=lc;
  2164.         lc1.print();
  2165.         cout<<lc1.sum()<<" "<<lc.sum()<<endl;
  2166.  
  2167.     }
  2168.     else {
  2169.         lc.print();
  2170.     }
  2171. }
  2172.  
  2173. //11. Жичани инструменти
  2174. #include<iostream>
  2175. #include<cstring>
  2176.  
  2177. using namespace std;
  2178.  
  2179. class ZicanInstrument
  2180. {
  2181. protected:
  2182.     char ime[20];
  2183.     int zhici;
  2184.     int price;
  2185. public:
  2186.     ZicanInstrument(){}
  2187.     ZicanInstrument(char *i, int z, int c)
  2188.     {
  2189.         strcpy(ime, i);
  2190.         zhici=z;
  2191.         price=c;
  2192.     }
  2193.     ZicanInstrument(ZicanInstrument *z)
  2194.     {
  2195.         strcpy(ime, z->ime);
  2196.         zhici=z->zhici;
  2197.         price=z->price;
  2198.     }
  2199.     int getZhici()
  2200.     {
  2201.         return zhici;
  2202.     }
  2203.     virtual double cena() = 0;
  2204.     virtual ~ZicanInstrument(){}
  2205. };
  2206.  
  2207. bool operator == (ZicanInstrument &z1, ZicanInstrument *z2)
  2208. {
  2209.     return z1.getZhici()==z2->getZhici();
  2210. }
  2211.  
  2212. ostream &operator << (ostream &os, ZicanInstrument *z)
  2213. {
  2214.     os<<z->cena();
  2215.     return os;
  2216. }
  2217.  
  2218. class Mandolina: public ZicanInstrument
  2219. {
  2220. private:
  2221.     char forma[20];
  2222. public:
  2223.     Mandolina():ZicanInstrument(){}
  2224.     Mandolina(char *i, int z, int c, char *f):ZicanInstrument(i, z, c)
  2225.     {
  2226.         strcpy(forma, f);
  2227.     }
  2228.     Mandolina(Mandolina *p):ZicanInstrument(p)
  2229.     {
  2230.         strcpy(forma,p->forma);
  2231.     }
  2232.     double cena()
  2233.     {
  2234.         if(strcmp(forma,"Neapolitan")==0)
  2235.             return price+15*price/100.00;
  2236.         else return price;
  2237.     }
  2238. };
  2239.  
  2240. class Violina: public ZicanInstrument
  2241. {
  2242. private:
  2243.     double golemina;
  2244. public:
  2245.     Violina():ZicanInstrument(){}
  2246.     Violina(char *i, int z, int c, double g):ZicanInstrument(i, z, c)
  2247.     {
  2248.         golemina=g;
  2249.     }
  2250.     Violina(Violina *v):ZicanInstrument(v)
  2251.     {
  2252.         golemina=v->golemina;
  2253.     }
  2254.     double cena()
  2255.     {
  2256.         if(golemina==0.25)
  2257.             return price+10*price/100.00;
  2258.         else if(golemina==1.00)
  2259.             return price+20*price/100.00;
  2260.         else
  2261.             return price;
  2262.     }
  2263. };
  2264.  
  2265. void pecatiInstrumenti(ZicanInstrument &zi, ZicanInstrument **i, int n)
  2266. {
  2267.     for(int j=0; j<n; j++)
  2268.     {
  2269.         if(zi==i[j])
  2270.         {
  2271.             cout<<i[j]<<endl;
  2272.         }
  2273.     }
  2274. }
  2275.  
  2276. int main() {
  2277.     char ime[20];
  2278.     int brojZici;
  2279.     float cena;
  2280.     char forma[20];
  2281.     cin >> ime >> brojZici >> cena >> forma;
  2282.     Mandolina m(ime, brojZici, cena, forma);
  2283.     int n;
  2284.     cin >> n;
  2285.     ZicanInstrument **zi = new ZicanInstrument*[2 * n];
  2286.     for(int i = 0; i < n; ++i) {
  2287.         cin >> ime >> brojZici >> cena >> forma;
  2288.         zi[i] = new Mandolina(ime, brojZici, cena, forma);
  2289.     }
  2290.     for(int i = 0; i < n; ++i) {
  2291.         float golemina;
  2292.         cin >> ime >> brojZici >> cena >> golemina;
  2293.         zi[n + i] = new Violina(ime, brojZici, cena, golemina);
  2294.     }
  2295.     pecatiInstrumenti(m, zi, 2 * n);
  2296.     for(int i = 0; i < 2 * n; ++i) {
  2297.         delete zi[i];
  2298.     }
  2299.     delete [] zi;
  2300.     return 0;
  2301. }
  2302.  
  2303. //12. Игротека
  2304. #include <iostream>
  2305. #include<cstring>
  2306. #include<cmath>
  2307.  
  2308. using namespace std;
  2309.  
  2310. class Igrachka
  2311. {
  2312. protected:
  2313.     char *boja;
  2314.     int gustina;
  2315. public:
  2316.     Igrachka()
  2317.     {
  2318.         boja=new char[0];
  2319.     }
  2320.     Igrachka(char *b, int g)
  2321.     {
  2322.         boja=new char[strlen(b)+1];
  2323.         strcpy(boja, b);
  2324.         gustina=g;
  2325.     }
  2326.     virtual double getMasa()=0;
  2327.     virtual double getVolumen()=0;
  2328.     virtual double getPlostina()=0;
  2329.     virtual ~Igrachka()
  2330.     {
  2331.         delete [] boja;
  2332.     }
  2333. };
  2334. class Forma
  2335. {
  2336. public:
  2337.     virtual double getMasa()=0;
  2338.     virtual double getVolumen()=0;
  2339. };
  2340.  
  2341. class Topka: public Igrachka, public Forma
  2342. {
  2343. private:
  2344.     int radius;
  2345. public:
  2346.     Topka(){}
  2347.     Topka(char *b, int g, int r):Igrachka(b, g),Forma()
  2348.     {
  2349.         radius=r;
  2350.     }
  2351.     double getVolumen()
  2352.     {
  2353.         return 4/3.0*radius*radius*radius*3.14;
  2354.     }
  2355.     double  getMasa()
  2356.     {
  2357.         return gustina*getVolumen();
  2358.     }
  2359.     double getPlostina()
  2360.     {
  2361.         return 4*radius*radius*3.14;
  2362.     }
  2363. };
  2364. class Kocka: public Igrachka, public Forma
  2365. {
  2366. private:
  2367.     int a;
  2368.     int b;
  2369.     int c;
  2370. public:
  2371.     Kocka(){}
  2372.     Kocka(char *b, int g, int aa, int bb, int cc):Igrachka(b, g),Forma()
  2373.     {
  2374.         a=aa;
  2375.         this->b=bb;
  2376.         c=cc;
  2377.     }
  2378.     double getVolumen()
  2379.     {
  2380.         return a*b*c;
  2381.     }
  2382.     double  getMasa()
  2383.     {
  2384.         return gustina*getVolumen();
  2385.     }
  2386.     double getPlostina()
  2387.     {
  2388.         return 2*(a*b+a*c+b*c);
  2389.     }
  2390. };
  2391.  
  2392. int main()
  2393. {
  2394.     int k,n,visina,shirina,dlabocina,radius,gustina;
  2395.     char boja[50];
  2396.     cin>>n;
  2397.     Igrachka **kupche=new Igrachka*[n];
  2398.     for(int i=0; i<n; i++)
  2399.     {
  2400.         cin>>k;
  2401.         if(k==1)
  2402.         {
  2403.             cin>>boja>>gustina>>radius;
  2404.             kupche[i]=new Topka(boja,gustina,radius);
  2405.         }
  2406.         if(k==2)
  2407.         {
  2408.             cin>>boja>>gustina>>visina>>shirina>>dlabocina;
  2409.             kupche[i]=new Kocka(boja,gustina,visina,shirina,dlabocina);
  2410.         }
  2411.     }
  2412.     cin>>boja>>gustina>>visina>>shirina>>dlabocina;
  2413.     Kocka Petra(boja,gustina,visina,shirina,dlabocina);
  2414.  
  2415.     float suma=0;
  2416.     for(int i=0; i<n; i++)
  2417.     {
  2418.         suma+=kupche[i]->getMasa();
  2419.     }
  2420.     if(suma>Petra.getMasa())
  2421.         cout<<"DA"<<endl;
  2422.     else
  2423.         cout<<"NE"<<endl;
  2424.  
  2425.  
  2426.     float max_volumen=0;
  2427.     float min_plostina=kupche[0]->getPlostina();
  2428.     for(int i=0; i<n; i++)
  2429.     {
  2430.         if(kupche[i]->getVolumen() > max_volumen)
  2431.         {
  2432.             max_volumen=kupche[i]->getVolumen();
  2433.         }
  2434.         if(kupche[i]->getPlostina() < min_plostina)
  2435.         {
  2436.             min_plostina=kupche[i]->getPlostina();
  2437.         }
  2438.     }
  2439.     cout<<"Razlikata e: "<<abs(max_volumen - Petra.getVolumen())<<endl;
  2440.     cout<<"Razlikata e: "<<abs(min_plostina - Petra.getPlostina())<<endl;
  2441.  
  2442. }
  2443.  
  2444. //13. Race
  2445. #include<iostream>
  2446. #include<cstring>
  2447.  
  2448. using namespace std;
  2449.  
  2450. class Runner {
  2451.     char *ime;
  2452.     char drzhava[50];
  2453.     int vreme[2];
  2454.     int medali;
  2455. public:
  2456.     Runner() {
  2457.         ime=new char[0];
  2458.         vreme[0]=vreme[1]=0;
  2459.         medali=0;
  2460.     }
  2461.     Runner(char *i, char *d, int m, int s, int med) {
  2462.         ime=new char[strlen(i)+1];
  2463.         strcpy(ime, i);
  2464.         strcpy(drzhava,d);
  2465.         vreme[0]=m;
  2466.         vreme[1]=s;
  2467.         medali=med;
  2468.     }
  2469.     Runner(const Runner &r) {
  2470.         ime=new char[strlen(r.ime)+1];
  2471.         strcpy(ime, r.ime);
  2472.         strcpy(drzhava,r.drzhava);
  2473.         vreme[0]=r.vreme[0];
  2474.         vreme[1]=r.vreme[1];
  2475.         medali=r.medali;
  2476.     }
  2477.     Runner& operator = (const Runner &r) {
  2478.         delete [] ime;
  2479.         ime=new char[strlen(r.ime)+1];
  2480.         strcpy(ime, r.ime);
  2481.         strcpy(drzhava,r.drzhava);
  2482.         vreme[0]=r.vreme[0];
  2483.         vreme[1]=r.vreme[1];
  2484.         medali=r.medali;
  2485.         return *this;
  2486.     }
  2487.     Runner &operator ++ () {
  2488.         ++medali;
  2489.         return *this;
  2490.     }
  2491.     bool operator != (Runner &r) {
  2492.         return(strcmp(drzhava, r.drzhava)!=0);
  2493.     }
  2494.     bool operator < (Runner &r) {
  2495.         if((vreme[0]*60+vreme[1])<(r.vreme[0]*60+r.vreme[1]))
  2496.             return true;
  2497.         else return false;
  2498.     }
  2499.     friend ostream& operator<<(ostream &os, Runner &r) {
  2500.         os<<r.ime<<" - "<<r.drzhava<<" - "<<r.vreme[0]<<":"<<r.vreme[1]<<" - "<<r.medali;
  2501.         return os;
  2502.     }
  2503.     ~Runner() {
  2504.         delete[]ime;
  2505.     }
  2506. };
  2507.  
  2508. class Race {
  2509.     char imeTrka[50];
  2510.     Runner *trkachi;
  2511.     int broj;
  2512. public:
  2513.     Race(char *i) {
  2514.         strcpy(imeTrka,i);
  2515.         trkachi=new Runner[0];
  2516.         broj=0;
  2517.     }
  2518.     Race(const Race &r)
  2519.     {
  2520.         strcpy(imeTrka,r.imeTrka);
  2521.         trkachi=new Runner[r.broj];
  2522.         for(int i=0; i<r.broj; i++)
  2523.         {
  2524.             trkachi[i]=r.trkachi[i];
  2525.         }
  2526.         broj=r.broj;
  2527.     }
  2528.     Race &operator = (const Race &r)
  2529.     {
  2530.         delete [] trkachi;
  2531.         strcpy(imeTrka,r.imeTrka);
  2532.         trkachi=new Runner[r.broj];
  2533.         for(int i=0; i<r.broj; i++)
  2534.         {
  2535.             trkachi[i]=r.trkachi[i];
  2536.         }
  2537.         broj=r.broj;
  2538.         return *this;
  2539.     }
  2540.     Race &operator += (const Runner &r)
  2541.     {
  2542.         Runner *pom=new Runner[broj];
  2543.         for(int i=0; i<broj; i++)
  2544.         {
  2545.             pom[i]=trkachi[i];
  2546.         }
  2547.         delete [] trkachi;
  2548.         trkachi=new Runner[broj+1];
  2549.         for(int i=0; i<broj; i++)
  2550.         {
  2551.             trkachi[i]=pom[i];
  2552.         }
  2553.         delete [] pom;
  2554.         trkachi[broj]=r;
  2555.         broj++;
  2556.         return *this;
  2557.     }
  2558.     Race &operator -= (Runner &r)
  2559.     {
  2560.         int j=0;
  2561.         Runner *pom=new Runner[broj];
  2562.         for(int i=0; i<broj; i++)
  2563.         {  
  2564.             if(trkachi[i]!=r)
  2565.             {
  2566.                 pom[j]=trkachi[i];
  2567.                 j++;
  2568.             }  
  2569.         }
  2570.         delete [] trkachi;
  2571.         trkachi=new Runner[j];
  2572.         for(int i=0; i<j; i++)
  2573.         {
  2574.             trkachi[i]=pom[i];
  2575.         }
  2576.         delete [] pom;
  2577.         broj=j;
  2578.         return *this;
  2579.     }
  2580.     Race &operator ++ () {
  2581.         Runner pom=trkachi[0];
  2582.         int index=0;
  2583.         for(int i=1; i<broj; i++)
  2584.         {
  2585.             if(trkachi[i]<pom)
  2586.             {
  2587.                 pom=trkachi[i];
  2588.                 index=i;
  2589.             }
  2590.         }
  2591.         ++trkachi[index];
  2592.         return *this;
  2593.     }
  2594.     friend ostream& operator << (ostream &os, Race &r)
  2595.     {
  2596.         os<<r.imeTrka<<":"<<endl;
  2597.         for(int i=0; i<r.broj; i++)
  2598.         {
  2599.             os<<r.trkachi[i]<<endl;
  2600.         }
  2601.         return os;
  2602.     }
  2603.     ~Race() {
  2604.         delete[]trkachi;
  2605.     }
  2606. };
  2607.  
  2608. int main() {
  2609.  
  2610.     int n;
  2611.     cin >> n;
  2612.  
  2613.     char nameRace[50];
  2614.     cin >> nameRace;
  2615.  
  2616.     Race race = Race(nameRace);
  2617.     int m;
  2618.     cin >> m;
  2619.  
  2620.     char name[50];
  2621.     char country[50];
  2622.     int minutes;
  2623.     int seconds;
  2624.     int numberOfMedals;
  2625.     for (int i=0; i < m; ++i) {
  2626.         cin >> name;
  2627.         cin >> country;
  2628.         cin >> minutes;
  2629.         cin >> seconds;
  2630.         cin >> numberOfMedals;
  2631.         Runner r = Runner(name,country,minutes,seconds,numberOfMedals);
  2632.         race += r;
  2633.     }
  2634.     cout << race;
  2635.  
  2636.     if (n == 1) {
  2637.         ++race;
  2638.         cout << race;
  2639.     } else if (n == 2) {
  2640.         cin >> name;
  2641.         cin >> country;
  2642.         cin >> minutes;
  2643.         cin >> seconds;
  2644.         cin >> numberOfMedals;
  2645.         Runner r = Runner(name,country,minutes,seconds,numberOfMedals);
  2646.         race -= r;
  2647.         cout << race;
  2648.     } else if (n == 3) {
  2649.         cin >> name;
  2650.         cin >> country;
  2651.         cin >> minutes;
  2652.         cin >> seconds;
  2653.         cin >> numberOfMedals;
  2654.         Runner r = Runner(name,country,minutes,seconds,numberOfMedals);
  2655.         race -= r;
  2656.         ++race;
  2657.         cout << race;
  2658.     }
  2659. }
  2660. //14. SocialNetwork
  2661. #include <iostream>
  2662. #include <cstring>
  2663.  
  2664. using namespace std;
  2665.  
  2666. class InvalidPassword
  2667. {
  2668. private:
  2669.     char text[50];
  2670. public:
  2671.     InvalidPassword(const char *txt)
  2672.     {
  2673.         strcpy(text, txt);
  2674.     }
  2675.     void message()
  2676.     {
  2677.         cout<<text<<endl;
  2678.     }
  2679. };
  2680.  
  2681. class InvalidEmail
  2682. {
  2683. private:
  2684.     char text[50];
  2685. public:
  2686.     InvalidEmail(const char *txt)
  2687.     {
  2688.         strcpy(text, txt);
  2689.     }
  2690.     void message()
  2691.     {
  2692.         cout<<text<<endl;
  2693.     }
  2694. };
  2695.  
  2696. class MaximumSizeLimit
  2697. {
  2698. private:
  2699.     int broj;
  2700. public:
  2701.     MaximumSizeLimit(int a)
  2702.     {
  2703.         broj=a;
  2704.     }
  2705.     void message()
  2706.     {
  2707.         cout<<"You can't add more than "<<broj<<" users."<<endl;
  2708.     }
  2709. };
  2710.  
  2711. bool proveriPass(char *p)
  2712. {
  2713.     int brojac1=0, brojac2=0, brojac3=0;
  2714.     for(int i=0; i<(int)strlen(p); i++)
  2715.     {
  2716.         if(isupper(p[i]))
  2717.             brojac1++;
  2718.         if(islower(p[i]))
  2719.             brojac2++;
  2720.         if(isdigit(p[i]))
  2721.             brojac3++;
  2722.     }
  2723.     return brojac1>=1&&brojac2>=1&&brojac3>=1;
  2724. }
  2725.  
  2726. bool proveriMail(char *m)
  2727. {
  2728.     int brojac1=0;
  2729.     for(int i=0; i<(int)strlen(m); i++)
  2730.     {
  2731.         if(m[i]=='@')
  2732.             brojac1++;
  2733.     }
  2734.     return brojac1==1;
  2735. }
  2736.  
  2737. class User
  2738. {
  2739. protected:
  2740.     char username[50];
  2741.     char password[50];
  2742.     char email[50];
  2743.     static double koefLike;
  2744.     static double koefComm;
  2745.     static double koefTwit;
  2746. public:
  2747.     User(char *u, char *p, char *e)
  2748.     {
  2749.         if(proveriPass(p)==false)
  2750.             throw InvalidPassword("Password is too weak.");
  2751.         if(proveriMail(e)==false)
  2752.             throw InvalidEmail("Mail is not valid.");
  2753.         strcpy(username, u);
  2754.         strcpy(password, p);
  2755.         strcpy(email, e);
  2756.     }
  2757.     virtual double popularity()=0;
  2758.     virtual ~User() {}
  2759. };
  2760. double User::koefLike=0.1;
  2761. double User::koefComm=0.5;
  2762. double User::koefTwit=0.5;
  2763.  
  2764. class FacebookUser: public User
  2765. {
  2766. private:
  2767.     int friends;
  2768.     int likes;
  2769.     int comments;
  2770. public:
  2771.     FacebookUser(char *u,char *p,char *e,int f, int l, int c):User(u, p, e)
  2772.     {
  2773.         friends=f;
  2774.         likes=l;
  2775.         comments=c;
  2776.     }
  2777.     double popularity()
  2778.     {
  2779.         return friends+likes*koefLike+comments*koefComm;
  2780.     }
  2781. };
  2782.  
  2783. class TwitterUser: public User
  2784. {
  2785. private:
  2786.     int follower;
  2787.     int twits;
  2788. public:
  2789.     TwitterUser(char *u,char *p,char *e,int f,int t):User(u,p,e)
  2790.     {
  2791.         follower=f;
  2792.         twits=t;
  2793.     }
  2794.     double popularity()
  2795.     {
  2796.         return follower+twits*koefTwit;
  2797.     }
  2798. };
  2799.  
  2800. class SocialNetwork
  2801. {
  2802. private:
  2803.     User **korisnici;
  2804.     int brojKorisnici;
  2805.     static int maxKorisnici;
  2806. public:
  2807.     SocialNetwork()
  2808.     {
  2809.         korisnici=new User*[0];
  2810.         brojKorisnici=0;
  2811.     }
  2812.     SocialNetwork(const SocialNetwork &s)
  2813.     {
  2814.         korisnici=new User*[s.brojKorisnici];
  2815.         brojKorisnici=s.brojKorisnici;
  2816.         for(int i=0; i<brojKorisnici; i++)
  2817.         {
  2818.             korisnici[i]=s.korisnici[i];
  2819.         }
  2820.     }
  2821.     SocialNetwork &operator += (User *u)
  2822.     {
  2823.         if(brojKorisnici+1>maxKorisnici)
  2824.             throw MaximumSizeLimit(maxKorisnici);
  2825.         User **temp=new User*[brojKorisnici+1];
  2826.         for(int i=0; i<brojKorisnici; i++)
  2827.         {
  2828.             temp[i]=korisnici[i];
  2829.         }
  2830.         temp[brojKorisnici++]=u;
  2831.         delete [] korisnici; //proveri
  2832.         korisnici=new User*[brojKorisnici];
  2833.         korisnici=temp;
  2834.         return *this;
  2835.  
  2836.     }
  2837.     double avgPopularity()
  2838.     {
  2839.         double vk=0;
  2840.         for(int i=0; i<brojKorisnici; i++)
  2841.         {
  2842.             vk+=korisnici[i]->popularity();
  2843.         }
  2844.         return vk/brojKorisnici;
  2845.     }
  2846.     static void changeMaximumSize(int number)
  2847.     {
  2848.         maxKorisnici=number;
  2849.     }
  2850.     ~SocialNetwork()
  2851.     {
  2852.         for(int i=0; i<brojKorisnici; i++)
  2853.         {
  2854.             delete korisnici[i];
  2855.         }
  2856.         delete [] korisnici;
  2857.     }
  2858. };
  2859. int SocialNetwork::maxKorisnici=5;
  2860.  
  2861. int main()
  2862. {
  2863.  
  2864.     SocialNetwork network = SocialNetwork();
  2865.     int n;
  2866.     cin >> n;
  2867.     char username[50];
  2868.     char password[50];
  2869.     char email[50];
  2870.     int userType;
  2871.     for (int i=0; i < n; ++i)
  2872.     {
  2873.         cin >> username;
  2874.         cin >> password;
  2875.         cin >> email;
  2876.         cin >> userType;
  2877.         if (userType == 1)
  2878.         {
  2879.             int friends;
  2880.             int likes;
  2881.             int comments;
  2882.             cin >> friends >> likes >> comments;
  2883.  
  2884.             // TODO: Try-catch
  2885.             try
  2886.             {
  2887.                 User * u = new FacebookUser(username,password,email,friends,likes,comments);
  2888.                 try
  2889.                 {
  2890.                     network += u;
  2891.                 }
  2892.                 catch(MaximumSizeLimit ms)
  2893.                 {
  2894.                     ms.message();
  2895.                 }
  2896.             }
  2897.             catch(InvalidPassword ip)
  2898.             {
  2899.                 ip.message();
  2900.             }
  2901.             catch(InvalidEmail ie)
  2902.             {
  2903.                 ie.message();
  2904.             }
  2905.  
  2906.         }
  2907.         else
  2908.         {
  2909.             int followers;
  2910.             int tweets;
  2911.             cin >> followers >> tweets;
  2912.  
  2913.             // TODO: Try-catch
  2914.             try
  2915.             {
  2916.                 User * u= new TwitterUser(username,password,email,followers,tweets);
  2917.                 try
  2918.                 {
  2919.                     network += u;
  2920.                 }
  2921.                 catch(MaximumSizeLimit ms)
  2922.                 {
  2923.                     ms.message();
  2924.                 }
  2925.             }
  2926.             catch(InvalidPassword ip)
  2927.             {
  2928.                 ip.message();
  2929.             }
  2930.             catch(InvalidEmail ie)
  2931.             {
  2932.                 ie.message();
  2933.             }
  2934.  
  2935.         }
  2936.  
  2937.     }
  2938.     network.changeMaximumSize(6);
  2939.     cin >> username;
  2940.     cin >> password;
  2941.     cin >> email;
  2942.     int followers;
  2943.     int tweets;
  2944.     cin >> followers >> tweets;
  2945.  
  2946.     // TODO: Try-catch
  2947.     try
  2948.     {
  2949.         User * u= new TwitterUser(username,password,email,followers,tweets);
  2950.         try
  2951.         {
  2952.             network += u;
  2953.         }
  2954.         catch(MaximumSizeLimit ms)
  2955.         {
  2956.             ms.message();
  2957.         }
  2958.     }
  2959.     catch(InvalidPassword ip)
  2960.     {
  2961.         ip.message();
  2962.     }
  2963.     catch(InvalidEmail ie)
  2964.     {
  2965.         ie.message();
  2966.     }
  2967.  
  2968.     cout << network.avgPopularity();
  2969.  
  2970. }
  2971.  
  2972. //15. Колекција од парови
  2973. #include<iostream>
  2974. #include<cstring>
  2975.  
  2976. using namespace std;
  2977.  
  2978. class Par {
  2979.     char *kluch;
  2980.     double vrednost;
  2981. public:
  2982.     Par(const double v) {
  2983.         kluch=new char[0];
  2984.         vrednost=v;
  2985.     }
  2986.     Par(const char *k="", const double v=0) {
  2987.         kluch=new char[strlen(k)+1];
  2988.         strcpy(kluch,k);
  2989.         vrednost=v;
  2990.     }
  2991.     Par(const Par &p) {
  2992.         kluch=new char[strlen(p.kluch)+1];
  2993.         strcpy(kluch,p.kluch);
  2994.         vrednost=p.vrednost;
  2995.     }
  2996.     Par& operator = (const Par &p) {
  2997.         delete [] kluch;
  2998.         kluch=new char[strlen(p.kluch)+1];
  2999.         strcpy(kluch,p.kluch);
  3000.         vrednost=p.vrednost;
  3001.         return *this;
  3002.     }
  3003.     friend ostream &operator << (ostream &os, const Par &p) {
  3004.         os<<"("<<p.kluch<<", "<<p.vrednost<<")"<<endl;
  3005.         return os;
  3006.     }
  3007.     Par &operator ++() {
  3008.         ++vrednost;
  3009.         return *this;
  3010.     }
  3011.     Par operator ++ (int) {
  3012.         Par pom(*this);
  3013.         ++vrednost;
  3014.         return pom;
  3015.     }
  3016.     Par operator + (const Par &p) {
  3017.         char *pom;
  3018.         if(strlen(kluch)>=strlen(p.kluch)) {
  3019.             pom=new char[strlen(kluch)+1];
  3020.             strcpy(pom, kluch);
  3021.         } else {
  3022.             pom=new char[strlen(p.kluch)+1];
  3023.             strcpy(pom, p.kluch);
  3024.         }
  3025.         double pomVrednost=vrednost+p.vrednost;
  3026.         Par nov(pom, pomVrednost);
  3027.         return nov;
  3028.     }
  3029.     bool operator == (const Par &p) {
  3030.         return((strcmp(kluch,p.kluch)==0)&&(vrednost==p.vrednost));
  3031.     }
  3032.     char* getKluch() {
  3033.         return kluch;
  3034.     }
  3035.     ~Par() {
  3036.         delete [] kluch;
  3037.     }
  3038.  
  3039. };
  3040.  
  3041. class Kolekcija {
  3042.     Par *parovi;
  3043.     int dolzhina;
  3044. public:
  3045.     Kolekcija() {
  3046.         parovi=new Par[0];
  3047.         dolzhina=0;
  3048.     }
  3049.     Kolekcija(const Kolekcija &k) {
  3050.         parovi=new Par[k.dolzhina];
  3051.         dolzhina=k.dolzhina;
  3052.         for(int i=0; i<dolzhina; i++) {
  3053.             parovi[i]=k.parovi[i];
  3054.         }
  3055.     }
  3056.     Kolekcija &operator = (const Kolekcija &k) {
  3057.         delete [] parovi;
  3058.         parovi=new Par[k.dolzhina];
  3059.         dolzhina=k.dolzhina;
  3060.         for(int i=0; i<dolzhina; i++) {
  3061.             parovi[i]=k.parovi[i];
  3062.         }
  3063.         return *this;
  3064.     }
  3065.     Kolekcija &operator += (const Par &p) {
  3066.         Par *pom=new Par[dolzhina];
  3067.         for(int i=0; i<dolzhina; i++) {
  3068.             pom[i]=parovi[i];
  3069.         }
  3070.         delete [] parovi;
  3071.         parovi=new Par[dolzhina+1];
  3072.         for(int i=0; i<dolzhina; i++) {
  3073.             parovi[i]=pom[i];
  3074.         }
  3075.         delete [] pom;
  3076.         parovi[dolzhina]=p;
  3077.         dolzhina++;
  3078.         return *this;
  3079.     }
  3080.     friend ostream &operator << (ostream &o, const Kolekcija &k) {
  3081.         o<<k.dolzhina<<endl;
  3082.         for(int i=0; i<k.dolzhina; i++) {
  3083.             o<<k.parovi[i];
  3084.         }
  3085.         return o;
  3086.     }
  3087.     bool operator == (const Kolekcija &k) {
  3088.         if(dolzhina!=k.dolzhina)
  3089.             return false;
  3090.         for(int i=0; i<dolzhina; i++) {
  3091.             if(!(parovi[i]==k.parovi[i]))
  3092.                 return false;
  3093.         }
  3094.         return true;
  3095.     }
  3096.     void najdi (const char * kluch) {
  3097.         for(int i=0; i<dolzhina; i++) {
  3098.             if(strcmp(parovi[i].getKluch(),kluch)==0) {
  3099.                 cout<<parovi[i];
  3100.                 break;
  3101.             }
  3102.         }
  3103.     }
  3104.     ~Kolekcija() {
  3105.         delete [] parovi;
  3106.     }
  3107. };
  3108.  
  3109. void printTrueOrFalse (Kolekcija k1, Kolekcija k2) {
  3110.     if (k1==k2)
  3111.         cout << "TRUE" <<endl;
  3112.     else
  3113.         cout <<"FALSE" << endl;
  3114. }
  3115.  
  3116. int main() {
  3117.  
  3118.     int testCase;
  3119.     cin >> testCase;
  3120.  
  3121.     if (testCase == 1) {
  3122.         cout<<"Testiranje na konstruktori za Par i operator << "<<endl;
  3123.         Par p[20];
  3124.         int n;
  3125.         cin>>n;
  3126.         char kluc[50];
  3127.         double vrednost;
  3128.         for (int i=0; i<n; i++) {
  3129.             cin >> kluc >> vrednost;
  3130.             //cout << kluc << vrednost;
  3131.             Par p1 = Par(kluc,vrednost);
  3132.             //cout <<"GRESKA";
  3133.             p[i] = p1;
  3134.             cout << p[i];
  3135.         }
  3136.     } else if (testCase == 2) {
  3137.         cout << "Testiranje na operatorite ++ vo prefix i postfix notacija" <<endl;
  3138.         Par p1 = Par("FINKI",10.20);
  3139.  
  3140.         cout << p1;
  3141.         cout << p1++;
  3142.         cout << p1;
  3143.  
  3144.         Par p2 = Par("OOP",69.69);
  3145.  
  3146.         cout << p2;
  3147.         cout << ++p2;
  3148.         cout << p2;
  3149.     } else if (testCase == 3) {
  3150.         cout << "Testiranje na operatorot + vo klasata Par"<<endl;
  3151.         double vrednost;
  3152.         char kluc[50];
  3153.         Par p[2];
  3154.         for (int i=0; i<2; i++) {
  3155.             cin >> kluc >> vrednost;
  3156.             p[i]=Par(kluc,vrednost);
  3157.         }
  3158.  
  3159.         cout << p[0]+p[1];
  3160.     } else if (testCase==4) {
  3161.         cout << "Testiranje na operatorot + vo klasata Par"<<endl;
  3162.         double vrednost;
  3163.         char kluc [50];
  3164.         int n;
  3165.         cin >> n;
  3166.         Par p [50];
  3167.         for (int i=0; i<n; i++) {
  3168.             cin>>kluc>>vrednost;
  3169.             p[i]=Par(kluc,vrednost);
  3170.         }
  3171.  
  3172.         Par p1 = p[0];
  3173.         for (int i=1; i<n; i++)
  3174.             p1 = (p1 + p[i]);
  3175.  
  3176.         cout << p1;
  3177.     } else if (testCase == 5) {
  3178.         cout<<"Testiranje na operatorite << i += vo klasata Kolekcija"<<endl;
  3179.         Kolekcija k;
  3180.         int n;
  3181.         double vrednost;
  3182.         char kluc [50];
  3183.         cin >> n;
  3184.         for (int i=0; i<n; i++) {
  3185.             cin >> kluc >> vrednost;
  3186.             Par p = Par (kluc,vrednost);
  3187.             k+=p;
  3188.             //cout << p;
  3189.         }
  3190.  
  3191.         cout << k;
  3192.     } else if (testCase == 6) {
  3193.         cout << "Testiranje na operator == za klasata Kolekcija"<<endl;
  3194.  
  3195.         Par p1 ("A",1);
  3196.         Par p2 ("B",2);
  3197.         Par p3 ("B",3);
  3198.         Par p4 ("C",4);
  3199.  
  3200.         Kolekcija k1;
  3201.         k1 += p1;
  3202.         k1 += p2;
  3203.         k1 += p3;
  3204.  
  3205.         Kolekcija k2;
  3206.         k2+=p1;
  3207.         k2+=p4;
  3208.  
  3209.         Kolekcija k3;
  3210.         k3+=p1;
  3211.         k3+=p4;
  3212.  
  3213.         Kolekcija k4;
  3214.         k4+=p1;
  3215.         k4+=p3;
  3216.  
  3217.         printTrueOrFalse(k1,k2);
  3218.         printTrueOrFalse(k1,k3);
  3219.         printTrueOrFalse(k1,k4);
  3220.         printTrueOrFalse(k2,k3);
  3221.         printTrueOrFalse(k2,k4);
  3222.         printTrueOrFalse(k3,k4);
  3223.  
  3224.  
  3225.     } else {
  3226.         cout << "Testiranje na metodot najdi() vo klasata Kolekcija"<<endl;
  3227.         Kolekcija k;
  3228.         int n;
  3229.         double vrednost;
  3230.         char kluc [50];
  3231.         cin >> n;
  3232.         for (int i=0; i<n; i++) {
  3233.             cin >> kluc >> vrednost;
  3234.             Par p = Par (kluc,vrednost);
  3235.             k+=p;
  3236.             //cout << p;
  3237.         }
  3238.  
  3239.         char toFind[50];
  3240.         cin >> toFind;
  3241.         k.najdi(toFind);
  3242.     }
  3243.     return 0;
  3244.  
  3245. }
  3246. //16. Листа од цели броеви
  3247. #include<iostream>
  3248. #include<cstring>
  3249. #include<cmath>
  3250.  
  3251. using namespace std;
  3252.  
  3253. class List {
  3254.  
  3255.     int *broevi;
  3256.     int dolzhina;
  3257.  
  3258. public:
  3259.     List()
  3260.     {
  3261.         broevi=new int[0];
  3262.         dolzhina=0;
  3263.     }
  3264.     List(int l) {
  3265.         broevi=new int[l];
  3266.         dolzhina=l;
  3267.     }
  3268.     List(int *b, int l) {
  3269.         broevi=new int[l];
  3270.         for(int i=0; i<l; i++) {
  3271.             broevi[i]=b[i];
  3272.         }
  3273.         dolzhina=l;
  3274.     }
  3275.     List(const List &l) {
  3276.         broevi=new int[l.dolzhina];
  3277.         for(int i=0; i<l.dolzhina; i++) {
  3278.             broevi[i]=l.broevi[i];
  3279.         }
  3280.         dolzhina=l.dolzhina;
  3281.     }
  3282.     List &operator = (const List &l) {
  3283.         delete [] broevi;
  3284.         broevi=new int[l.dolzhina];
  3285.         for(int i=0; i<l.dolzhina; i++) {
  3286.             broevi[i]=l.broevi[i];
  3287.         }
  3288.         dolzhina=l.dolzhina;
  3289.         return *this;
  3290.     }
  3291.     int sum() const {
  3292.         int suma=0;
  3293.         for(int i=0; i<dolzhina; i++) {
  3294.             suma+=broevi[i];
  3295.         }
  3296.         return suma;
  3297.     }
  3298.     void setDol(int d)
  3299.     {
  3300.         int *pom=new int[d];
  3301.         for(int i=0; i<d; i++)
  3302.         {
  3303.             pom[i]=broevi[i];
  3304.         }
  3305.         delete [] broevi;
  3306.         broevi=new int[d];
  3307.         for(int i=0; i<d; i++)
  3308.         {
  3309.             broevi[i]=pom[i];
  3310.         }
  3311.         dolzhina=d;
  3312.         delete [] pom;
  3313.     }
  3314.     double average() const {
  3315.         return (sum()*1.0)/dolzhina;
  3316.     }
  3317.     bool operator == (List &l) {
  3318.         return(sum()==l.sum());
  3319.     }
  3320.     friend ostream &operator << (ostream &o, const List &l) {
  3321.         if(l.dolzhina<=0) {
  3322.             o<<"The list is empty"<<endl;
  3323.             return o;
  3324.         }
  3325.         o<<l.dolzhina<<": ";
  3326.         for(int i=0; i<l.dolzhina; i++) {
  3327.             o<<l.broevi[i]<<" ";
  3328.         }
  3329.         o<<"sum: "<<l.sum()<<" average: "<<l.average()<<endl;
  3330.         return o;
  3331.     }
  3332.     friend istream &operator >> (istream &i, List &l) {
  3333.         i>>l.dolzhina;
  3334.         //l.setDol(l.dolzhina);
  3335.         l.broevi=new int[l.dolzhina];
  3336.         for(int j=0; j<l.dolzhina; j++) {
  3337.             i>>l.broevi[j];
  3338.         }
  3339.         return i;
  3340.     }
  3341.     List operator + (List l) {
  3342.         if(dolzhina==l.dolzhina)
  3343.         {
  3344.             int *pom = new int [dolzhina];
  3345.             for(int i=0; i<dolzhina; i++)
  3346.             {
  3347.                 pom[i]=broevi[i]+l.broevi[i];
  3348.             }
  3349.             List pom1(pom, dolzhina);
  3350.             return pom1;
  3351.         }
  3352.         else
  3353.         {
  3354.             List pom;
  3355.             return pom;
  3356.         }
  3357.  
  3358.     }
  3359.     List operator - (List l) {
  3360.         if(dolzhina==l.dolzhina)
  3361.         {
  3362.             int *pom = new int [dolzhina];
  3363.             for(int i=0; i<dolzhina; i++)
  3364.             {
  3365.                 pom[i]=broevi[i]-l.broevi[i];
  3366.             }
  3367.             List pom1(pom, dolzhina);
  3368.             return pom1;
  3369.         }
  3370.         else
  3371.         {
  3372.             List pom;
  3373.             return pom;
  3374.         }
  3375.  
  3376.     }
  3377.     List operator ++ () {
  3378.         for(int i=0; i<dolzhina; i++) {
  3379.             ++broevi[i];
  3380.         }
  3381.         return *this;
  3382.     }
  3383.     List operator -- (int) {
  3384.         List newList(broevi, dolzhina);
  3385.         for(int i=0; i<dolzhina; i++) {
  3386.             --broevi[i];
  3387.         }
  3388.         return newList;
  3389.     }
  3390.     List &operator += (int a) {
  3391.         int brojac=0;
  3392.         for(int i=0; i<dolzhina; i++) {
  3393.             if(a==broevi[i])
  3394.                 brojac++;
  3395.         }
  3396.         if(brojac<2) {
  3397.             int *pom=new int [dolzhina];
  3398.             for(int i=0; i<dolzhina; i++) {
  3399.                 pom[i]=broevi[i];
  3400.             }
  3401.             delete [] broevi;
  3402.             broevi=new int[dolzhina+1];
  3403.             for(int i=0; i<dolzhina; i++) {
  3404.                 broevi[i]=pom[i];
  3405.             }
  3406.             broevi[dolzhina]=a;
  3407.             delete [] pom;
  3408.             dolzhina++;
  3409.         }
  3410.         return *this;
  3411.     }
  3412.     int operator [] (int index) {
  3413.         return broevi[index];
  3414.     }
  3415.     List addList (List &l) {
  3416.         int newDol=dolzhina+l.dolzhina-1;
  3417.         int *newNum=new int[newDol];
  3418.         for(int i=0; i<dolzhina; i++) {
  3419.             newNum[i]=broevi[i];
  3420.         }
  3421.         for(int i=0; i<l.dolzhina; i++) {
  3422.             newNum[dolzhina+i]=l.broevi[i+1];
  3423.         }
  3424.         List nova(newNum, newDol);
  3425.         return nova;
  3426.     }
  3427.     ~List() {
  3428.         delete [] broevi;
  3429.     }
  3430. };
  3431.  
  3432. int main() {
  3433.  
  3434.     int testCase;
  3435.     cin>>testCase;
  3436.  
  3437.     if (testCase==1) {
  3438.         cout<<"Testiranje na operatorite << i >>"<<endl;
  3439.         List l;
  3440.         cin >> l;
  3441.         cout<< l;
  3442.     } else if (testCase == 2) {
  3443.         cout<<"Testiranje na operatorot = za klasata List"<<endl;
  3444.         List l1;
  3445.         cin >> l1;
  3446.         List l2;
  3447.         l2 = l1;
  3448.         cout << l2;
  3449.     } else if (testCase == 3) {
  3450.         //2 test primeri tuka
  3451.         cout << "Testiranje na operatorot +"<<endl;
  3452.         List l1,l2;
  3453.         cin >> l1;
  3454.         cin >> l2;
  3455.         List l3;
  3456.         l3 = l1+l2;
  3457.         cout << l3;
  3458.     } else if (testCase == 4) {
  3459.         cout << "Testiranje na operatorot - "<<endl;
  3460.         List l1,l2;
  3461.         cin >> l1;
  3462.         cin >> l2;
  3463.         List l3;
  3464.         l3 = l1-l2;
  3465.         cout << l3;
  3466.     } else if (testCase == 5) {
  3467.         cout << "Testiranje na operator ++ vo prefix notacija"<<endl;
  3468.         List l1;
  3469.         cin >> l1;
  3470.         cout << l1;
  3471.         cout << ++l1;
  3472.     } else if (testCase == 6) {
  3473.         cout << "Testiranje na operatorot -- vo sufix notacija"<<endl;
  3474.         List l1;
  3475.         cin >> l1;
  3476.         cout << "Pocetna vrednost: " << l1;
  3477.         List l2;
  3478.         l2 = l1--;
  3479.         cout << "Se povikuva ++ vo sufiks: " << l2;
  3480.         cout << "Posle povik: " << l1;
  3481.     } else if (testCase == 7) {
  3482.  
  3483.         cout << "Testiranje na operator += "<<endl;
  3484.         List l1;
  3485.         cin >> l1;
  3486.         int n;
  3487.         cin >> n;
  3488.         for (int i=0; i<n; i++) {
  3489.             int broj;
  3490.             cin >> broj;
  3491.             l1 += broj;
  3492.         }
  3493.         cout << l1;
  3494.     } else if (testCase == 8) {
  3495.         cout << "Testiranje na operatorot [ ] "<< endl;
  3496.         List l1;
  3497.         cin >> l1;
  3498.         int n;
  3499.         cin >> n;
  3500.         for (int i=0; i<n; i++) {
  3501.             int idx;
  3502.             cin >> idx;
  3503.             cout << "List["<< idx <<"] = " << l1[idx] << endl;
  3504.         }
  3505.     } else {
  3506.         //Dopolnitelno baranje
  3507.         cout <<"Testiranje na addList() metodot"<<endl;
  3508.         List l1,l2;
  3509.         cin >> l1;
  3510.         cin >> l2;
  3511.         cout << l1.addList(l2);
  3512.     }
  3513.  
  3514.     return 0;
  3515. }
  3516.  
  3517. //17. Vector
  3518. #include<iostream>
  3519. #include<cstring>
  3520.  
  3521. using namespace std;
  3522.  
  3523. class MyVector
  3524. {
  3525.     int broevi[15];
  3526.     int elementi;
  3527. public:
  3528.     MyVector()
  3529.     {
  3530.         elementi=0;
  3531.     }
  3532.     MyVector(int *b, int e)
  3533.     {
  3534.         for(int i=0; i<e; i++)
  3535.         {
  3536.             broevi[i]=b[i];
  3537.         }
  3538.         elementi=e;
  3539.     }
  3540.     void setElementi(int e)
  3541.     {
  3542.         elementi=e;
  3543.     }
  3544.     friend istream &operator >> (istream &is, MyVector &m)
  3545.     {
  3546.         is>>m.elementi;
  3547.         m.setElementi(m.elementi);
  3548.         for(int i=0; i<m.elementi; i++)
  3549.         {
  3550.             is>>m.broevi[i];
  3551.         }
  3552.         return is;
  3553.     }
  3554.     friend ostream &operator << (ostream &os, MyVector &m)
  3555.     {  
  3556.         os<<"<";
  3557.         for(int i=0; i<m.elementi; i++)
  3558.         {
  3559.             if(i!=m.elementi-1)
  3560.                 os<<m.broevi[i]<<",";
  3561.             else
  3562.                 os<<m.broevi[i];
  3563.         }
  3564.         os<<">"<<endl;
  3565.         return os;
  3566.     }
  3567.     MyVector &operator -= (MyVector &m)
  3568.     {
  3569.         for(int i=0; i<elementi; i++)
  3570.         {
  3571.             broevi[i]-=m.broevi[i];
  3572.         }
  3573.         return *this;
  3574.     }
  3575.     int operator * (MyVector &m)
  3576.     {
  3577.         int suma=0;
  3578.         for(int i=0; i<elementi; i++)
  3579.         {
  3580.             suma+=broevi[i]*m.broevi[i];
  3581.         }
  3582.         return suma;
  3583.     }
  3584.     bool operator <= (MyVector &m)
  3585.     {
  3586.         int suma1=0, suma2=0;
  3587.         for(int i=0; i<elementi; i++)
  3588.         {
  3589.             suma1+=broevi[i];
  3590.         }
  3591.         for(int i=0; i<m.elementi; i++)
  3592.         {
  3593.             suma2+=m.broevi[i];
  3594.         }
  3595.         return(suma1<=suma2);
  3596.     }
  3597.     void Error()
  3598.     {
  3599.         cout<<"Index out of bounds"<<endl;
  3600.     }
  3601.     int operator [] (int index)
  3602.     {
  3603.         if(index<0 || index>elementi-1)
  3604.         {
  3605.             Error();
  3606.             return -1;
  3607.         }  
  3608.         else
  3609.             return broevi[index];
  3610.     }
  3611.     MyVector &operator --()
  3612.     {
  3613.         for(int i=0; i<elementi; i++)
  3614.         {
  3615.             if(broevi[i]>0)
  3616.             --broevi[i];
  3617.         }
  3618.         return *this;
  3619.     }
  3620.     MyVector operator ++(int)
  3621.     {
  3622.         MyVector temp(*this);
  3623.         for(int i=0; i<elementi; i++)
  3624.         {
  3625.             if(broevi[i]<0)
  3626.                 ++broevi[i];
  3627.         }
  3628.         return temp;
  3629.     }
  3630. };
  3631. int main() {
  3632. int n;
  3633.  
  3634. cin >> n;
  3635. if (n == 1) {
  3636.   cout << "Testiranje na operatorite >> i <<" << endl;
  3637.   cout << "==============================\n";
  3638.   MyVector a;
  3639.   MyVector b;
  3640.   cin >> a;
  3641.   cin >> b;
  3642.   cout << a;
  3643.   cout << b;
  3644. }
  3645. else if (n == 2) {
  3646.   cout << "Testiranje na operatorot -="<< endl;
  3647.   cout << "==============================\n";
  3648.   int m;
  3649.   int niza[15];
  3650.   cin >> m;
  3651.   for (int i=0; i < m; ++i){
  3652.     cin >> niza[i];
  3653.   }
  3654.   MyVector a(niza,m);
  3655.   for (int i=0; i < m; ++i) {
  3656.     cin >> niza[i];
  3657.   }
  3658.   MyVector b(niza,m);
  3659.   a -= b;
  3660.   cout << a;
  3661. }
  3662. else if (n == 3) {
  3663.   cout << "Testiranje na operatorot *"<< endl;
  3664.   cout << "==============================\n";
  3665.   int m;
  3666.   int niza[15];
  3667.   cin >> m;
  3668.   for (int i=0; i < m; ++i){
  3669.     cin >> niza[i];
  3670.   }
  3671.   MyVector a(niza,m);
  3672.   for (int i=0; i < m; ++i) {
  3673.     cin >> niza[i];
  3674.   }
  3675.   MyVector b(niza,m);
  3676.   cout << a * b;
  3677. }
  3678. else if (n == 4){
  3679.   cout << "Testiranje na operatorot <="<< endl;
  3680.   cout << "==============================\n";
  3681.   int m;
  3682.   int l;
  3683.   int niza[15];
  3684.   cin >> m;
  3685.   for (int i=0; i < m; ++i){
  3686.     cin >> niza[i];
  3687.   }
  3688.   MyVector a(niza,m);
  3689.   cin >> l;
  3690.   for (int i=0; i < l; ++i) {
  3691.     cin >> niza[i];
  3692.   }
  3693.   MyVector b(niza,l);
  3694.   cout << (a <= b);
  3695. }
  3696. else if (n == 5){
  3697.   cout << "Testiranje na operatorot []"<< endl;
  3698.   cout << "==============================\n";
  3699.   int m;
  3700.   int niza[15];
  3701.   cin >> m;
  3702.   for (int i=0; i < m; ++i){
  3703.     cin >> niza[i];
  3704.   }
  3705.   MyVector a(niza,m);
  3706.   for (int i=0; i < m; ++i) {
  3707.     cin >> niza[i];
  3708.   }
  3709.   MyVector b(niza,m);
  3710.   cout << a[2];
  3711.   cout << endl;
  3712.   cout << b[3];
  3713. }
  3714. else if (n == 6) {
  3715.   cout << "Testiranje na operatorot --"<< endl;
  3716.   cout << "==============================\n";
  3717.   int m;
  3718.   int niza[15];
  3719.   cin >> m;
  3720.   for (int i=0; i < m; ++i){
  3721.     cin >> niza[i];
  3722.   }
  3723.   MyVector a(niza,m);
  3724.   --a;
  3725.   cout << a;
  3726. }
  3727. else if (n == 7) {
  3728.   cout << "Testiranje na operatorot ++"<< endl;
  3729.   cout << "==============================\n";
  3730.   int m;
  3731.   int niza[15];
  3732.   cin >> m;
  3733.   for (int i=0; i < m; ++i){
  3734.     cin >> niza[i];
  3735.   }
  3736.   MyVector a(niza,m);
  3737.   MyVector b = a++;
  3738.   cout << a;
  3739.   cout << b;
  3740. }
  3741. }
  3742. //18. Мој термин
  3743. #include <iostream>
  3744. #include <cstring>
  3745.  
  3746. using namespace std;
  3747.  
  3748. class Lekar
  3749. {
  3750. protected:
  3751.     int faksimil;
  3752.     char ime[20];
  3753.     char prezime[20];
  3754.     double pay;
  3755. public:
  3756.     Lekar(){}
  3757.     Lekar(int faksimil, char *ime, char *prezime, double pay)
  3758.     {
  3759.         this->faksimil=faksimil;
  3760.         strcpy(this->ime, ime);
  3761.         strcpy(this->prezime, prezime);
  3762.         this->pay=pay;
  3763.     }
  3764.     Lekar(const Lekar &l)
  3765.     {
  3766.         this->faksimil=l.faksimil;
  3767.         strcpy(this->ime, l.ime);
  3768.         strcpy(this->prezime, l.prezime);
  3769.         this->pay=l.pay;
  3770.     }
  3771.     Lekar &operator = (const Lekar &l)
  3772.     {
  3773.         this->faksimil=l.faksimil;
  3774.         strcpy(this->ime, l.ime);
  3775.         strcpy(this->prezime, l.prezime);
  3776.         this->pay=l.pay;
  3777.         return *this;
  3778.     }
  3779.     void pecati()
  3780.     {
  3781.         cout<<faksimil<<": "<<ime<<" "<<prezime<<endl;
  3782.     }
  3783.     double plata()
  3784.     {
  3785.         return pay;
  3786.     }  
  3787. };
  3788.  
  3789. class MaticenLekar: public Lekar
  3790. {
  3791. private:
  3792.     int broj;
  3793.     double *kotizacii;
  3794. public:
  3795.     MaticenLekar():Lekar()
  3796.     {
  3797.         broj=0;
  3798.         kotizacii=new double[0];
  3799.     }
  3800.     MaticenLekar(const Lekar &l, int broj, double *kotizacii):Lekar(l)
  3801.     {
  3802.         this->broj=broj;
  3803.         this->kotizacii=new double[broj];
  3804.         for(int i=0; i<broj; i++)
  3805.         {
  3806.             this->kotizacii[i]=kotizacii[i];
  3807.         }
  3808.     }
  3809.     MaticenLekar(const MaticenLekar &l):Lekar(l)
  3810.     {
  3811.         this->broj=l.broj;
  3812.         this->kotizacii=new double[broj];
  3813.         for(int i=0; i<broj; i++)
  3814.         {
  3815.             this->kotizacii[i]=l.kotizacii[i];
  3816.         }
  3817.     }
  3818.     MaticenLekar &operator = (const MaticenLekar &l)
  3819.     {
  3820.         (Lekar&)(*this)=l;
  3821.         delete [] kotizacii;
  3822.         this->broj=l.broj;
  3823.         this->kotizacii=new double[broj];
  3824.         for(int i=0; i<broj; i++)
  3825.         {
  3826.             this->kotizacii[i]=l.kotizacii[i];
  3827.         }
  3828.         return *this;
  3829.     }
  3830.     void pecati()
  3831.     {
  3832.         Lekar::pecati();
  3833.         double sum=0;
  3834.         for(int i=0; i<broj; i++)
  3835.         {
  3836.             sum+=kotizacii[i];
  3837.         }
  3838.         cout<<"Prosek na kotizacii: "<<sum/broj<<endl;
  3839.     }
  3840.     double plata()
  3841.     {
  3842.         double sum=0;
  3843.         for(int i=0; i<broj; i++)
  3844.         {
  3845.             sum+=kotizacii[i];
  3846.         }
  3847.         return 0.3*sum/broj+Lekar::plata();
  3848.     }
  3849.     ~MaticenLekar()
  3850.     {
  3851.         delete [] kotizacii;
  3852.     }
  3853.    
  3854. };
  3855.  
  3856. int main() {
  3857.     int n;
  3858.     cin>>n;
  3859.     int pacienti;
  3860.     double kotizacii[100];
  3861.     int faksimil;
  3862.     char ime [20];
  3863.     char prezime [20];
  3864.     double osnovnaPlata;
  3865.    
  3866.     Lekar * lekari = new Lekar [n];
  3867.     MaticenLekar * maticni = new MaticenLekar [n];
  3868.    
  3869.     for (int i=0;i<n;i++){
  3870.         cin >> faksimil >> ime >> prezime >> osnovnaPlata;
  3871.         lekari[i] = Lekar(faksimil,ime,prezime,osnovnaPlata);      
  3872.     }
  3873.    
  3874.     for (int i=0;i<n;i++){
  3875.         cin >> pacienti;
  3876.         for (int j=0;j<pacienti;j++){
  3877.             cin >> kotizacii[j];
  3878.         }
  3879.         maticni[i]=MaticenLekar(lekari[i],pacienti,kotizacii);
  3880.     }
  3881.    
  3882.     int testCase;
  3883.     cin>>testCase;
  3884.    
  3885.     if (testCase==1){
  3886.         cout<<"===TESTIRANJE NA KLASATA LEKAR==="<<endl;
  3887.         for (int i=0;i<n;i++){
  3888.             lekari[i].pecati();
  3889.             cout<<"Osnovnata plata na gorenavedeniot lekar e: "<<lekari[i].plata()<<endl;
  3890.         }
  3891.     }
  3892.     else {
  3893.         cout<<"===TESTIRANJE NA KLASATA MATICENLEKAR==="<<endl;
  3894.         for (int i=0;i<n;i++){
  3895.             maticni[i].pecati();
  3896.             cout<<"Platata na gorenavedeniot maticen lekar e: "<<maticni[i].plata()<<endl;
  3897.         }
  3898.     }
  3899.    
  3900.     delete [] lekari;
  3901.     delete [] maticni;
  3902.    
  3903.     return 0;
  3904. }
  3905.  
  3906. //19. Квадрат и правоаголник
  3907. #include <iostream>
  3908.  
  3909. using namespace std;
  3910.  
  3911. class Kvadrat
  3912. {
  3913. protected:
  3914.     double a;
  3915. public:
  3916.     Kvadrat() {}
  3917.     Kvadrat(double a)
  3918.     {
  3919.         this->a=a;
  3920.     }
  3921.     Kvadrat(const Kvadrat &k)
  3922.     {
  3923.         a=k.a;
  3924.     }
  3925.     double perimetar()
  3926.     {
  3927.         return 4*a;
  3928.     }
  3929.     double plostina()
  3930.     {
  3931.         return a*a;
  3932.     }
  3933.     void pecati()
  3934.     {
  3935.         cout<<"Kvadrat so dolzina a="<<a<<" ima plostina P="<<plostina()<<" i perimetar L="<<perimetar()<<endl;
  3936.     }
  3937. };
  3938.  
  3939. class Pravoagolnik: public Kvadrat   //da se vmetni nasleduvanjeto
  3940. {
  3941. private:
  3942.     double x;
  3943.     double y;
  3944. public:
  3945.     Pravoagolnik() {}
  3946.     Pravoagolnik(const Kvadrat &k, double x, double y):Kvadrat(k)
  3947.     {
  3948.         this->x=x;
  3949.         this->y=y;
  3950.     }
  3951.     Pravoagolnik(const Pravoagolnik &p):Kvadrat(p)
  3952.     {
  3953.         x=p.x;
  3954.         y=p.y;
  3955.     }
  3956.     double perimetar()
  3957.     {
  3958.         double per = Kvadrat::perimetar()+2*(x+y);
  3959.         return per;
  3960.     }
  3961.     double plostina()
  3962.     {
  3963.         double plos = Kvadrat::plostina()+a*x+a*y+x*y;
  3964.         return plos;
  3965.     }
  3966.     void pecati()
  3967.     {
  3968.         if(x==y)
  3969.         {
  3970.             a+=x;
  3971.             Kvadrat::pecati();
  3972.             a-=x;
  3973.         }
  3974.         else
  3975.             cout<<"Pravoagolnik so strani: "<<a+x<<" i "<<a+y<<" ima plostina P="<<plostina()<<" i perimetar L="<<perimetar()<<endl;
  3976.     }
  3977. };
  3978.  
  3979. int main()
  3980. {
  3981.     int n;
  3982.     double a,x,y;
  3983.     Kvadrat * kvadrati;
  3984.     Pravoagolnik * pravoagolnici;
  3985.  
  3986.     cin>>n;
  3987.  
  3988.     kvadrati = new Kvadrat [n];
  3989.     pravoagolnici = new Pravoagolnik [n];
  3990.  
  3991.     for (int i=0; i<n; i++)
  3992.     {
  3993.         cin>>a;
  3994.  
  3995.         kvadrati[i] = Kvadrat(a);
  3996.     }
  3997.  
  3998.     for (int i=0; i<n; i++)
  3999.     {
  4000.         cin>>x>>y;
  4001.  
  4002.         pravoagolnici[i]=Pravoagolnik(kvadrati[i],x,y);
  4003.     }
  4004.  
  4005.     int testCase;
  4006.     cin>>testCase;
  4007.  
  4008.     if (testCase==1)
  4009.     {
  4010.         cout<<"===Testiranje na klasata Kvadrat==="<<endl;
  4011.         for (int i=0; i<n; i++)
  4012.             kvadrati[i].pecati();
  4013.     }
  4014.     else
  4015.     {
  4016.         cout<<"===Testiranje na klasata Pravoagolnik==="<<endl;
  4017.         for (int i=0; i<n; i++)
  4018.             pravoagolnici[i].pecati();
  4019.     }
  4020. }
  4021.  
  4022. //20. NBA
  4023. #include <iostream>
  4024. #include <cstring>
  4025.  
  4026. using namespace std;
  4027.  
  4028. class NBAPlayer
  4029. {
  4030. protected:
  4031.     char *ime;
  4032.     char tim[40];
  4033.     double points;
  4034.     double assists;
  4035.     double rebounds;
  4036. public:
  4037.     NBAPlayer()
  4038.     {
  4039.         ime=new char[0];
  4040.         points=assists=rebounds=0;
  4041.     }
  4042.     NBAPlayer(char *ime, char *tim, double points, double assists, double rebounds)
  4043.     {
  4044.         this->ime = new char[strlen(ime)+1];
  4045.         strcpy(this->ime, ime);
  4046.         strcpy(this->tim, tim);
  4047.         this->points=points;
  4048.         this->assists=assists;
  4049.         this->rebounds=rebounds;
  4050.     }
  4051.     NBAPlayer(const NBAPlayer &n)
  4052.     {
  4053.         this->ime = new char[strlen(n.ime)+1];
  4054.         strcpy(this->ime, n.ime);
  4055.         strcpy(this->tim, n.tim);
  4056.         this->points=n.points;
  4057.         this->assists=n.assists;
  4058.         this->rebounds=n.rebounds;
  4059.     }
  4060.     NBAPlayer &operator = (const NBAPlayer &n)
  4061.     {
  4062.         delete [] ime;
  4063.         this->ime = new char[strlen(n.ime)+1];
  4064.         strcpy(this->ime, n.ime);
  4065.         strcpy(this->tim, n.tim);
  4066.         this->points=n.points;
  4067.         this->assists=n.assists;
  4068.         this->rebounds=n.rebounds;
  4069.         return *this;
  4070.     }
  4071.     double rating()
  4072.     {
  4073.         return 0.45*points+0.3*assists+0.25*rebounds;
  4074.     }
  4075.     void print()
  4076.     {
  4077.         cout<<ime<<" - "<<tim<<endl;
  4078.         cout<<"Points: "<<points<<endl;
  4079.         cout<<"Assists: "<<assists<<endl;
  4080.         cout<<"Rebounds: "<<rebounds<<endl;
  4081.         cout<<"Rating: "<<rating()<<endl;
  4082.     }
  4083.     ~NBAPlayer()
  4084.     {
  4085.         delete [] ime;
  4086.     }
  4087.  
  4088. };
  4089.  
  4090. class AllStarPlayer: public NBAPlayer
  4091. {
  4092. protected:
  4093.     double pointsAvg;
  4094.     double assistsAvg;
  4095.     double reboundsAvg;
  4096. public:
  4097.     AllStarPlayer():NBAPlayer()
  4098.     {
  4099.         pointsAvg=assistsAvg=reboundsAvg=0;
  4100.     }
  4101.     AllStarPlayer(char *ime, char *tim, double points, double assists, double rebounds, double pointsAvg, double assistsAvg, double reboundsAvg):NBAPlayer(ime, tim, points, assists, rebounds)
  4102.     {
  4103.         this->pointsAvg=pointsAvg;
  4104.         this->assistsAvg=assistsAvg;
  4105.         this->reboundsAvg=reboundsAvg;
  4106.     }
  4107.     AllStarPlayer(const NBAPlayer &n, double pointsAvg, double assistsAvg, double reboundsAvg):NBAPlayer(n)
  4108.     {
  4109.         this->pointsAvg=pointsAvg;
  4110.         this->assistsAvg=assistsAvg;
  4111.         this->reboundsAvg=reboundsAvg;
  4112.     }
  4113.     AllStarPlayer(const AllStarPlayer &n):NBAPlayer(n)
  4114.     {
  4115.         this->pointsAvg=n.pointsAvg;
  4116.         this->assistsAvg=n.assistsAvg;
  4117.         this->reboundsAvg=n.reboundsAvg;
  4118.     }
  4119.     AllStarPlayer &operator = (const AllStarPlayer &n)
  4120.     {
  4121.         (NBAPlayer&)(*this)=n;
  4122.         this->pointsAvg=n.pointsAvg;
  4123.         this->assistsAvg=n.assistsAvg;
  4124.         this->reboundsAvg=n.reboundsAvg;
  4125.         return *this;
  4126.     }
  4127.     double AllStarRating()
  4128.     {
  4129.         return 0.3*pointsAvg+0.4*assistsAvg+0.3*reboundsAvg;
  4130.     }
  4131.     double rating()
  4132.     {
  4133.         return (AllStarRating()+NBAPlayer::rating())/2;
  4134.     }
  4135.     void print()
  4136.     {
  4137.         NBAPlayer::print();
  4138.         cout<<"All Star Rating: "<<AllStarRating()<<endl;
  4139.         cout<<"New Rating: "<<rating()<<endl;
  4140.     }
  4141. };
  4142.  
  4143. int main() {
  4144.  
  4145.   char name[50];
  4146.   char team[40];
  4147.   double points;
  4148.   double assists;
  4149.   double rebounds;
  4150.   double allStarPoints;
  4151.   double allStarAssists;
  4152.   double allStarRebounds;
  4153.  
  4154.   NBAPlayer * players = new NBAPlayer[5];
  4155.   AllStarPlayer * asPlayers = new AllStarPlayer[5];
  4156.   int n;
  4157.   cin >> n;
  4158.  
  4159.   if (n == 1) {
  4160.  
  4161.     cout << "NBA PLAYERS:" << endl;
  4162.     cout << "=====================================" << endl;
  4163.     for (int i = 0; i < 5; ++i) {
  4164.       cin >> name >> team >> points >> assists >> rebounds;
  4165.       players[i] = NBAPlayer(name,team,points,assists,rebounds);
  4166.       players[i].print();
  4167.     }
  4168.   }
  4169.   else if (n == 2) {
  4170.  
  4171.     for (int i=0; i < 5; ++i){
  4172.       cin >> name >> team >> points >> assists >> rebounds;
  4173.       cin >> allStarPoints >> allStarAssists >> allStarRebounds;
  4174.       players[i] = NBAPlayer(name,team,points,assists,rebounds);
  4175.       asPlayers[i] = AllStarPlayer(players[i],allStarPoints,allStarAssists,allStarAssists);
  4176.     }
  4177.  
  4178.     cout << "NBA PLAYERS:" << endl;
  4179.     cout << "=====================================" << endl;
  4180.     for (int i=0; i < 5; ++i)
  4181.       players[i].print();
  4182.  
  4183.     cout << "ALL STAR PLAYERS:" << endl;
  4184.     cout << "=====================================" << endl;
  4185.     for (int i=0; i < 5; ++i)
  4186.       asPlayers[i].print();
  4187.  
  4188.     }
  4189.     else if (n == 3) {
  4190.  
  4191.       for (int i=0; i < 5; ++i){
  4192.         cin >> name >> team >> points >> assists >> rebounds;
  4193.         cin >> allStarPoints >> allStarAssists >> allStarRebounds;
  4194.         asPlayers[i] = AllStarPlayer(name, team, points, assists, rebounds,
  4195.                                      allStarPoints,allStarAssists,allStarAssists);
  4196.       }
  4197.       cout << "ALL STAR PLAYERS:" << endl;
  4198.       cout << "=====================================" << endl;
  4199.       for (int i=0; i < 5; ++i)
  4200.         asPlayers[i].print();
  4201.  
  4202.     }
  4203.    
  4204.     delete [] players;
  4205.     delete [] asPlayers;
  4206. }
  4207.  
  4208. //21. Employee
  4209. #include<iostream>
  4210. #include<cstring>
  4211.  
  4212. using namespace std;
  4213.  
  4214. class Employee
  4215. {
  4216. protected:
  4217.     char ime[50];
  4218.     int godini;
  4219.     int rabotnoIskustvo;
  4220. public:
  4221.     Employee(const char *ime, int godini, int rabotnoIskustvo)
  4222.     {
  4223.         strcpy(this->ime, ime);
  4224.         this->godini=godini;
  4225.         this->rabotnoIskustvo=rabotnoIskustvo;
  4226.     }
  4227.     int getGod()
  4228.     {
  4229.         return godini;
  4230.     }
  4231.     virtual double plata()const =0;
  4232.     virtual double bonus()const
  4233.     {
  4234.         return 0;
  4235.     }
  4236.     virtual ~Employee() {}
  4237. };
  4238.  
  4239. bool operator == (Employee &emp1,Employee &emp2) {
  4240.   return emp1.getGod() == emp2.getGod()&&emp1.bonus() == emp2.bonus();
  4241. }
  4242.  
  4243. class SalaryEmployee:public Employee
  4244. {
  4245. private:
  4246.     double osnovnaPlata;
  4247. public:
  4248.  
  4249.     SalaryEmployee(char *ime, int godini, int rabotnoIskustvo, double osnovnaPlata):Employee(ime, godini, rabotnoIskustvo)
  4250.     {
  4251.         this->osnovnaPlata=osnovnaPlata;
  4252.     }
  4253.     double bonus()const
  4254.     {
  4255.         return (osnovnaPlata*rabotnoIskustvo)/100.00;
  4256.     }
  4257.     double plata()const
  4258.     {
  4259.         return bonus()+osnovnaPlata;
  4260.     }
  4261. };
  4262.  
  4263. class HourlyEmployee:public Employee
  4264. {
  4265. private:
  4266.     int rabotniChasovi;
  4267.     int plataPoChas;
  4268. public:
  4269.  
  4270.     HourlyEmployee(const char *ime, int godini, int rabotnoIskustvo, int rabotniChasovi, int plataPoChas):Employee(ime, godini, rabotnoIskustvo)
  4271.     {
  4272.         this->rabotniChasovi=rabotniChasovi;
  4273.         this->plataPoChas=plataPoChas;
  4274.     }
  4275.     double bonus()const
  4276.     {
  4277.         if(rabotniChasovi>320)
  4278.             return (rabotniChasovi-320)*0.5*plataPoChas;
  4279.         else return 0;
  4280.     }
  4281.     double plata()const
  4282.     {
  4283.         return bonus()+rabotniChasovi*plataPoChas;
  4284.     }
  4285. };
  4286.  
  4287. class Freelancer:public Employee
  4288. {
  4289. private:
  4290.     int brojProekti;
  4291.     double plati[20];
  4292. public:
  4293.  
  4294.     Freelancer(char *ime, int godini, int rabotnoIskustvo, int brojProekti, double *plati):Employee(ime, godini, rabotnoIskustvo)
  4295.     {
  4296.         this->brojProekti=brojProekti;
  4297.         for(int i=0; i<brojProekti; i++)
  4298.         {
  4299.             this->plati[i]=plati[i];
  4300.         }
  4301.     }
  4302.     double bonus()const
  4303.     {
  4304.         if(brojProekti>5)
  4305.             return (brojProekti-5)*1000.0;
  4306.         else return 0;
  4307.     }
  4308.     double plata()const
  4309.     {
  4310.         double sum=0;
  4311.         for(int i=0; i<brojProekti; i++)
  4312.         {
  4313.             sum+=plati[i];
  4314.         }
  4315.         return sum+bonus();
  4316.     }
  4317. };
  4318.  
  4319. class Company
  4320. {
  4321. private:
  4322.     char ime[50];
  4323.     int brojVraboteni;
  4324.     Employee **vraboteni;
  4325. public:
  4326.     Company(char *ime)
  4327.     {
  4328.         strcpy(this->ime, ime);
  4329.         brojVraboteni=0;
  4330.         vraboteni=new Employee*[0];
  4331.     }
  4332.     Company &operator += (Employee *p)
  4333.     {
  4334.         Employee **temp=new Employee*[brojVraboteni+1];
  4335.         for(int i=0; i<brojVraboteni; i++)
  4336.         {
  4337.             temp[i]=vraboteni[i];
  4338.         }
  4339.         temp[brojVraboteni]=p;
  4340.         brojVraboteni++;
  4341.         delete [] vraboteni;
  4342.         vraboteni=temp;
  4343.         return *this;
  4344.     }
  4345.     double vkupnaPlata()
  4346.     {
  4347.         double sum=0;
  4348.         for(int i=0; i<brojVraboteni; i++)
  4349.         {
  4350.             sum+=vraboteni[i]->plata();
  4351.         }
  4352.         return sum;
  4353.     }
  4354.     double filtriranaPlata(Employee * emp)
  4355.     {
  4356.         double sum=0;
  4357.         for(int i=0; i<brojVraboteni; i++)
  4358.         {
  4359.             if(*emp==*vraboteni[i])
  4360.                 sum+=vraboteni[i]->plata();
  4361.         }
  4362.         return sum;
  4363.     }
  4364.     void pecatiRabotnici()
  4365.     {
  4366.         int salary, hourly, free;
  4367.         salary=hourly=free=0;
  4368.         for(int i=0; i<brojVraboteni; i++)
  4369.         {
  4370.             SalaryEmployee *temp1=dynamic_cast<SalaryEmployee*>(vraboteni[i]);
  4371.             HourlyEmployee *temp2=dynamic_cast<HourlyEmployee*>(vraboteni[i]);
  4372.             Freelancer *temp3=dynamic_cast<Freelancer*>(vraboteni[i]);
  4373.             if(temp1!=0)
  4374.                 salary++;
  4375.             if(temp2!=0)
  4376.                 hourly++;
  4377.             if(temp3!=0)
  4378.                 free++;
  4379.         }
  4380.         cout << "Vo kompanijata " << ime << " rabotat:" <<endl;
  4381.         cout << "Salary employees: " << salary << endl;
  4382.         cout << "Hourly employees: " << hourly << endl;
  4383.         cout << "Freelancers: " << free << endl;
  4384.  
  4385.  
  4386.     }
  4387.     ~Company()
  4388.     {
  4389.         for(int i=0; i<brojVraboteni; i++)
  4390.         {
  4391.             delete vraboteni[i];
  4392.         }
  4393.         delete [] vraboteni;
  4394.     }
  4395. };
  4396.  
  4397. int main()
  4398. {
  4399.  
  4400.     char name[50];
  4401.     cin >> name;
  4402.     Company c(name);
  4403.  
  4404.     int n;
  4405.     cin >> n;
  4406.  
  4407.     char employeeName[50];
  4408.     int age;
  4409.     int experience;
  4410.     int type;
  4411.  
  4412.     for (int i=0; i <n; ++i)
  4413.     {
  4414.         cin >> type;
  4415.         cin >> employeeName >> age >> experience;
  4416.  
  4417.         if (type == 1)
  4418.         {
  4419.             int basicSalary;
  4420.             cin >> basicSalary;
  4421.             c += new SalaryEmployee(employeeName, age, experience, basicSalary);
  4422.         }
  4423.  
  4424.         else if (type == 2)
  4425.         {
  4426.             int hoursWorked;
  4427.             int hourlyPay;
  4428.             cin >> hoursWorked >> hourlyPay;
  4429.             c += new HourlyEmployee(employeeName, age, experience, hoursWorked, hourlyPay);
  4430.         }
  4431.  
  4432.         else
  4433.         {
  4434.             int numProjects;
  4435.             cin >> numProjects;
  4436.             double projects[10];
  4437.             for (int i=0; i < numProjects; ++i)
  4438.             {
  4439.                 cin >> projects[i];
  4440.             }
  4441.             c += new Freelancer(employeeName, age, experience, numProjects, projects);
  4442.         }
  4443.     }
  4444.  
  4445.     c.pecatiRabotnici();
  4446.     cout << "Vkupnata plata e: " << c.vkupnaPlata() << endl;
  4447.     Employee * emp = new HourlyEmployee("Petre_Petrov",31,6,340,80);
  4448.     cout << "Filtriranata plata e: " << c.filtriranaPlata(emp);
  4449.  
  4450.     delete emp;
  4451. }
  4452. //22. Распоредувач на задачи
  4453. #include<iostream>
  4454. #include<cstring>
  4455.  
  4456. using namespace std;
  4457.  
  4458. class Task {
  4459. protected:
  4460.     char ID[5];
  4461. public:
  4462.     Task(){}
  4463.     Task(const char *id) {
  4464.         strcpy(ID, id);
  4465.     }
  4466.     char *getID()
  4467.     {
  4468.         return ID;
  4469.     }
  4470.     Task (Task &t)
  4471.     {
  4472.         strcpy(ID, t.ID);
  4473.     }
  4474.     virtual int getOrder()=0;
  4475.     virtual void print()=0;
  4476.     virtual ~Task() {}
  4477. };
  4478.  
  4479. class TimedTask: public Task {
  4480. private:
  4481.     int time;
  4482. public:
  4483.     TimedTask():Task(){}
  4484.     TimedTask(const char *id, const int t):Task(id) {
  4485.         time=t;
  4486.     }
  4487.     TimedTask(TimedTask &t):Task(t) {
  4488.         time=t.time;
  4489.     }
  4490.     int getOrder() {
  4491.         return time;
  4492.     }
  4493.     void print() {
  4494.         cout<<"TT->"<<ID<<":"<<getOrder()<<endl;
  4495.     }
  4496. };
  4497.  
  4498. class PriorityTask: public Task {
  4499. private:
  4500.     int priority;
  4501. public:
  4502.     PriorityTask():Task(){}
  4503.     PriorityTask(const char *id, const int t):Task(id) {
  4504.         priority=t;
  4505.     }
  4506.     PriorityTask(PriorityTask &t):Task(t) {
  4507.         priority=t.priority;
  4508.     }
  4509.     int getOrder() {
  4510.         return priority;
  4511.     }
  4512.     void print() {
  4513.         cout<<"PT->"<<ID<<":"<<getOrder()<<endl;
  4514.     }
  4515. };
  4516.  
  4517. void scheduleTimedTasks (Task ** tasks, int n, int t) {
  4518.     for(int i=0; i<n-1; i++) {
  4519.         TimedTask *temp1=dynamic_cast<TimedTask*>(tasks[i]);
  4520.         if(temp1!=0)
  4521.             for(int j=i; j<n; j++) {
  4522.                 TimedTask *temp2=dynamic_cast<TimedTask*>(tasks[j]);
  4523.                 if(temp2!=0&&tasks[i]->getOrder()>tasks[j]->getOrder()) {
  4524.                     Task *temp;
  4525.                     temp=tasks[i];
  4526.                     tasks[i]=tasks[j];
  4527.                     tasks[j]=temp;
  4528.                 }
  4529.             }
  4530.     }
  4531.     for(int i=0; i<n; i++) {
  4532.         TimedTask *temp=dynamic_cast<TimedTask*>(tasks[i]);
  4533.         if(temp!=0&&tasks[i]->getOrder()<t)
  4534.             tasks[i]->print();
  4535.     }
  4536.  
  4537. }
  4538. void schedulePriorityTasks(Task ** tasks, int n,int p) {
  4539.     for(int i=0; i<n-1; i++) {
  4540.         PriorityTask *temp1=dynamic_cast<PriorityTask*>(tasks[i]);
  4541.         if(temp1!=0)
  4542.             for(int j=i; j<n; j++) {
  4543.                 PriorityTask *temp2=dynamic_cast<PriorityTask*>(tasks[j]);
  4544.                 if(temp2!=0&&tasks[i]->getOrder()>tasks[j]->getOrder()) {
  4545.                     Task *temp;
  4546.                     temp=tasks[i];
  4547.                     tasks[i]=tasks[j];
  4548.                     tasks[j]=temp;
  4549.                 }
  4550.             }
  4551.     }
  4552.     for(int i=0; i<n; i++) {
  4553.         PriorityTask *temp=dynamic_cast<PriorityTask*>(tasks[i]);
  4554.         if(temp!=0&&tasks[i]->getOrder()<p)
  4555.             tasks[i]->print();
  4556.     }
  4557.  
  4558. }
  4559. bool operator == (Task *t, Task &p)
  4560. {
  4561.     return t->getOrder()==p.getOrder()&&strcmp(t->getID(), p.getID())==0;
  4562. }
  4563.  
  4564. int main () {
  4565.     int testCase;
  4566.     int n;
  4567.     cin>>testCase;
  4568.  
  4569.     if (testCase==0) {
  4570.         cin>>n;
  4571.         Task ** tasks;
  4572.         tasks = new Task * [n];
  4573.         for (int i=0; i<n; i++) {
  4574.             char id [5];
  4575.             int timeOrPriority;
  4576.             int type; //0 za timed, 1 za priority
  4577.             cin >> type >>id >> timeOrPriority;
  4578.             if (type==0)
  4579.                 tasks[i] = new TimedTask(id,timeOrPriority);
  4580.             else
  4581.                 tasks[i] = new PriorityTask(id,timeOrPriority);
  4582.             //tasks[i]->print();
  4583.         }
  4584.  
  4585.         cout<<"SCHEDULING PRIORITY TASKS WITH PRIORITY DEGREE LESS THAN 10"<<endl;
  4586.         schedulePriorityTasks(tasks,n,10);
  4587.  
  4588.     } else if (testCase==1) {
  4589.         cin>>n;
  4590.         Task ** tasks;
  4591.         tasks = new Task * [n];
  4592.         for (int i=0; i<n; i++) {
  4593.             char id [5];
  4594.             int timeOrPriority;
  4595.             int type; //0 za timed, 1 za priority
  4596.             cin >> type >>id >> timeOrPriority;
  4597.             if (type==0)
  4598.                 tasks[i] = new TimedTask(id,timeOrPriority);
  4599.             else
  4600.                 tasks[i] = new PriorityTask(id,timeOrPriority);
  4601.             //tasks[i]->print();
  4602.         }
  4603.  
  4604.  
  4605.         cout<<"SCHEDULING TIMED TASKS WITH EXECUTION TIME LESS THAN 50"<<endl;
  4606.         scheduleTimedTasks(tasks,n,50);
  4607.     } else {
  4608.         TimedTask * tt1 = new TimedTask("11",10);
  4609.         TimedTask * tt2 = new TimedTask("11",11);
  4610.         TimedTask * tt3 = new TimedTask("11",11);
  4611.         PriorityTask * pp1 = new PriorityTask("aa",10);
  4612.         PriorityTask * pp2 = new PriorityTask("11",10);
  4613.  
  4614.         cout << (tt1==(*tt2))<<endl;
  4615.         cout << (tt2==(*tt3))<<endl;
  4616.         cout << (pp1==(*pp2))<<endl;
  4617.         cout << (pp2==(*tt1))<<endl;
  4618.     }
  4619.  
  4620.     return 0;
  4621. }
  4622.  
  4623. //23. Numbers
  4624. #include<iostream>
  4625. using namespace std;
  4626.  
  4627. class Number
  4628. {
  4629. public:
  4630.     virtual double doubleValue()const=0;
  4631.     virtual int intValue()const=0;
  4632.     virtual void print()=0;
  4633.     virtual ~Number() {}
  4634. };
  4635.  
  4636. class Integer: public Number
  4637. {
  4638. private:
  4639.     int a;
  4640.  
  4641. public:
  4642.     Integer(int a):Number()
  4643.     {
  4644.         this->a=a;
  4645.     }
  4646.     double doubleValue()const
  4647.     {
  4648.         return 0;
  4649.     }
  4650.     int intValue()const
  4651.     {
  4652.         return a;
  4653.     }
  4654.     void print()
  4655.     {
  4656.         cout<<"Integer: "<<a<<endl;
  4657.     }
  4658. };
  4659.  
  4660. class Double: public Number
  4661. {
  4662. private:
  4663.     double a;
  4664.  
  4665. public:
  4666.     Double(double a):Number()
  4667.     {
  4668.         this->a=a;
  4669.     }
  4670.     double doubleValue()const
  4671.     {
  4672.         return a;
  4673.     }
  4674.     int intValue()const
  4675.     {
  4676.         return 0;
  4677.     }
  4678.     void print()
  4679.     {
  4680.         cout<<"Double: "<<a<<endl;
  4681.     }
  4682. };
  4683.  
  4684. class Numbers
  4685. {
  4686. private:
  4687.     Number **broevi;
  4688.     int elementi;
  4689.  
  4690. public:
  4691.     Numbers()
  4692.     {
  4693.         elementi=0;
  4694.         broevi=new Number*[0];
  4695.     }
  4696.     Numbers(const Numbers &n)
  4697.     {
  4698.         broevi=new Number*[n.elementi];
  4699.         elementi=n.elementi;
  4700.         for(int i=0; i<elementi; i++)
  4701.         {
  4702.             broevi[i]=n.broevi[i];
  4703.         }
  4704.     }
  4705.     Numbers &operator = (const Numbers &n)
  4706.     {
  4707.         for(int i=0; i<elementi; i++)
  4708.         {
  4709.             delete broevi[i];
  4710.         }
  4711.         delete [] broevi;
  4712.         broevi=new Number*[n.elementi];
  4713.         elementi=n.elementi;
  4714.         for(int i=0; i<elementi; i++)
  4715.         {
  4716.             broevi[i]=n.broevi[i];
  4717.         }
  4718.         return *this;
  4719.     }
  4720.  
  4721.     ~Numbers()
  4722.     {
  4723.         for(int i=0; i<elementi; i++)
  4724.         {
  4725.             delete broevi[i];
  4726.         }
  4727.         delete [] broevi;
  4728.     }
  4729.  
  4730.     Numbers &operator += (Number *n)
  4731.     {
  4732.         Number **temp=new Number*[elementi];
  4733.         for(int i=0; i<elementi; i++)
  4734.         {
  4735.             temp[i]=broevi[i];
  4736.         }
  4737.         delete [] broevi;
  4738.         broevi=new Number*[elementi+1];
  4739.         for(int i=0; i<elementi; i++)
  4740.         {
  4741.             broevi[i]=temp[i];
  4742.         }
  4743.         broevi[elementi]=n;
  4744.         elementi++;
  4745.         delete [] temp;
  4746.         return *this;
  4747.     }
  4748.  
  4749.     void statistics()
  4750.     {
  4751.         double sumaSite=0, sumaDouble=0;
  4752.         int sumaInt=0, elementiDouble=0, elementiInt=0;
  4753.         cout<<"Count of numbers: "<<elementi<<endl;
  4754.         for(int i=0; i<elementi; i++)
  4755.         {
  4756.             Integer *temp=dynamic_cast<Integer*>(broevi[i]);
  4757.             if(temp!=0)
  4758.             {
  4759.                 sumaInt+=broevi[i]->intValue();
  4760.                 elementiInt++;
  4761.             }
  4762.             else
  4763.             {
  4764.                 sumaDouble+=broevi[i]->doubleValue();
  4765.                 elementiDouble++;
  4766.             }
  4767.         }
  4768.         sumaSite=sumaInt+sumaDouble;
  4769.         cout<<"Sum of all numbers: "<<sumaSite<<endl;
  4770.         cout<<"Count of integer numbers: "<<elementiInt<<endl;
  4771.         cout<<"Sum of integer numbers: "<<sumaInt<<endl;
  4772.         cout<<"Count of double numbers: "<<elementiDouble<<endl;
  4773.         cout<<"Sum of double numbers: "<<sumaDouble<<endl;
  4774.     }
  4775.  
  4776.     void integersLessThan (Integer n)
  4777.     {
  4778.         bool f=true;
  4779.         for(int i=0; i<elementi; i++)
  4780.         {
  4781.             Integer *temp=dynamic_cast<Integer*>(broevi[i]);
  4782.             if(broevi[i]->intValue()<n.intValue()&&temp!=0)
  4783.             {
  4784.                 broevi[i]->print();
  4785.                 f=false;
  4786.             }
  4787.         }
  4788.         if(f)
  4789.         {
  4790.             cout<<"None"<<endl;
  4791.         }
  4792.     }
  4793.  
  4794.     void doublesBiggerThan (Double n)
  4795.     {
  4796.         bool f=true;
  4797.         for(int i=0; i<elementi; i++)
  4798.         {
  4799.             Integer *temp=dynamic_cast<Integer*>(broevi[i]);
  4800.             if(broevi[i]->doubleValue()>n.doubleValue()&&temp==0)
  4801.             {
  4802.                 broevi[i]->print();
  4803.                 f=false;
  4804.             }
  4805.         }
  4806.         if(f)
  4807.         {
  4808.             cout<<"None"<<endl;
  4809.         }
  4810.     }
  4811. };
  4812.  
  4813. int main()
  4814. {
  4815.  
  4816.     int n;
  4817.     cin>>n;
  4818.     Numbers numbers;
  4819.     for (int i=0; i<n; i++)
  4820.     {
  4821.         int type;
  4822.         double number;
  4823.         cin>>type>>number;
  4824.         if (type==0)   //Integer object
  4825.         {
  4826.             Integer * integer = new Integer((int) number);
  4827.             numbers+=integer;
  4828.         }
  4829.         else
  4830.         {
  4831.             Double * doublee = new Double(number);
  4832.             numbers+=doublee;
  4833.         }
  4834.     }
  4835.  
  4836.     int lessThan;
  4837.     double biggerThan;
  4838.  
  4839.     cin>>lessThan;
  4840.     cin>>biggerThan;
  4841.  
  4842.     cout<<"STATISTICS FOR THE NUMBERS\n";
  4843.     numbers.statistics();
  4844.     cout<<"INTEGER NUMBERS LESS THAN "<<lessThan<<endl;
  4845.     numbers.integersLessThan(Integer(lessThan));
  4846.     cout<<"DOUBLE NUMBERS BIGGER THAN "<<biggerThan<<endl;
  4847.     numbers.doublesBiggerThan(Double(biggerThan));
  4848.  
  4849.     return 0;
  4850. }
  4851.  
  4852. //24. Тајни пораки
  4853. #include<cstring>
  4854. #include<iostream>
  4855. using namespace std;
  4856.  
  4857. class Secret {
  4858. public:
  4859.     virtual double simpleEntropy()=0;
  4860.     virtual int total()=0;
  4861.     virtual ~Secret() {}
  4862. };
  4863.  
  4864. bool operator == (Secret &s1, Secret &s2) {
  4865.     return s1.total()==s2.total()&&s1.simpleEntropy()==s2.simpleEntropy();
  4866. }
  4867.  
  4868. bool operator != (Secret &s1, Secret &s2) {
  4869.     return s1.total()!=s2.total() || s1.simpleEntropy()!=s2.simpleEntropy();
  4870. }
  4871.  
  4872. class DigitSecret: public Secret {
  4873. private:
  4874.     int broevi[100];
  4875.     int elementi;
  4876. public:
  4877.     DigitSecret():Secret() {
  4878.         elementi=0;
  4879.     }
  4880.     DigitSecret(const int *broevi, const int elementi):Secret() {
  4881.         for(int i=0; i<elementi; i++)
  4882.             this->broevi[i]=broevi[i];
  4883.         this->elementi=elementi;
  4884.     }
  4885.     DigitSecret(DigitSecret *p):Secret() {
  4886.         for(int i=0; i<p->elementi; i++)
  4887.             this->broevi[i]=p->broevi[i];
  4888.         this->elementi=p->elementi;
  4889.     }
  4890.     double simpleEntropy() {
  4891.         int brojac=0;
  4892.         int glaven=0;
  4893.         for(int i=0; i<10; i++) {
  4894.             brojac=0;
  4895.             for(int j=0; j<elementi; j++) {
  4896.                 if(i==broevi[j]) {
  4897.                     brojac++;
  4898.                 }
  4899.             }
  4900.             if(brojac==1)
  4901.                 glaven++;
  4902.         }
  4903.         return (double)glaven/elementi;
  4904.     }
  4905.     int total() {
  4906.         return elementi;
  4907.     }
  4908.     friend ostream &operator <<(ostream &o, DigitSecret &d) {
  4909.         for(int i=0; i<d.elementi; i++)
  4910.             o<<d.broevi[i];
  4911.         o<<" Simple entropy: "<<d.simpleEntropy()<<" Total: "<<d.total();
  4912.         return o;
  4913.     }
  4914. };
  4915.  
  4916. class CharSecret:public Secret {
  4917. private:
  4918.     char znaci[100];
  4919.     int elementi;
  4920.  
  4921. public:
  4922.     CharSecret():Secret() {
  4923.         elementi=0;
  4924.     }
  4925.     CharSecret(const char *z):Secret() {
  4926.         strcpy(znaci, z);
  4927.         elementi=strlen(znaci);
  4928.     }
  4929.     CharSecret(CharSecret *p):Secret() {
  4930.         strcpy(znaci, p->znaci);
  4931.         elementi=strlen(znaci);
  4932.     }
  4933.     double simpleEntropy() {
  4934.         int brojac=0;
  4935.         int glaven=0;
  4936.         for(char i='a'; i<='z'; i++) {
  4937.             brojac=0;            
  4938.             for(int j=0; j<elementi; j++) {
  4939.                 if(i==znaci[j]) {
  4940.                     brojac++;
  4941.                 }
  4942.             }
  4943.             if(brojac==1)
  4944.                 glaven++;
  4945.         }
  4946.         return (double)glaven/elementi;
  4947.     }
  4948.     int total() {
  4949.         return elementi;
  4950.     }
  4951.     friend ostream &operator <<(ostream &o, CharSecret &d) {
  4952.         for(int i=0; i<d.elementi; i++)
  4953.             o<<d.znaci[i];
  4954.         o<<" Simple entropy: "<<d.simpleEntropy()<<" Total: "<<d.total();
  4955.         return o;
  4956.     }
  4957.  
  4958.  
  4959. };
  4960.  
  4961. void process(Secret ** secrets, int n) {
  4962.     double maxE=0;
  4963.     int index;
  4964.     for(int i=0; i<n; i++) {
  4965.         if(secrets[i]->simpleEntropy()>maxE) {
  4966.             maxE=secrets[i]->simpleEntropy();
  4967.             index=i;
  4968.         }
  4969.     }
  4970.     DigitSecret *temp1=dynamic_cast<DigitSecret*>(secrets[index]);
  4971.     CharSecret *temp2=dynamic_cast<CharSecret*>(secrets[index]);
  4972.     if(temp1!=0) {
  4973.         DigitSecret nov(temp1);
  4974.         cout<<nov;
  4975.     } else {
  4976.         CharSecret nov(temp2);
  4977.         cout<<nov;
  4978.     }
  4979.  
  4980. }
  4981.  
  4982. void printAll (Secret ** secrets, int n) {
  4983.     for(int i=0; i<n; i++) {
  4984.         DigitSecret *temp1=dynamic_cast<DigitSecret*>(secrets[i]);
  4985.         CharSecret *temp2=dynamic_cast<CharSecret*>(secrets[i]);
  4986.         if(temp1!=0) {
  4987.             DigitSecret nov(temp1);
  4988.             cout<<nov<<endl;
  4989.         } else {
  4990.             CharSecret nov(temp2);
  4991.             cout<<nov<<endl;
  4992.         }
  4993.     }
  4994. }
  4995.  
  4996.  
  4997. int main() {
  4998.     int n;
  4999.     cin >> n;
  5000.     if(n == 0) {
  5001.         cout << "Constructors" << endl;
  5002.         int numbers [] = {1,2,3,4,5};
  5003.         DigitSecret ds(numbers,5);
  5004.         CharSecret cs("abcabc");
  5005.         cout << "OK" << endl;
  5006.     } else if(n == 1) {
  5007.         cout << "operator <<" << endl;
  5008.         int numbers [] = {1,2,3,4,5};
  5009.         DigitSecret ds(numbers,5);
  5010.         CharSecret cs("abcabc");
  5011.         cout << ds << endl;
  5012.         cout << cs << endl;
  5013.     } else if(n == 2) {
  5014.         cout << "== and !=" << endl;
  5015.         int numbers [] = {1,2,3,4,5};
  5016.         DigitSecret ds(numbers,5);
  5017.         CharSecret cs("abcabc");
  5018.         CharSecret css("abcabc");
  5019.         cout << (ds == cs) << endl;
  5020.         cout << (cs != ds) << endl;
  5021.         cout << (cs == css) << endl;
  5022.         cout << (cs != css) << endl;
  5023.     } else if(n == 3) {
  5024.         cout << "Secret processor" << endl;
  5025.         int numbers1 [] = {1,2,3,4,5,6,4,3,2,1,1,2,3,4,5};
  5026.         DigitSecret ds1(numbers1,15);
  5027.         int numbers2 [] = {1,2,3,4,5,0,0,0,5,5,4,4,3,3,2};
  5028.         DigitSecret ds2(numbers2,15);
  5029.         int numbers3 [] = {1,0,9,4,3,8,4,0,9,3,1,4,3,2,1,4,4,3,7,2};
  5030.         DigitSecret ds3(numbers3,20);
  5031.         CharSecret cs1("fhdaieowujkfjdsafjdsakjhueiqoyroq");
  5032.         CharSecret cs2("nvzcfsadrqipqhfjdfncxoqw");
  5033.         CharSecret cs3("uyoihfdsanmqeqrzvdhfeqyrq");
  5034.         Secret** s = new Secret*[6];
  5035.         s[0] = &ds1;
  5036.         s[1] = &ds2;
  5037.         s[2] = &ds3;
  5038.         s[3] = &cs1;
  5039.         s[4] = &cs2;
  5040.         s[5] = &cs3;
  5041.         process(s,6);
  5042.         delete [] s;
  5043.     } else if (n==4) {
  5044.         cout << "Print all secrets" << endl;
  5045.         int numbers1 [] = {1,2,3,4,5,5,4,3,2,1,1,2,3,4,5};
  5046.         DigitSecret ds1(numbers1,15);
  5047.         int numbers2 [] = {1,2,3,4,5,0,0,0,5,5,4,4,3,3,2};
  5048.         DigitSecret ds2(numbers2,15);
  5049.         int numbers3 [] = {1,0,9,4,3,8,4,0,9,3,1,4,3,2,1,4,4,3,7,2};
  5050.         DigitSecret ds3(numbers3,20);
  5051.         CharSecret cs1("fhdaieowujkfjdsafjdsakjhueiqoyroq");
  5052.         CharSecret cs2("nvzcfsadrqipqhfjdfncxoqw");
  5053.         CharSecret cs3("uyoihfdsanmqeqrzvdhfeqyrq");
  5054.         Secret** s = new Secret*[6];
  5055.         s[0] = &ds1;
  5056.         s[1] = &ds2;
  5057.         s[2] = &ds3;
  5058.         s[3] = &cs1;
  5059.         s[4] = &cs2;
  5060.         s[5] = &cs3;
  5061.         printAll(s,6);
  5062.         delete [] s;
  5063.     }
  5064.  
  5065.     return 0;
  5066. }
  5067.  
  5068. //25. Shapes
  5069. #include <iostream>
  5070. #include <cmath>
  5071. using namespace std;
  5072.  
  5073. class Shape
  5074. {
  5075. protected:
  5076.     int a;
  5077. public:
  5078.     Shape(){}
  5079.     Shape(int a)
  5080.     {
  5081.         this->a=a;
  5082.     }
  5083.     virtual double plostina()=0;
  5084.     virtual void pecati(){}
  5085.     virtual int getType()=0;
  5086. };
  5087.  
  5088. class Square: public Shape
  5089. {
  5090. public:
  5091.     Square(int a):Shape(a){}
  5092.     double plostina()
  5093.     {
  5094.         return a*a;
  5095.     }
  5096.     void pecati()
  5097.     {
  5098.         cout<<"Kvadrat so plostina = "<<plostina()<<endl;
  5099.     }
  5100.     int getType()
  5101.     {
  5102.         return 1;
  5103.     }
  5104.    
  5105. };
  5106.  
  5107. class Circle: public Shape
  5108. {
  5109. public:
  5110.     Circle(int a):Shape(a){};
  5111.     double plostina()
  5112.     {
  5113.         return 3.14*a*a;
  5114.     }
  5115.     void pecati()
  5116.     {
  5117.         cout<<"Krug so plostina = "<<plostina()<<endl;
  5118.     }
  5119.     int getType()
  5120.     {
  5121.         return 2;
  5122.     }
  5123.    
  5124. };
  5125. class Triangle: public Shape
  5126. {
  5127. public:
  5128.     Triangle(int a):Shape(a){};
  5129.     double plostina()
  5130.     {
  5131.         return (sqrt(3)/4)*a*a;
  5132.     }
  5133.     void pecati()
  5134.     {
  5135.         cout<<"Triagolnik so plostina = "<<plostina()<<endl;
  5136.     }
  5137.     int getType()
  5138.     {
  5139.         return 3;
  5140.     }
  5141.    
  5142. };
  5143. void checkNumTypes(Shape** niza, int n)
  5144. {
  5145.     int kvadrati, krugovi, triagolnici;
  5146.     kvadrati=krugovi=triagolnici=0;
  5147.     for(int i=0; i<n; i++)
  5148.     {
  5149.         if(niza[i]->getType()==1)  
  5150.             kvadrati++;
  5151.         else if(niza[i]->getType()==2)
  5152.             krugovi++;
  5153.             else triagolnici++;
  5154.     }
  5155.     cout<<"Broj na kvadrati vo nizata = "<<kvadrati<<endl;
  5156.     cout<<"Broj na krugovi vo nizata = "<<krugovi<<endl;
  5157.     cout<<"Broj na triagolnici vo nizata = "<<triagolnici<<endl;
  5158. }
  5159.  
  5160.  
  5161. int main(){
  5162.  
  5163.  
  5164.     int n;
  5165.     cin >> n;
  5166.  
  5167.     Shape **pokazhuvachi;
  5168.     pokazhuvachi=new Shape*[n];
  5169.  
  5170.    
  5171.  
  5172.     //TODO: alociraj memorija so golemina n za prethodno navedenata niza
  5173.    
  5174.  
  5175.     int classType;
  5176.     int side;
  5177.  
  5178.     //TODO: konstruiraj for ciklus so chija pomosh ke ja popolnish nizata
  5179.     for(int i = 0; i < n; ++i){
  5180.  
  5181.         cin >> classType;
  5182.         cin >> side;
  5183.         if(classType==1)
  5184.             pokazhuvachi[i]=new Square(side);
  5185.         else if(classType==2)
  5186.             pokazhuvachi[i]=new Circle(side);
  5187.             else
  5188.             pokazhuvachi[i]=new Triangle(side);
  5189.        
  5190.     }
  5191.    
  5192.    
  5193.     for(int i = 0; i < n; ++i){
  5194.  
  5195.         pokazhuvachi[i]->pecati();
  5196.     }
  5197.  
  5198.     checkNumTypes(pokazhuvachi, n);
  5199.  
  5200.  
  5201.     return 0;
  5202. }
  5203. //26. Трансакции
  5204. #include<iostream>
  5205. #include<cstring>
  5206.  
  5207. using namespace std;
  5208.  
  5209. class InvalidDataException
  5210. {
  5211. private:
  5212.     int den;
  5213.     int mesec;
  5214.     int godina;
  5215. public:
  5216.     InvalidDataException(int d, int m, int g)
  5217.     {
  5218.         den=d;
  5219.         mesec=m;
  5220.         godina=g;
  5221.     }
  5222.     void message()
  5223.     {
  5224.         cout<<"Invalid Date "<<den<<"/"<<mesec<<"/"<<godina<<endl;
  5225.     }
  5226. };
  5227.  
  5228. class NotSupportedCurrencyException
  5229. {
  5230. private:
  5231.     char currency[3];
  5232. public:
  5233.     NotSupportedCurrencyException(char *c)
  5234.     {
  5235.         strcpy(currency, c);
  5236.     }
  5237.     void message()
  5238.     {
  5239.         cout<<currency<<" is not a supported currency"<<endl;
  5240.     }
  5241. };
  5242.  
  5243. class Transakcija
  5244. {
  5245. protected:
  5246.     int den;
  5247.     int mesec;
  5248.     int godina;
  5249.     double parichenIznos;
  5250.     static double EUR;
  5251.     static double USD;
  5252. public:
  5253.     Transakcija(int d, int m, int g, double p)
  5254.     {
  5255.         if(d<1 || d>31 || m<1 || m>12)
  5256.             throw InvalidDataException(d, m, g);
  5257.         den=d;
  5258.         mesec=m;
  5259.         godina=g;
  5260.         parichenIznos=p;
  5261.     }
  5262.     static void setEUR(double E)
  5263.     {
  5264.         EUR=E;
  5265.     }
  5266.     static void setUSD(double U)
  5267.     {
  5268.         USD=U;
  5269.     }
  5270.     static double getEUR()
  5271.     {
  5272.         return EUR;
  5273.     }
  5274.     static double getUSD()
  5275.     {
  5276.         return USD;
  5277.     }
  5278.     virtual double voDenari()=0;
  5279.     virtual double voEvra()=0;
  5280.     virtual double voDolari()=0;
  5281.     virtual void pecati() {}
  5282.     virtual ~Transakcija() {}
  5283. };
  5284. double Transakcija::EUR=61;
  5285. double Transakcija::USD=50;
  5286.  
  5287. class DenarskaTransakcija: public Transakcija
  5288. {
  5289. public:
  5290.     DenarskaTransakcija(int d, int m, int g, double iznos):Transakcija(d, m, g, iznos) {}
  5291.     double voDenari()
  5292.     {
  5293.         return parichenIznos;
  5294.     }
  5295.     double voEvra()
  5296.     {
  5297.         return parichenIznos/EUR;
  5298.     }
  5299.     double voDolari()
  5300.     {
  5301.         return parichenIznos/USD;
  5302.     }
  5303.     void pecati()
  5304.     {
  5305.         cout<<den<<"/"<<mesec<<"/"<<godina<<" "<<parichenIznos<<" MKD"<<endl;
  5306.     }
  5307. };
  5308.  
  5309. class DeviznaTransakcija: public Transakcija
  5310. {
  5311. private:
  5312.     char valuta[3];
  5313. public:
  5314.     DeviznaTransakcija(int d, int m, int g, double iznos,char* v):Transakcija(d, m, g, (int)iznos)
  5315.     {
  5316.         if(strcmp(v,"EUR")==0 || strcmp(v,"USD")==0)
  5317.         {
  5318.             strcpy(valuta, v);
  5319.         }
  5320.         else
  5321.             throw NotSupportedCurrencyException(v);
  5322.     }
  5323.     double voDenari()
  5324.     {
  5325.         if(strcmp(valuta, "EUR")==0)
  5326.             return parichenIznos*EUR;
  5327.         else if(strcmp(valuta, "USD")==0)
  5328.             return parichenIznos*USD;
  5329.         else
  5330.             return parichenIznos;
  5331.     }
  5332.     double voEvra()
  5333.     {
  5334.         return voDenari()/EUR;
  5335.     }
  5336.     double voDolari()
  5337.     {
  5338.         return voDenari()/USD;
  5339.     }
  5340.     void pecati()
  5341.     {
  5342.         cout<<den<<"/"<<mesec<<"/"<<godina<<" "<<parichenIznos<<" "<<valuta<<endl;
  5343.     }
  5344. };
  5345.  
  5346. class Smetka
  5347. {
  5348. private:
  5349.     Transakcija **transakcii;
  5350.     int brojTransakcii;
  5351.     char IDsmetka[50];
  5352.     double saldo;
  5353. public:
  5354.     Smetka(const char *ID, double sal)
  5355.     {
  5356.         strcpy(IDsmetka, ID);
  5357.         saldo=sal;
  5358.         transakcii=new Transakcija*[0];
  5359.         brojTransakcii=0;
  5360.     }
  5361.     Smetka &operator += (Transakcija *t)
  5362.     {
  5363.         Transakcija **temp=new Transakcija*[brojTransakcii+1];
  5364.         for(int i=0; i<brojTransakcii; i++)
  5365.         {
  5366.             temp[i]=transakcii[i];
  5367.         }
  5368.         temp[brojTransakcii++]=t;
  5369.         transakcii=temp;
  5370.         return *this;
  5371.     }
  5372.     void izvestajVoDenari()
  5373.     {
  5374.         double vk=saldo;
  5375.         for(int i=0; i<brojTransakcii; i++)
  5376.         {
  5377.             vk+=transakcii[i]->voDenari();
  5378.         }
  5379.         cout<<"Korisnikot so smetka: "<<IDsmetka<<" ima momentalno saldo od "<<vk<<" MKD"<<endl;
  5380.     }
  5381.     void izvestajVoEvra()
  5382.     {
  5383.         double vk=saldo/Transakcija::getEUR();
  5384.         for(int i=0; i<brojTransakcii; i++)
  5385.         {
  5386.             vk+=transakcii[i]->voEvra();
  5387.         }
  5388.         cout<<"Korisnikot so smetka: "<<IDsmetka<<" ima momentalno saldo od "<<vk<<" EUR"<<endl;
  5389.     }
  5390.     void izvestajVoDolari()
  5391.     {
  5392.         double vk=saldo/Transakcija::getUSD();
  5393.         for(int i=0; i<brojTransakcii; i++)
  5394.         {
  5395.             vk+=transakcii[i]->voDolari();
  5396.         }
  5397.         cout<<"Korisnikot so smetka: "<<IDsmetka<<" ima momentalno saldo od "<<vk<<" USD"<<endl;
  5398.     }
  5399.     void pecatiTransakcii()
  5400.     {
  5401.         for(int i=0; i<brojTransakcii; i++)
  5402.         {
  5403.             transakcii[i]->pecati();
  5404.         }
  5405.     }
  5406.     ~Smetka()
  5407.     {
  5408.         for(int i=0; i<brojTransakcii; i++)
  5409.         {
  5410.             delete transakcii[i];
  5411.         }
  5412.         delete [] transakcii;
  5413.     }
  5414. };
  5415.  
  5416. int main () {
  5417.    
  5418.     Smetka s ("300047024112789",1500);
  5419.    
  5420.     int n, den, mesec, godina, tip;
  5421.     double iznos;
  5422.     char valuta [3];
  5423.    
  5424.     cin>>n;
  5425.     cout<<"===VNESUVANJE NA TRANSAKCIITE I SPRAVUVANJE SO ISKLUCOCI==="<<endl;
  5426.     for (int i=0;i<n;i++){
  5427.         cin>>tip>>den>>mesec>>godina>>iznos;       
  5428.         if (tip==2){
  5429.             cin>>valuta;
  5430.             try
  5431.             {
  5432.                 Transakcija * t = new DeviznaTransakcija(den,mesec,godina,iznos,valuta);
  5433.                 s+=t;
  5434.             }
  5435.             catch (InvalidDataException id)
  5436.             {
  5437.                 id.message();
  5438.             }
  5439.             catch(NotSupportedCurrencyException c)
  5440.             {
  5441.                 c.message();
  5442.             }
  5443.             //delete t;
  5444.         }
  5445.         else {
  5446.             try
  5447.             {
  5448.                 Transakcija * t = new DenarskaTransakcija(den,mesec,godina,iznos);
  5449.                 s+=t;
  5450.             }
  5451.             catch(InvalidDataException id)
  5452.             {
  5453.                 id.message();
  5454.             }
  5455.             catch(NotSupportedCurrencyException c)
  5456.             {
  5457.                 c.message();
  5458.             }
  5459.             //delete t;
  5460.         }
  5461.        
  5462.            
  5463.     }
  5464.     cout<<"===PECHATENJE NA SITE TRANSAKCII==="<<endl;
  5465.     s.pecatiTransakcii();
  5466.     cout<<"===IZVESHTAJ ZA SOSTOJBATA NA SMETKATA VO DENARI==="<<endl;
  5467.     s.izvestajVoDenari();
  5468.     cout<<"===IZVESHTAJ ZA SOSTOJBATA NA SMETKATA VO EVRA==="<<endl;
  5469.     s.izvestajVoEvra();
  5470.     cout<<"===IZVESHTAJ ZA SOSTOJBATA NA SMETKATA VO DOLARI==="<<endl;
  5471.     s.izvestajVoDolari();
  5472.    
  5473.     cout<<"\n===PROMENA NA KURSOT NA EVROTO I DOLAROT===\n"<<endl;
  5474.    
  5475.        
  5476.     double newEUR, newUSD;
  5477.     cin>>newEUR>>newUSD;
  5478.     Transakcija::setEUR(newEUR);
  5479.     Transakcija::setUSD(newUSD);
  5480.     cout<<"===IZVESHTAJ ZA SOSTOJBATA NA SMETKATA VO DENARI==="<<endl;
  5481.     s.izvestajVoDenari();
  5482.     cout<<"===IZVESHTAJ ZA SOSTOJBATA NA SMETKATA VO EVRA==="<<endl;
  5483.     s.izvestajVoEvra();
  5484.     cout<<"===IZVESHTAJ ZA SOSTOJBATA NA SMETKATA VO DOLARI==="<<endl;
  5485.     s.izvestajVoDolari();
  5486.    
  5487.    
  5488.    
  5489.     return 0;
  5490. }
  5491. //27. Трасаккции (simple version)
  5492. #include<iostream>
  5493. #include<cstring>
  5494.  
  5495. using namespace std;
  5496.  
  5497. class InvalidDataException
  5498. {
  5499. private:
  5500.     int den;
  5501.     int mesec;
  5502.     int godina;
  5503. public:
  5504.     InvalidDataException(int d, int m, int g)
  5505.     {
  5506.         den=d;
  5507.         mesec=m;
  5508.         godina=g;
  5509.     }
  5510.     void message()
  5511.     {
  5512.         cout<<"Invalid Date "<<den<<"/"<<mesec<<"/"<<godina<<endl;
  5513.     }
  5514. };
  5515.  
  5516. class NotSupportedCurrencyException
  5517. {
  5518. private:
  5519.     char currency[3];
  5520. public:
  5521.     NotSupportedCurrencyException(char *c)
  5522.     {
  5523.         strcpy(currency, c);
  5524.     }
  5525.     void message()
  5526.     {
  5527.         cout<<currency<<" is not a supported currency"<<endl;
  5528.     }
  5529. };
  5530.  
  5531. class Transakcija
  5532. {
  5533. protected:
  5534.     int den;
  5535.     int mesec;
  5536.     int godina;
  5537.     double parichenIznos;
  5538.     static double EUR;
  5539.     static double USD;
  5540. public:
  5541.     Transakcija(int d, int m, int g, double p)
  5542.     {
  5543.         if(d<1 || d>31 || m<1 || m>12)
  5544.             throw InvalidDataException(d, m, g);
  5545.         den=d;
  5546.         mesec=m;
  5547.         godina=g;
  5548.         parichenIznos=p;
  5549.     }
  5550.     static void setEUR(double E)
  5551.     {
  5552.         EUR=E;
  5553.     }
  5554.     static void setUSD(double U)
  5555.     {
  5556.         USD=U;
  5557.     }
  5558.     virtual double voDenari()=0;
  5559.     virtual void pecati() {}
  5560.     virtual ~Transakcija() {}
  5561. };
  5562. double Transakcija::EUR=61;
  5563. double Transakcija::USD=50;
  5564.  
  5565. class DenarskaTransakcija: public Transakcija
  5566. {
  5567. public:
  5568.     DenarskaTransakcija(int d, int m, int g, double iznos):Transakcija(d, m, g, iznos) {}
  5569.     double voDenari()
  5570.     {
  5571.         return parichenIznos;
  5572.     }
  5573.     void pecati()
  5574.     {
  5575.         cout<<den<<"/"<<mesec<<"/"<<godina<<" "<<parichenIznos<<" MKD"<<endl;
  5576.     }
  5577. };
  5578.  
  5579. class DeviznaTransakcija: public Transakcija
  5580. {
  5581. private:
  5582.     char valuta[3];
  5583. public:
  5584.     DeviznaTransakcija(int d, int m, int g, double iznos,char* v):Transakcija(d, m, g, iznos)
  5585.     {
  5586.         if(strcmp(v,"EUR")==0 || strcmp(v,"USD")==0)
  5587.             strcpy(valuta, v);
  5588.         else
  5589.             throw NotSupportedCurrencyException(v);
  5590.     }
  5591.     double voDenari()
  5592.     {
  5593.         if(strcmp(valuta, "EUR")==0)
  5594.             return parichenIznos*EUR;
  5595.         else if(strcmp(valuta, "USD")==0)
  5596.             return parichenIznos*USD;
  5597.         else
  5598.             return parichenIznos;
  5599.     }
  5600.     void pecati()
  5601.     {
  5602.         cout<<den<<"/"<<mesec<<"/"<<godina<<" "<<parichenIznos<<" "<<valuta<<endl;
  5603.     }
  5604. };
  5605.  
  5606. class Smetka
  5607. {
  5608. private:
  5609.     Transakcija **transakcii;
  5610.     int brojTransakcii;
  5611.     char IDsmetka[50];
  5612.     double saldo;
  5613. public:
  5614.     Smetka(const char *ID, double sal)
  5615.     {
  5616.         strcpy(IDsmetka, ID);
  5617.         saldo=sal;
  5618.         transakcii=new Transakcija*[0];
  5619.         brojTransakcii=0;
  5620.     }
  5621.     Smetka &operator += (Transakcija *t)
  5622.     {
  5623.         Transakcija **temp=new Transakcija*[brojTransakcii+1];
  5624.         for(int i=0; i<brojTransakcii; i++)
  5625.         {
  5626.             temp[i]=transakcii[i];
  5627.         }
  5628.         temp[brojTransakcii++]=t;
  5629.         transakcii=temp;
  5630.         return *this;
  5631.     }
  5632.     void izvestajVoDenari()
  5633.     {
  5634.         double vk=saldo;
  5635.         for(int i=0; i<brojTransakcii; i++)
  5636.         {
  5637.             vk+=transakcii[i]->voDenari();
  5638.         }
  5639.         cout<<"Korisnikot so smetka: "<<IDsmetka<<" ima momentalno saldo od "<<vk<<" MKD"<<endl;
  5640.     }
  5641.     void pecatiTransakcii()
  5642.     {
  5643.         for(int i=0; i<brojTransakcii; i++)
  5644.         {
  5645.             transakcii[i]->pecati();
  5646.         }
  5647.     }
  5648.     ~Smetka()
  5649.     {
  5650.         for(int i=0; i<brojTransakcii; i++)
  5651.         {
  5652.             delete transakcii[i];
  5653.         }
  5654.         delete [] transakcii;
  5655.     }
  5656. };
  5657. int main ()
  5658. {
  5659.  
  5660.     Smetka s ("300047024112789",1500);
  5661.  
  5662.     int n, den, mesec, godina, tip;
  5663.     double iznos;
  5664.     char valuta [3];
  5665.  
  5666.     cin>>n;
  5667.     cout<<"===VNESUVANJE NA TRANSAKCIITE I SPRAVUVANJE SO ISKLUCOCI==="<<endl;
  5668.     for (int i=0; i<n; i++)
  5669.     {
  5670.         cin>>tip>>den>>mesec>>godina>>iznos;
  5671.         if (tip==2)
  5672.         {
  5673.             cin>>valuta;
  5674.             try
  5675.             {
  5676.                 Transakcija * t = new DeviznaTransakcija(den,mesec,godina,iznos,valuta);
  5677.                 s+=t;
  5678.             }
  5679.             catch (InvalidDataException id)
  5680.             {
  5681.                 id.message();
  5682.             }
  5683.             catch(NotSupportedCurrencyException c)
  5684.             {
  5685.                 c.message();
  5686.             }
  5687.             //delete t;
  5688.         }
  5689.         else
  5690.         {
  5691.             try
  5692.             {
  5693.                 Transakcija * t = new DenarskaTransakcija(den,mesec,godina,iznos);
  5694.                 s+=t;
  5695.             }
  5696.             catch(InvalidDataException id)
  5697.             {
  5698.                 id.message();
  5699.             }
  5700.             catch(NotSupportedCurrencyException c)
  5701.             {
  5702.                 c.message();
  5703.             }
  5704.             //delete t;
  5705.         }
  5706.  
  5707.     }
  5708.     cout<<"===PECHATENJE NA SITE TRANSAKCII==="<<endl;
  5709.     s.pecatiTransakcii();
  5710.     cout<<"===IZVESHTAJ ZA SOSTOJBATA NA SMETKATA VO DENARI==="<<endl;
  5711.     s.izvestajVoDenari();
  5712.  
  5713.  
  5714.     cout<<"\n===PROMENA NA KURSOT NA EVROTO I DOLAROT===\n"<<endl;
  5715.  
  5716.  
  5717.     double newEUR, newUSD;
  5718.     cin>>newEUR>>newUSD;
  5719.     Transakcija::setEUR(newEUR);
  5720.     Transakcija::setUSD(newUSD);
  5721.     cout<<"===IZVESHTAJ ZA SOSTOJBATA NA SMETKATA VO DENARI==="<<endl;
  5722.     s.izvestajVoDenari();
  5723.  
  5724.  
  5725.  
  5726.  
  5727.     return 0;
  5728. }
  5729.  
  5730. //28. Броеви (само искчучоци)
  5731. #include <iostream>
  5732. #include <cstring>
  5733.  
  5734. using namespace std;
  5735.  
  5736. /*EXCEPTION*/
  5737. class ArithmeticException
  5738. {
  5739. private:
  5740.     char text[50];
  5741. public:
  5742.     ArithmeticException(const char *t)
  5743.     {
  5744.         strcpy(text, t);
  5745.     }
  5746.     void print()
  5747.     {
  5748.         cout<<text<<endl;
  5749.     }
  5750. };
  5751.  
  5752. class NumbersNotDivisibleException
  5753. {
  5754. private:
  5755.     int broj;
  5756. public:
  5757.     NumbersNotDivisibleException(int a)
  5758.     {
  5759.         broj=a;
  5760.     }
  5761.     void print()
  5762.     {
  5763.         cout<<"Division by "<<broj<<" is not supported"<<endl;
  5764.     }
  5765. };
  5766.  
  5767. class ArrayFullException
  5768. {
  5769. private:
  5770.     char text[50];
  5771. public:
  5772.     ArrayFullException(const char *t)
  5773.     {
  5774.         strcpy(text, t);
  5775.     }
  5776.     void print()
  5777.     {
  5778.         cout<<text<<endl;
  5779.     }
  5780. };
  5781.  
  5782. class IndexOutOfBoundsException
  5783. {
  5784. private:
  5785.     int broj;
  5786. public:
  5787.     IndexOutOfBoundsException(int a)
  5788.     {
  5789.         broj=a;
  5790.     }
  5791.     void print()
  5792.     {
  5793.         cout<<"Index "<<broj<<" is out of bounds"<<endl;
  5794.     }
  5795. };
  5796.  
  5797. class NumberIsNotPositiveException
  5798. {
  5799. private:
  5800.     int broj;
  5801. public:
  5802.     NumberIsNotPositiveException(int a)
  5803.     {
  5804.         broj=a;
  5805.     }
  5806.     void print()
  5807.     {
  5808.         cout<<"Number "<<broj<<" is not positive integer"<<endl;
  5809.     }
  5810. };
  5811.  
  5812. class PositiveIntegers
  5813. {
  5814. private:
  5815.     int *broevi;
  5816.     int elementi;
  5817.     int capacity;
  5818. public:
  5819.     PositiveIntegers()
  5820.     {
  5821.         broevi=new int[0];
  5822.         elementi=0;
  5823.     }
  5824.     PositiveIntegers(int c)
  5825.     {
  5826.         broevi=new int[0];
  5827.         elementi=0;
  5828.         capacity=c;
  5829.     }
  5830.     void increaseCapacity(int c)
  5831.     {
  5832.         capacity+=c;
  5833.     }
  5834.     PositiveIntegers &operator += (const int &a)
  5835.     {
  5836.         if(elementi+1>capacity)
  5837.             throw ArrayFullException("The array is full. Increase the capacity");
  5838.         else if(a<=0)
  5839.             throw NumberIsNotPositiveException(a);
  5840.         int *temp=new int[elementi];
  5841.         for(int i=0; i<elementi; i++)
  5842.         {
  5843.             temp[i]=broevi[i];
  5844.         }
  5845.         delete [] broevi;
  5846.         broevi=new int[elementi+1];
  5847.         for(int i=0; i<elementi; i++)
  5848.         {
  5849.             broevi[i]=temp[i];
  5850.         }
  5851.         broevi[elementi++]=a;
  5852.         delete [] temp;
  5853.         return *this;
  5854.     }
  5855.     PositiveIntegers (const PositiveIntegers &p)
  5856.     {
  5857.         broevi=new int[p.elementi];
  5858.         elementi=p.elementi;
  5859.         capacity=p.capacity;
  5860.         for(int i=0; i<elementi; i++)
  5861.         {
  5862.             broevi[i]=p.broevi[i];
  5863.         }
  5864.     }
  5865.     PositiveIntegers &operator = (const PositiveIntegers &p)
  5866.     {
  5867.         delete [] broevi;
  5868.         broevi=new int[p.elementi];
  5869.         elementi=p.elementi;
  5870.         capacity=p.capacity;
  5871.         for(int i=0; i<elementi; i++)
  5872.         {
  5873.             broevi[i]=p.broevi[i];
  5874.         }
  5875.         return *this;
  5876.        
  5877.     }
  5878.     PositiveIntegers operator * (const int a)
  5879.     {
  5880.         PositiveIntegers nov(*this);
  5881.         for(int i=0; i<elementi; i++)
  5882.         {
  5883.             nov.broevi[i]*=a;
  5884.         }
  5885.         return nov;
  5886.     }
  5887.     PositiveIntegers operator / (int a)
  5888.     {
  5889.         if(a==0)
  5890.             throw ArithmeticException("Division by zero is not allowed");
  5891.         PositiveIntegers nov(*this);
  5892.         for(int i=0; i<elementi; i++)
  5893.         {
  5894.             if(nov.broevi[i]%a!=0)
  5895.                 throw NumbersNotDivisibleException(a);
  5896.         }
  5897.         for(int i=0; i<elementi; i++)
  5898.         {
  5899.             nov.broevi[i]/=a;
  5900.         }
  5901.         return nov;
  5902.     }
  5903.     int &operator [] (int a)
  5904.     {
  5905.         if(a<0 || a>=elementi)
  5906.             throw IndexOutOfBoundsException(a);
  5907.         return broevi[a];
  5908.     }
  5909.     void print()
  5910.     {
  5911.         cout<<"Size: "<<elementi<<" Capacity: "<<capacity<<" Numbers: ";
  5912.         for(int i=0; i<elementi; i++)
  5913.         {
  5914.             cout<<broevi[i]<<" ";
  5915.         }
  5916.         cout<<endl;
  5917.     }
  5918. };
  5919. int main()
  5920. {
  5921.     int n, capacity;
  5922.     cin>>n>>capacity;
  5923.     PositiveIntegers pi (capacity);
  5924.     for(int i=0; i<n; i++)
  5925.     {
  5926.         int number;
  5927.         cin>>number;
  5928.         try
  5929.         {
  5930.             pi+=number;
  5931.         }
  5932.         catch(ArrayFullException af)
  5933.         {
  5934.             af.print();
  5935.  
  5936.         }
  5937.         catch(NumberIsNotPositiveException np)
  5938.         {
  5939.             np.print();
  5940.         }
  5941.     }
  5942.     cout<<"===FIRST ATTEMPT TO ADD NUMBERS==="<<endl;
  5943.     pi.print();
  5944.     int incCapacity;
  5945.     cin>>incCapacity;
  5946.     pi.increaseCapacity(incCapacity);
  5947.     cout<<"===INCREASING CAPACITY==="<<endl;
  5948.     pi.print();
  5949.  
  5950.     int n1;
  5951.     cin>>n1;
  5952.     for(int i=0; i<n1; i++)
  5953.     {
  5954.         int number;
  5955.         cin>>number;
  5956.         try
  5957.         {
  5958.             pi+=number;
  5959.         }
  5960.         catch(ArrayFullException af)
  5961.         {
  5962.             af.print();
  5963.         }
  5964.         catch(NumberIsNotPositiveException np)
  5965.         {
  5966.             np.print();
  5967.         }
  5968.     }
  5969.  
  5970.     cout<<"===SECOND ATTEMPT TO ADD NUMBERS==="<<endl;
  5971.     pi.print();
  5972.     PositiveIntegers pi1;
  5973.     cout<<"===TESTING DIVISION==="<<endl;
  5974.     try
  5975.     {
  5976.         pi1=pi/0;
  5977.         pi1.print();
  5978.     }
  5979.     catch(NumbersNotDivisibleException nd)
  5980.     {
  5981.         nd.print();
  5982.     }
  5983.     catch(ArithmeticException ar)
  5984.     {
  5985.         ar.print();
  5986.     }
  5987.     try
  5988.     {
  5989.         pi1=pi/1;
  5990.         pi1.print();
  5991.     }
  5992.     catch(NumbersNotDivisibleException nd)
  5993.     {
  5994.         nd.print();
  5995.     }
  5996.     catch(ArithmeticException ar)
  5997.     {
  5998.         ar.print();
  5999.     }
  6000.     try
  6001.     {
  6002.         pi1=pi/2;
  6003.         pi1.print();
  6004.     }
  6005.     catch(NumbersNotDivisibleException nd)
  6006.     {
  6007.         nd.print();
  6008.     }
  6009.     catch(ArithmeticException ar)
  6010.     {
  6011.         ar.print();
  6012.     }
  6013.  
  6014.     cout<<"===TESTING MULTIPLICATION==="<<endl;
  6015.     pi1=pi*3;
  6016.     pi1.print();
  6017.  
  6018.     cout<<"===TESTING [] ==="<<endl;
  6019.     try
  6020.     {
  6021.         cout<<"PositiveIntegers[-1] = "<<pi[-1]<<endl;
  6022.     }
  6023.     catch(IndexOutOfBoundsException ib)
  6024.     {
  6025.         ib.print();
  6026.     }
  6027.     try
  6028.     {
  6029.         cout<<"PositiveIntegers[2] = "<<pi[2]<<endl;
  6030.     }
  6031.     catch(IndexOutOfBoundsException ib)
  6032.     {
  6033.         ib.print();
  6034.     }
  6035.     try
  6036.     {
  6037.         cout<<"PositiveIntegers[3] = "<<pi[3]<<endl;
  6038.     }
  6039.     catch(IndexOutOfBoundsException ib)
  6040.     {
  6041.         ib.print();
  6042.     }
  6043.     try
  6044.     {
  6045.         cout<<"PositiveIntegers[12] = "<<pi[12]<<endl;
  6046.     }
  6047.     catch(IndexOutOfBoundsException ib)
  6048.     {
  6049.         ib.print();
  6050.     }
  6051.     return 0;
  6052. }
  6053.  
  6054. //29. Едноставен датотечен систем
  6055. #include<iostream>
  6056. #include<cstring>
  6057. using namespace std;
  6058.  
  6059. class FileAlreadyExists
  6060. {
  6061. private:
  6062.     char text[50];
  6063.  
  6064. public:
  6065.     FileAlreadyExists(const char *t)
  6066.     {
  6067.         strcpy(text, t);
  6068.     }
  6069.  
  6070.     void message(){
  6071.         cout<<"File with name "<<text<<" already exists in this folder"<<endl;
  6072.     }
  6073. };
  6074.  
  6075. class FileInformation
  6076. {
  6077. protected:
  6078.     char ime[50];
  6079.     double golemina;
  6080.     bool read;
  6081.     bool write;
  6082.     bool execute;
  6083. public:
  6084.     FileInformation(){}
  6085.     FileInformation(char *i, double g, bool r, bool w, bool e)
  6086.     {
  6087.         strcpy(ime, i);
  6088.         golemina=g;
  6089.         read=r;
  6090.         write=w;
  6091.         execute=e;
  6092.     }
  6093.     virtual void printFileInfo() {}
  6094.     virtual double totalFileMemory()=0;
  6095.     bool checkPermissionsAndSize (bool r, bool w, bool x, double size)
  6096.     {
  6097.         return (read==r&&write==w&&execute==x&&golemina<size);
  6098.     }
  6099.     char *getIme()
  6100.     {
  6101.         return ime;
  6102.     }
  6103. };
  6104.  
  6105. bool operator > (FileInformation &f1, FileInformation &f2)
  6106. {
  6107.     return f1.totalFileMemory()>f2.totalFileMemory();
  6108. }
  6109.  
  6110. class File:public FileInformation
  6111. {
  6112. public:
  6113.     File():FileInformation(){}
  6114.     File(char *i, double g, bool r, bool w, bool e):FileInformation(i, g, r, w, e) {}
  6115.     void printFileInfo()
  6116.     {
  6117.         cout<<"-";
  6118.         if(read)
  6119.             cout<<"r";
  6120.         else
  6121.             cout<<"-";
  6122.         if(write)
  6123.             cout<<"w";
  6124.         else
  6125.             cout<<"-";
  6126.         if(execute)
  6127.             cout<<"x ";
  6128.         else
  6129.             cout<<"- ";
  6130.         cout<<ime<<" "<<golemina<<endl;
  6131.     }
  6132.     double totalFileMemory()
  6133.     {
  6134.         return golemina;
  6135.     }
  6136.     bool sameName(File &f)
  6137.     {
  6138.         return (strcmp(ime, f.ime)==0);
  6139.     }
  6140. };
  6141.  
  6142. class Folder:public FileInformation
  6143. {
  6144. private:
  6145.     File *fajl;
  6146.     int brojFajlovi;
  6147. public:
  6148.     Folder(char *i, bool r, bool w, bool e):FileInformation(i, 0, r, w, e)
  6149.     {
  6150.         fajl=new File[0];
  6151.         brojFajlovi=0;
  6152.     }
  6153.     Folder &operator += (File &f)
  6154.     {
  6155.         for(int i=0; i<brojFajlovi; i++)
  6156.         {
  6157.             if(fajl[i].sameName(f))
  6158.                 throw FileAlreadyExists(f.getIme());  
  6159.         }  
  6160.         File *temp=new File[brojFajlovi];
  6161.         for(int i=0; i<brojFajlovi; i++)
  6162.         {
  6163.             temp[i]=fajl[i];
  6164.         }
  6165.         delete [] fajl;
  6166.         fajl=new File[brojFajlovi+1];
  6167.         for(int i=0; i<brojFajlovi; i++)
  6168.         {
  6169.             fajl[i]=temp[i];
  6170.         }
  6171.         fajl[brojFajlovi++]=f;
  6172.         golemina+=f.totalFileMemory();
  6173.         delete [] temp;
  6174.         return *this;
  6175.     }
  6176.     File* getFajlovi()
  6177.     {
  6178.         return fajl;
  6179.     }
  6180.     int getBrojFajlovi()
  6181.     {
  6182.         return brojFajlovi;
  6183.     }
  6184.     void printFileInfo()
  6185.     {
  6186.         cout<<"d";
  6187.         if(read)
  6188.             cout<<"r";
  6189.         else
  6190.             cout<<"-";
  6191.         if(write)
  6192.             cout<<"w";
  6193.         else
  6194.             cout<<"-";
  6195.         if(execute)
  6196.             cout<<"x ";
  6197.         else
  6198.             cout<<"- ";
  6199.         cout<<ime<<" "<<golemina<<endl;
  6200.         for(int i=0; i<brojFajlovi; i++)
  6201.         {
  6202.             cout<<" ";
  6203.             fajl[i].printFileInfo();
  6204.         }
  6205.     }
  6206.     double totalFileMemory()
  6207.     {
  6208.         double vk=0;
  6209.         for(int i=0; i<brojFajlovi; i++)
  6210.         {
  6211.             vk+=fajl[i].totalFileMemory();
  6212.         }
  6213.         return vk;
  6214.     }
  6215. };
  6216.  
  6217. class FileSystem
  6218. {
  6219. public:
  6220.     static void printFileSystem(FileInformation ** fi, int n)
  6221.     {
  6222.         for(int i=0; i<n; i++)
  6223.         {
  6224.             fi[i]->printFileInfo();
  6225.         }
  6226.     }
  6227.  
  6228.     static void printFileWithMaxSize(FileInformation **fi, int n)
  6229.     {
  6230.         double maxMem=0;
  6231.         int index;
  6232.         for(int i=0; i<n; i++)
  6233.         {
  6234.             if(maxMem<fi[i]->totalFileMemory())
  6235.             {
  6236.                 maxMem=fi[i]->totalFileMemory();
  6237.                 index=i;
  6238.             }
  6239.         }
  6240.         fi[index]->printFileInfo();
  6241.     }
  6242.  
  6243.     static void printFilesLessThanWithPermissions(FileInformation ** fi, int n, bool r, bool w, bool x, double size)
  6244.     {
  6245.         for(int i=0; i<n; i++)
  6246.         {
  6247.             Folder *temp=dynamic_cast<Folder*>(fi[i]);
  6248.             if(temp!=0)
  6249.                 for(int j=0; j<temp->getBrojFajlovi(); j++)
  6250.             {
  6251.                 if(temp->getFajlovi()[j].checkPermissionsAndSize(r, w, x, size))
  6252.                     temp->getFajlovi()[j].printFileInfo();
  6253.             }
  6254.             else
  6255.             {
  6256.                 File *temp=dynamic_cast<File*>(fi[i]);
  6257.                 if(temp->checkPermissionsAndSize(r, w, x, size))
  6258.                     temp->printFileInfo();
  6259.             }
  6260.         }
  6261.     }
  6262.  
  6263.  
  6264. };
  6265.  
  6266.  
  6267. int main()
  6268. {
  6269.  
  6270.     int n;
  6271.     cin>>n;
  6272.     FileInformation ** fi = new FileInformation * [n];
  6273.  
  6274.     for (int i=0; i<n; i++)
  6275.     {
  6276.         char name [50];
  6277.         bool read, write, execute;
  6278.         double size;
  6279.         int type;
  6280.  
  6281.         cin>>type;
  6282.         if (type==1)   //File
  6283.         {
  6284.             cin>>name>>size>>read>>write>>execute;
  6285.             fi[i] = new File(name,size,read,write,execute);
  6286.         }
  6287.         else   //Folder
  6288.         {
  6289.             cin>>name>>read>>write>>execute;
  6290.             fi[i] = new Folder(name,read,write,execute);
  6291.             int N;
  6292.             cin>>N;
  6293.             for (int j=0; j<N; j++)
  6294.             {
  6295.                 //cin>>N;
  6296.                 cin>>name>>size>>read>>write>>execute;
  6297.                 File f = File(name,size,read,write,execute);
  6298.                 Folder * folder = dynamic_cast<Folder *>(fi[i]);
  6299.                 try{
  6300.                 (*folder)+=f;
  6301.                 }
  6302.                 catch(FileAlreadyExists fe)
  6303.                 {
  6304.                     fe.message();
  6305.                 }
  6306.             }
  6307.         }
  6308.     }
  6309.  
  6310.     cout<<"===TESTING printFileSystem()==="<<endl;
  6311.     FileSystem::printFileSystem(fi,n);
  6312.     cout<<"===TESTING printFileWithMaxSize()==="<<endl;
  6313.     FileSystem::printFileWithMaxSize(fi,n);
  6314.     cout<<"===TESTING printFilesLessThanWithPermissions()==="<<endl;
  6315.     FileSystem::printFilesLessThanWithPermissions(fi,n,1,1,1,20.5);
  6316.     return 0;
  6317. }
  6318.  
  6319. //30. Скијачки центар
  6320. #include<stdio.h>
  6321. #include<string.h>
  6322.  
  6323. typedef struct SkiLift{
  6324.     char ime[20];
  6325.     int max_skijaci;
  6326.     int voUpotreba;
  6327. }skiLift;
  6328.  
  6329. typedef struct SkiCenter {
  6330.     char ime[20];
  6331.     char drzava[20];
  6332.     skiLift niza[20];
  6333.     int br_lifts;
  6334. }skiCenter;
  6335.  
  6336. int kapacitet(skiCenter sc)
  6337. {
  6338.     int i;
  6339.     int tmp = 0;
  6340.     for (i = 0; i < sc.br_lifts; i++)
  6341.     {
  6342.         if (sc.niza[i].voUpotreba == 1)
  6343.         {
  6344.             tmp += sc.niza[i].max_skijaci;
  6345.         }
  6346.     }
  6347.     return tmp;
  6348.  
  6349. }
  6350. void najgolemKapacitet(skiCenter *sc, int n)
  6351. {
  6352.     int tmp, i, j, max, max_ind;
  6353.     max = 0;
  6354.     max_ind = 0;
  6355.     for (i = 0; i < n; i++)
  6356.     {
  6357.         tmp = kapacitet(sc[i]);
  6358.         if ((tmp > max) || (tmp == max&&sc[i].br_lifts > sc[max_ind].br_lifts)) { max = tmp; max_ind = i; }
  6359.     }
  6360.     printf("%s\n%s\n%d\n", sc[max_ind].ime, sc[max_ind].drzava, max);
  6361. }
  6362.  
  6363. int main()
  6364. {
  6365.     int i, j, n, broj;
  6366.     skiCenter sc[20];
  6367.     scanf("%d", &n);
  6368.     for (i = 0; i < n; i++){
  6369.         //printf("Ime:");
  6370.         scanf("%s", sc[i].ime);
  6371.         //printf("\nDrzava:");
  6372.         scanf("%s", sc[i].drzava);
  6373.         scanf("%d", &sc[i].br_lifts);
  6374.        
  6375.         for (j = 0; j < sc[i].br_lifts; j++){
  6376.             scanf("%s", sc[i].niza[j].ime);
  6377.             scanf("%d", &sc[i].niza[j].max_skijaci);
  6378.             scanf("%d", &sc[i].niza[j].voUpotreba);
  6379.         }
  6380.     }
  6381.     najgolemKapacitet(sc, n);
  6382.    
  6383.     return 0;
  6384. }
  6385. //31. Компјутерска игра
  6386. #include<iostream>
  6387. using namespace std;
  6388. struct Igrac
  6389. {
  6390.     char ime[15];
  6391.     int nivo;
  6392.     int osvoenipoeni;
  6393. };
  6394.  
  6395. struct KompjuterskaIgra
  6396. {
  6397.     char ime[20];
  6398.     Igrac igraci[20];
  6399.     int broj;
  6400. };
  6401.  
  6402. void najdobarIgrac(KompjuterskaIgra *lista,int n)
  6403. {
  6404.     int maxbroj=0;
  6405.     int indeks1=0;
  6406.     for(int i=0;i<n;i++)
  6407.     {
  6408.         if(lista[i].broj>=maxbroj)
  6409.         {
  6410.             maxbroj=lista[i].broj;
  6411.             indeks1=i;
  6412.         }
  6413.     }
  6414.     int maxpoeni=0;
  6415.     int indeks=0;
  6416.     int maxnivo=0;
  6417.     for(int i=0;i<n;i++)
  6418.     {
  6419.         for(int j=0;j<lista[i].broj;j++)
  6420.         {
  6421.             if(lista[i].igraci[j].osvoenipoeni>maxpoeni)
  6422.             {
  6423.                 maxpoeni=lista[i].igraci[j].osvoenipoeni;
  6424.                 indeks=j;
  6425.                 maxnivo=lista[i].igraci[j].nivo;
  6426.             }else if(lista[i].igraci[j].osvoenipoeni==maxpoeni)
  6427.             {
  6428.                 if(lista[i].igraci[j].nivo>maxnivo)
  6429.                 {
  6430.                     maxnivo=lista[i].igraci[j].nivo;
  6431.                     maxpoeni=lista[i].igraci[j].osvoenipoeni;
  6432.                     indeks=j;
  6433.                 }
  6434.             }
  6435.         }
  6436.     }
  6437.     cout<<"Najdobar igrac e igracot so korisnicko ime ";
  6438.     cout<<lista[indeks1].igraci[indeks].ime<<" koj ja igra igrata "<<lista[indeks1].ime<<endl;
  6439. }
  6440.  
  6441. int main() {
  6442.     int n,m;
  6443.     char ime[20];
  6444.     cin>>n;
  6445.     KompjuterskaIgra poleigri[100];
  6446.     for (int i=0; i<n; i++) {
  6447.         KompjuterskaIgra nova;
  6448.         cin>>nova.ime>>nova.broj;
  6449.         Igrac pole[30];
  6450.         for (int j=0; j<nova.broj; j++) {
  6451.             Igrac nov;
  6452.             cin>>nov.ime>>nov.nivo>>nov.osvoenipoeni;
  6453.             nova.igraci[j]=nov;
  6454.         }
  6455.         poleigri[i]=nova;
  6456.     }
  6457.  
  6458.     najdobarIgrac(poleigri,n);
  6459.     return 0;
  6460. }
  6461. //32. Железничка станица
  6462. #include<iostream>
  6463. #include <cstring>
  6464. using namespace std;
  6465.  
  6466. struct Voz
  6467. {
  6468.     char relacija[50];
  6469.     float pat;
  6470.     int patnici;
  6471. };
  6472.  
  6473. struct ZeleznickaStanica
  6474. {
  6475.     char grad[25];
  6476.     Voz vozovi[30];
  6477.     int vozBr;
  6478. };
  6479.  
  6480. void najkratkaRelacija(ZeleznickaStanica* zs, int n, char* grad)
  6481. {
  6482.     int k;
  6483.     char pomRelacija[50];
  6484.     int pomPat=999999;
  6485.    
  6486.     for(int i=0; i<n; i++)
  6487.     {
  6488.         for(int j=0; j<zs[i].vozBr; j++)
  6489.         {
  6490.            
  6491.             char pochetna[25];
  6492.            
  6493.             for(k=0; k<25; k++)
  6494.             {
  6495.                 if(zs[i].vozovi[j].relacija[k]=='-')
  6496.                 break;
  6497.                 else
  6498.                 pochetna[k]=zs[i].vozovi[j].relacija[k];
  6499.             }
  6500.             pochetna[k]='\0';
  6501.        
  6502.             if(strcmp(grad,pochetna)==0)
  6503.             {
  6504.                 if(zs[i].vozovi[j].pat<=pomPat)
  6505.                 {
  6506.                     pomPat=zs[i].vozovi[j].pat;
  6507.                     strcpy(pomRelacija,zs[i].vozovi[j].relacija);
  6508.                 }
  6509.                    
  6510.             }
  6511.         }
  6512.        
  6513.     }
  6514.     cout<<"Najkratka relacija: "<<pomRelacija<<" ("<<pomPat<<" km)"<<endl;
  6515.    
  6516.    
  6517.    
  6518. }
  6519. int main(){
  6520.  
  6521.     int n;
  6522.     cin>>n; //se cita brojot na zelezlnichki stanici
  6523.    
  6524.     ZeleznickaStanica zStanica[100];
  6525.     for (int i=0;i<n;i++){
  6526.         //se citaat infomracii za n zelezlnichkite stanici i se zacuvuvaat vo poleto zStanica
  6527.         cin>>zStanica[i].grad>>zStanica[i].vozBr;
  6528.         for(int j=0; j<zStanica[i].vozBr; j++)
  6529.         {
  6530.             cin>>zStanica[i].vozovi[j].relacija;
  6531.             cin>>zStanica[i].vozovi[j].pat;
  6532.             cin>>zStanica[i].vozovi[j].patnici;
  6533.         }
  6534.     }
  6535.  
  6536.     char grad[25];
  6537.     cin>>grad;
  6538.  
  6539.     najkratkaRelacija(zStanica,n,grad);
  6540.     return 0;
  6541. }
  6542.  
  6543. //33. CD
  6544. #include<iostream>
  6545. #include<cstring>
  6546. using namespace std;
  6547.  
  6548. enum tip{pop, rap, rok};
  6549.  
  6550. class Pesna
  6551. {
  6552.     char *ime;
  6553.     int vreme;
  6554.     tip t;
  6555. public:
  6556.     Pesna()
  6557.     {
  6558.         ime=new char[0];
  6559.     }
  6560.     Pesna(char *i, int v, tip t1)
  6561.     {
  6562.         ime=new char[strlen(i)+1];
  6563.         strcpy(ime,i);
  6564.         vreme=v;
  6565.         t=t1;
  6566.     }
  6567.     Pesna(Pesna &p)
  6568.     {
  6569.         ime=new char[strlen(p.ime)+1];
  6570.         strcpy(ime,p.ime);
  6571.         vreme=p.vreme;
  6572.         t=p.t;
  6573.     }
  6574.     Pesna& operator =(Pesna &p)
  6575.     {
  6576.         if(this!=&p)
  6577.         {
  6578.             delete [] ime;
  6579.             ime=new char [strlen(p.ime)+1];
  6580.             strcpy(ime,p.ime);
  6581.             vreme=p.vreme;
  6582.             t=p.t;
  6583.         }
  6584.         return *this;
  6585.     }
  6586.     void pecati()
  6587.     {
  6588.         cout<<"\""<<ime<<"\"-"<<vreme<<"min"<<endl;
  6589.     }
  6590.     int getVreme()
  6591.     {
  6592.         return vreme;
  6593.     }
  6594.     tip getTip()
  6595.     {
  6596.         return t;
  6597.     }
  6598.     ~Pesna()
  6599.     {
  6600.         delete [] ime;
  6601.     }
  6602.  
  6603. };
  6604.  
  6605. class CD
  6606. {
  6607.     Pesna pesni[10];
  6608.     int brojPesni;
  6609.     int vremetraenje;
  6610. public:
  6611.     CD(int v)
  6612.     {
  6613.         vremetraenje=v;
  6614.         brojPesni=0;
  6615.     }
  6616.     Pesna& getPesna(int i)
  6617.     {
  6618.         return pesni[i];
  6619.     }
  6620.     int getBroj()
  6621.     {
  6622.         return brojPesni;
  6623.     }
  6624.     void dodadiPesna (Pesna p)
  6625.     {
  6626.         int vkupno=0;
  6627.         for(int i=0; i<brojPesni; i++)
  6628.         {
  6629.             vkupno+=pesni[i].getVreme();
  6630.         }
  6631.         if((vkupno+p.getVreme()<=vremetraenje)&&(brojPesni<10))
  6632.         {
  6633.             pesni[brojPesni]=p;
  6634.             brojPesni++;
  6635.         }
  6636.     }
  6637.     void pecatiPesniPoTip(tip t)
  6638.     {
  6639.         for(int i=0; i<brojPesni; i++)
  6640.         {
  6641.             if(pesni[i].getTip()==t)
  6642.             {
  6643.                 pesni[i].pecati();
  6644.             }
  6645.         }
  6646.     }
  6647. };
  6648.  
  6649. int main() {
  6650.     // se testira zadacata modularno
  6651.     int testCase;
  6652.     cin >> testCase;
  6653.  
  6654.     int n, minuti, kojtip;
  6655.     char ime[50];
  6656.  
  6657.     if(testCase == 1) {
  6658.         cout << "===== Testiranje na klasata Pesna ======" << endl;
  6659.         cin >> ime;
  6660.         cin >> minuti;
  6661.         cin >> kojtip; //se vnesuva 0 za POP,1 za RAP i 2 za ROK
  6662.         Pesna p(ime,minuti,(tip)kojtip);
  6663.         p.pecati();
  6664.     } else if(testCase == 2) {
  6665.         cout << "===== Testiranje na klasata CD ======" << endl;
  6666.         CD omileno(20);
  6667.         cin>>n;
  6668.             for (int i=0;i<n;i++){
  6669.                 cin >> ime;
  6670.                 cin >> minuti;
  6671.                 cin >> kojtip; //se vnesuva 0 za POP,1 za RAP i 2 za ROK
  6672.                 Pesna p(ime,minuti,(tip)kojtip);
  6673.                 omileno.dodadiPesna(p);
  6674.             }
  6675.             for (int i=0; i<n; i++)
  6676.                 (omileno.getPesna(i)).pecati();
  6677.     }
  6678.     else if(testCase == 3) {
  6679.         cout << "===== Testiranje na metodot dodadiPesna() od klasata CD ======" << endl;
  6680.         CD omileno(20);
  6681.         cin>>n;
  6682.             for (int i=0;i<n;i++){
  6683.                 cin >> ime;
  6684.                 cin >> minuti;
  6685.                 cin >> kojtip; //se vnesuva 0 za POP,1 za RAP i 2 za ROK
  6686.                 Pesna p(ime,minuti,(tip)kojtip);
  6687.                 omileno.dodadiPesna(p);
  6688.             }
  6689.             for (int i=0; i<omileno.getBroj(); i++)
  6690.                 (omileno.getPesna(i)).pecati();
  6691.     }
  6692.     else if(testCase == 4) {
  6693.         cout << "===== Testiranje na metodot pecatiPesniPoTip() od klasata CD ======" << endl;
  6694.         CD omileno(20);
  6695.         cin>>n;
  6696.             for (int i=0;i<n;i++){
  6697.                 cin >> ime;
  6698.                 cin >> minuti;
  6699.                 cin >> kojtip; //se vnesuva 0 za POP,1 za RAP i 2 za ROK
  6700.                 Pesna p(ime,minuti,(tip)kojtip);
  6701.                 omileno.dodadiPesna(p);
  6702.             }
  6703.         cin>>kojtip;
  6704.         omileno.pecatiPesniPoTip((tip)kojtip);
  6705.  
  6706.     }
  6707.     else if(testCase == 5) {
  6708.         cout << "===== Testiranje na metodot pecatiPesniPoTip() od klasata CD ======" << endl;
  6709.         CD omileno(20);
  6710.         cin>>n;
  6711.             for (int i=0;i<n;i++){
  6712.                 cin >> ime;
  6713.                 cin >> minuti;
  6714.                 cin >> kojtip; //se vnesuva 0 za POP,1 za RAP i 2 za ROK
  6715.                 Pesna p(ime,minuti,(tip)kojtip);
  6716.                 omileno.dodadiPesna(p);
  6717.             }
  6718.         cin>>kojtip;
  6719.         omileno.pecatiPesniPoTip((tip)kojtip);
  6720.  
  6721.     }
  6722.  
  6723. return 0;
  6724. }
  6725.  
  6726. //34. Пицерија
  6727. #include <iostream>
  6728. #include <cstring>
  6729.  
  6730. using namespace std;
  6731.  
  6732. class Pica {
  6733. private:
  6734.     char ime[15];
  6735.     int cena;
  6736.     char *sostojki;
  6737.     int namaluvanje;
  6738. public:
  6739.     Pica() {
  6740.         sostojki=new char[0];
  6741.     }
  6742.     Pica(char *i, int c, char *s, int n) {
  6743.         strcpy(ime,i);
  6744.         sostojki=new char[strlen(s)+1];
  6745.         cena=c;
  6746.         strcpy(sostojki, s);
  6747.         namaluvanje=n;
  6748.     }
  6749.     Pica(Pica &p) {
  6750.         strcpy(ime,p.ime);
  6751.         sostojki=new char[strlen(p.sostojki)+1];
  6752.         cena=p.cena;
  6753.         strcpy(sostojki, p.sostojki);
  6754.         namaluvanje=p.namaluvanje;
  6755.     }
  6756.     void pecati() {
  6757.         cout<<ime<<" - "<<sostojki<<", "<<cena;
  6758.     }
  6759.  
  6760.     bool istiSe(Pica p) {
  6761.         if(strcmp(sostojki,p.sostojki)==0) {
  6762.             return true;
  6763.         } else return false;
  6764.     }
  6765.  
  6766.     char *getSostojki() {
  6767.         return sostojki;
  6768.     }
  6769.  
  6770.     int getCena() {
  6771.         return cena;
  6772.     }
  6773.  
  6774.     int getNamaluvanje() {
  6775.         return namaluvanje;
  6776.     }
  6777.  
  6778.     Pica& operator = (Pica &p) {
  6779.         if(this!=&p) {
  6780.             strcpy(ime,p.ime);
  6781.             cena=p.cena;
  6782.             delete [] sostojki;
  6783.             sostojki=new char[strlen(p.sostojki)+1];
  6784.             strcpy(sostojki, p.sostojki);
  6785.             namaluvanje=p.namaluvanje;
  6786.         }
  6787.         return *this;
  6788.     }
  6789.  
  6790.     ~Pica() {
  6791.         delete [] sostojki;
  6792.     }
  6793. };
  6794.  
  6795. class Picerija {
  6796.     char ime[15];
  6797.     Pica *pici;
  6798.     int brpici;
  6799. public:
  6800.     Picerija() {
  6801.         pici=new Pica[0];
  6802.     }
  6803.     Picerija(char *i, Pica *p, int n) {
  6804.         strcpy(ime, i);
  6805.         pici = new Pica[n];
  6806.         for(int i=0; i<n; i++) {
  6807.             pici[i]=p[i];
  6808.         }
  6809.         brpici=n;
  6810.     }
  6811.     Picerija(char *i) {
  6812.         strcpy(ime,i);
  6813.         pici=new Pica[0];
  6814.         brpici=0;
  6815.     }
  6816.     Picerija(Picerija &p) {
  6817.         strcpy(ime, p.ime);
  6818.         pici=new Pica[p.brpici];
  6819.         for(int i=0; i<p.brpici; i++) {
  6820.             pici[i]=p.pici[i];
  6821.         }
  6822.         brpici=p.brpici;
  6823.     }
  6824.     Picerija &operator = (Picerija &p) {
  6825.         if(this!=&p) {
  6826.             strcpy(ime,p.ime);
  6827.             delete [] pici;
  6828.             pici=new Pica[p.brpici];
  6829.             for(int i=0; i<p.brpici; i++) {
  6830.                 pici[i]=p.pici[i];
  6831.             }
  6832.             brpici=p.brpici;
  6833.         }
  6834.         return *this;
  6835.     }
  6836.     void dodadi (Pica &p) {
  6837.         bool f=true;
  6838.         for(int i=0; i<brpici; i++) {
  6839.             if(p.istiSe(pici[i])) {
  6840.                 f=false;
  6841.             }
  6842.         }
  6843.         if(f) {
  6844.             Pica *tmp = new Pica[brpici];
  6845.             for(int i=0; i<brpici; i++) {
  6846.                 tmp[i]=pici[i];
  6847.             }
  6848.             delete [] pici;
  6849.             pici=new Pica[brpici+1];
  6850.             for(int i=0; i<brpici; i++) {
  6851.                 pici[i]=tmp[i];
  6852.             }
  6853.             pici[brpici]=p;
  6854.             ++brpici;
  6855.             delete [] tmp;
  6856.  
  6857.         }
  6858.     }
  6859.     void setIme(char *i) {
  6860.         strcpy(ime, i);
  6861.     }
  6862.     char *getIme() {
  6863.         return ime;
  6864.     }
  6865.     void piciNaPromocija() {
  6866.         for(int i=0; i<brpici; i++) {
  6867.             if(pici[i].getNamaluvanje()>0) {
  6868.                 pici[i].pecati();
  6869.                 cout<<" "<<pici[i].getCena()*(100-pici[i].getNamaluvanje())/100<<endl;
  6870.             }
  6871.         }
  6872.     }
  6873.     ~Picerija() {
  6874.         delete [] pici;
  6875.     }
  6876. };
  6877.  
  6878. int main () {
  6879.  
  6880.     int n;
  6881.     char ime[15];
  6882.     cin >> ime;
  6883.     cin >> n;
  6884.  
  6885.     Picerija p1(ime);
  6886.     for(int i = 0; i < n; i++) {
  6887.         char imp[100];
  6888.         cin.get();
  6889.         cin.getline(imp,100);
  6890.         int cena;
  6891.         cin >> cena;
  6892.         char sostojki[100];
  6893.         cin.get();
  6894.         cin.getline(sostojki,100);
  6895.         int popust;
  6896.         cin >> popust;
  6897.         Pica p(imp,cena,sostojki,popust);
  6898.         p1.dodadi(p);
  6899.     }
  6900.  
  6901.     Picerija p2 = p1;
  6902.     cin >> ime;
  6903.     p2.setIme(ime);
  6904.     char imp[100];
  6905.     cin.get();
  6906.     cin.getline(imp,100);
  6907.     int cena;
  6908.     cin >> cena;
  6909.     char sostojki[100];
  6910.     cin.get();
  6911.     cin.getline(sostojki,100);
  6912.     int popust;
  6913.     cin >> popust;
  6914.     Pica p(imp,cena,sostojki,popust);
  6915.     p2.dodadi(p);
  6916.  
  6917.     cout<<p1.getIme()<<endl;
  6918.     cout<<"Pici na promocija:"<<endl;
  6919.     p1.piciNaPromocija();
  6920.  
  6921.     cout<<p2.getIme()<<endl;
  6922.     cout<<"Pici na promocija:"<<endl;
  6923.     p2.piciNaPromocija();
  6924.  
  6925.     return 0;
  6926. }
  6927.  
  6928. //35. Маратон
  6929. #include<iostream>
  6930. #include<cstring>
  6931.  
  6932. using namespace std;
  6933.  
  6934. class Ucesnik {
  6935.     char *ime;
  6936.     bool pol;
  6937.     int vozrast;
  6938. public:
  6939.     Ucesnik() {
  6940.         ime=new char[0];
  6941.     }
  6942.     Ucesnik(char *i, bool p, int v) {
  6943.         ime=new char[strlen(i)+1];
  6944.         strcpy(ime,i);
  6945.         pol=p;
  6946.         vozrast=v;
  6947.     }
  6948.     Ucesnik(Ucesnik &u) {
  6949.         ime=new char[strlen(u.ime)+1];
  6950.         strcpy(ime,u.ime);
  6951.         pol=u.pol;
  6952.         vozrast=u.vozrast;
  6953.     }
  6954.     Ucesnik &operator = (Ucesnik &u) {
  6955.         if(this!=&u) {
  6956.             delete [] ime;
  6957.             ime=new char[strlen(u.ime)+1];
  6958.             strcpy(ime,u.ime);
  6959.             pol=u.pol;
  6960.             vozrast=u.vozrast;
  6961.         }
  6962.         return *this;
  6963.     }
  6964.     bool operator > (Ucesnik &u) {
  6965.         if(vozrast>u.vozrast) {
  6966.             return true;
  6967.         } else return false;
  6968.     }
  6969.     friend ostream &operator << (ostream &os, Ucesnik &u) {
  6970.         os<<u.ime<<endl;
  6971.         if(!u.pol)
  6972.             os<<"zhenski"<<endl;
  6973.         else
  6974.             os<<"mashki"<<endl;
  6975.         os<<u.vozrast;
  6976.         return os;
  6977.     }
  6978.     int getVozrast() {
  6979.         return vozrast;
  6980.     }
  6981.     ~Ucesnik() {
  6982.         delete [] ime;
  6983.     }
  6984. };
  6985.  
  6986. class Maraton {
  6987.     char lokacija[100];
  6988.     Ucesnik *ucesnici;
  6989.     int broj;
  6990. public:
  6991.     Maraton(char *l) {
  6992.         strcpy(lokacija,l);
  6993.         ucesnici=new Ucesnik[0];
  6994.         broj=0;
  6995.     }
  6996.     Maraton(char *l, Ucesnik *u, int b) {
  6997.         ucesnici=new Ucesnik[b];
  6998.         strcpy(lokacija,l);
  6999.         for(int i=0; i<b; i++) {
  7000.             ucesnici[i]=u[i];
  7001.         }
  7002.         broj=b;
  7003.     }
  7004.     Maraton(Maraton &m) {
  7005.         ucesnici=new Ucesnik[m.broj];
  7006.         strcpy(lokacija,m.lokacija);
  7007.         for(int i=0; i<m.broj; i++) {
  7008.             ucesnici[i]=m.ucesnici[i];
  7009.         }
  7010.         broj=m.broj;
  7011.     }
  7012.     Maraton &operator += (Ucesnik &u) {
  7013.         Ucesnik *temp=new Ucesnik[broj];
  7014.         for(int i=0; i<broj; i++) {
  7015.             temp[i]=ucesnici[i];
  7016.         }
  7017.         delete [] ucesnici;
  7018.         ucesnici = new Ucesnik[broj+1];
  7019.         for(int i=0; i<broj; i++) {
  7020.             ucesnici[i]=temp[i];
  7021.         }
  7022.         ucesnici[broj]=u;
  7023.         broj++;
  7024.         delete [] temp;
  7025.         return *this;
  7026.     }
  7027.     float prosecnoVozrast() {
  7028.         float suma=0;
  7029.         for(int i=0; i<broj; i++) {
  7030.             suma+=ucesnici[i].getVozrast();
  7031.         }
  7032.         return suma/broj;
  7033.     }
  7034.     void pecatiPomladi(Ucesnik &u) {
  7035.         for(int i=0; i<broj; i++) {
  7036.             if(ucesnici[i].getVozrast() < u.getVozrast())
  7037.                 cout<<ucesnici[i]<<endl;
  7038.         }
  7039.     }
  7040.     ~Maraton() {
  7041.         delete [] ucesnici;
  7042.     }
  7043. };
  7044.  
  7045. int main() {
  7046.     char ime[100];
  7047.     bool maski;
  7048.     int vozrast, n;
  7049.     cin >> n;
  7050.     char lokacija[100];
  7051.     cin >> lokacija;
  7052.     Maraton m(lokacija);
  7053.     Ucesnik **u = new Ucesnik*[n];
  7054.     for(int i = 0; i < n; ++i) {
  7055.         cin >> ime >> maski >> vozrast;
  7056.         u[i] = new Ucesnik(ime, maski, vozrast);
  7057.         m += *u[i];
  7058.     }
  7059.     m.pecatiPomladi(*u[n - 1]);
  7060.     cout << m.prosecnoVozrast() << endl;
  7061.     for(int i = 0; i < n; ++i) {
  7062.         delete u[i];
  7063.     }
  7064.     delete [] u;
  7065.     return 0;
  7066. }
  7067. //36. Сладолед
  7068. #include <iostream>
  7069. #include <cstring>
  7070. using namespace std;
  7071.  
  7072. class IceCream {
  7073. private:
  7074.     char *name;
  7075.     char ingredients[100];
  7076.     float price;
  7077.     int discount;
  7078.     void copy(const IceCream &ic) {
  7079.         name = new char[strlen(ic.name) + 1];
  7080.         strcpy(name, ic.name);
  7081.         strncpy(ingredients, ic.ingredients, 99);
  7082.         ingredients[99] = '\0';
  7083.         price = ic.price;
  7084.         discount = ic.discount;
  7085.     }
  7086. public:
  7087.     IceCream(const char *nm = "", const char *ingr = "", float p = 0) {
  7088.         name = new char[strlen(nm) + 1];
  7089.         strcpy(name, nm);
  7090.         strncpy(ingredients, ingr, 99);
  7091.         ingredients[99] = '\0';
  7092.         price = p;
  7093.         discount = 0;
  7094.     }
  7095.  
  7096.     IceCream(const IceCream &ic) {
  7097.         copy(ic);
  7098.     }
  7099.  
  7100.     IceCream& operator=(const IceCream &ic) {
  7101.         if (this == &ic) return *this;
  7102.         delete [] name;
  7103.         copy(ic);
  7104.         return *this;
  7105.     }
  7106.  
  7107.     friend ostream& operator<<(ostream &out, const IceCream &ic) {
  7108.         out << ic.name << ": ";
  7109.         out << ic.ingredients << " ";
  7110.         out << ic.price << " ";
  7111.         if (ic.discount > 0) {
  7112.             out << "(" << ic.price * (100 - ic.discount) / 100 << ")";
  7113.         }
  7114.         return out;
  7115.     }
  7116.     void setName(char *n) {
  7117.         delete [] name;
  7118.         name = new char[strlen(n) + 1];
  7119.         strcpy(name, n);
  7120.     }
  7121.  
  7122.     IceCream& operator++() {
  7123.         discount += 5;
  7124.         return *this;
  7125.     }
  7126.  
  7127.     IceCream operator+(const char* extra) {
  7128.  
  7129.         char* newName = new char[strlen(name) + strlen(extra) + 4];
  7130.         strcat(newName, name);
  7131.         strcat(newName, " + ");
  7132.         strcat(newName, extra);
  7133.  
  7134.         IceCream res(newName, ingredients, price + 10);
  7135.         res.setDiscount(discount);
  7136.         return res;
  7137.     }
  7138.  
  7139.     void setName(const char* n) {
  7140.         delete [] name;
  7141.         name = new char[strlen(n) + 1];
  7142.         strcpy(name, n);
  7143.     }
  7144.  
  7145.     void setDiscount(int d) {
  7146.  
  7147.         if(d>=0&&d<=100)
  7148.             discount = d;
  7149.     }
  7150.  
  7151.     ~IceCream() {
  7152.         delete [] name;
  7153.     }
  7154. };
  7155.  
  7156. class IceCreamShop {
  7157. private:
  7158.     char name[50];
  7159.     IceCream *icecreams;
  7160.     int n;
  7161.     void copy(const IceCreamShop &ics) {
  7162.         strcpy(name, ics.name);
  7163.         n = ics.n;
  7164.         icecreams = new IceCream[n];
  7165.         for (int i = 0; i < n; ++i) {
  7166.             icecreams[i] = ics.icecreams[i];
  7167.         }
  7168.     }
  7169. public:
  7170.     IceCreamShop(char* nm) {
  7171.         strcpy(name, nm);
  7172.         icecreams = NULL;
  7173.         n = 0;
  7174.     }
  7175.     IceCreamShop(const IceCreamShop &ics) {
  7176.         copy(ics);
  7177.     }
  7178.     IceCreamShop& operator=(const IceCreamShop &ics) {
  7179.         if (this == &ics) return *this;
  7180.         delete [] icecreams;
  7181.         copy(ics);
  7182.         return *this;
  7183.     }
  7184.     ~IceCreamShop() {
  7185.         delete [] icecreams;
  7186.     }
  7187.  
  7188.     IceCreamShop& operator+= (IceCream &ic) {
  7189.         IceCream *tmp = icecreams;
  7190.         icecreams = new IceCream[n + 1];
  7191.         for (int i = 0; i < n; ++i) {
  7192.             icecreams[i] = tmp[i];
  7193.         }
  7194.         icecreams[n] = ic;
  7195.         ++n;
  7196.         delete [] tmp;
  7197.         return *this;
  7198.     }
  7199.  
  7200.     friend ostream& operator<<(ostream &out, const IceCreamShop &ics) {
  7201.         cout << ics.name << endl;
  7202.         for (int i = 0; i < ics.n; ++i) {
  7203.             out << ics.icecreams[i] << endl;
  7204.         }
  7205.         return out;
  7206.     }
  7207.  
  7208. };
  7209.  
  7210. int main() {
  7211.     char name[100];
  7212.     char ingr[100];
  7213.     float price;
  7214.     int discount;
  7215.  
  7216.     int testCase;
  7217.  
  7218.     cin >> testCase;
  7219.     cin.get();
  7220.     if(testCase == 1) {
  7221.         cout << "====== TESTING IceCream CLASS ======" << endl;
  7222.         cin.getline(name,100);
  7223.         cin.getline(ingr,100);
  7224.         cin >> price;
  7225.         cin >> discount;
  7226.         cout << "CONSTRUCTOR" << endl;
  7227.         IceCream ic1(name, ingr, price);
  7228.         ic1.setDiscount(discount);
  7229.         cin.get();
  7230.         cin.getline(name,100);
  7231.         cin.getline(ingr,100);
  7232.         cin >> price;
  7233.         cin >> discount;
  7234.         IceCream ic2(name, ingr, price);
  7235.         ic2.setDiscount(discount);
  7236.         cout << "OPERATOR <<" << endl;
  7237.         cout << ic1 << endl;
  7238.         cout << ic2 << endl;
  7239.         cout << "OPERATOR ++" << endl;
  7240.         ++ic1;
  7241.         cout << ic1 << endl;
  7242.         cout << "OPERATOR +" << endl;
  7243.         IceCream ic3 = ic2 + "chocolate";
  7244.         cout << ic3 << endl;
  7245.     } else if(testCase == 2) {
  7246.         cout << "====== TESTING IceCream CONSTRUCTORS ======" << endl;
  7247.         cin.getline(name,100);
  7248.         cin.getline(ingr,100);
  7249.         cin >> price;
  7250.         //cin >> discount;
  7251.         cout << "CONSTRUCTOR" << endl;
  7252.         IceCream ic1(name, ingr, price);
  7253.         cout << ic1 << endl;
  7254.         cout << "COPY CONSTRUCTOR" << endl;
  7255.         IceCream ic2(ic1);
  7256.         cin.get();
  7257.         cin.getline(name,100);
  7258.         ic2.setName(name);
  7259.         cout << ic1 << endl;
  7260.         cout << ic2 << endl;
  7261.         cout << "OPERATOR =" << endl;
  7262.         ic1 = ic2;
  7263.         cin.getline(name,100);
  7264.         ic2.setName(name);
  7265.         cout << ic1 << endl;
  7266.         cout << ic2 << endl;
  7267.  
  7268.         cin >> discount;
  7269.         ic1.setDiscount(discount);
  7270.  
  7271.  
  7272.     } else if(testCase == 3) {
  7273.         cout << "====== TESTING IceCreamShop ======" << endl;
  7274.         char icsName[50];
  7275.         cin.getline(icsName,100);
  7276.         cout << "CONSTRUCTOR" << endl;
  7277.         IceCreamShop ics(icsName);
  7278.         int n;
  7279.         cin >> n;
  7280.         cout << "OPERATOR +=" << endl;
  7281.         for(int i = 0; i < n; ++i) {
  7282.             cin.get();
  7283.             cin.getline(name,100);
  7284.             cin.getline(ingr,100);
  7285.             cin >> price;
  7286.             IceCream ic(name, ingr, price);
  7287.             ics += ic;
  7288.         }
  7289.         cout << ics;
  7290.     } else if(testCase == 4) {
  7291.         cout << "====== TESTING IceCreamShop CONSTRUCTORS ======" << endl;
  7292.         char icsName[50];
  7293.         cin.getline(icsName,100);
  7294.         IceCreamShop ics(icsName);
  7295.         int n;
  7296.         cin >> n;
  7297.         for(int i = 0; i < n; ++i) {
  7298.             cin.get();
  7299.             cin.getline(name,100);
  7300.             cin.getline(ingr,100);
  7301.             cin >> price;
  7302.             IceCream ic(name, ingr, price);
  7303.             ics += ic;
  7304.         }
  7305.         IceCream x("FINKI fruits", "strawberry ice cream, raspberry ice cream, blueberry ice cream", 60);
  7306.         IceCreamShop icp = ics;
  7307.         ics+=x;
  7308.         cout << ics << endl;
  7309.         cout << icp << endl;
  7310.     }
  7311.  
  7312.  
  7313.     return 0;
  7314. }
  7315. //37. Планинарски дом
  7316. #include<iostream>
  7317. #include<string.h>
  7318. using namespace std;
  7319.  
  7320. class Zichara
  7321. {
  7322.     char *mesto;
  7323.     int cena;
  7324. public:
  7325.     Zichara()
  7326.     {
  7327.         mesto=new char[0];
  7328.     }
  7329.     Zichara(char *m, int c)
  7330.     {
  7331.         mesto=new char[strlen(m)+1];
  7332.         strcpy(mesto,m);
  7333.         cena=c;
  7334.     }
  7335.     Zichara(Zichara &z)
  7336.     {
  7337.         mesto=new char[strlen(z.mesto)+1];
  7338.         strcpy(mesto,z.mesto);
  7339.         cena=z.cena;
  7340.     }
  7341.     int getCena()
  7342.     {
  7343.         return cena;
  7344.     }
  7345.     Zichara& operator = (Zichara &z)
  7346.     {
  7347.         if(this!=&z)
  7348.         {
  7349.             delete [] mesto;
  7350.             mesto=new char[strlen(z.mesto)+1];
  7351.             strcpy(mesto,z.mesto);
  7352.             cena=z.cena;
  7353.         }
  7354.         return *this;
  7355.     }
  7356.     ~Zichara()
  7357.     {
  7358.         delete [] mesto;
  7359.     }
  7360. };
  7361.  
  7362. class PlaninarskiDom
  7363. {
  7364.     char ime[15];
  7365.     int cenaSezona[2];
  7366.     char klasa;
  7367.     bool imaZichara;
  7368.     Zichara *pok;
  7369. public:
  7370.     PlaninarskiDom(){}
  7371.     PlaninarskiDom(char *i, int *cSezona, char k)
  7372.     {
  7373.         strcpy(ime,i);
  7374.         cenaSezona[0]=cSezona[0];
  7375.         cenaSezona[1]=cSezona[1];
  7376.         klasa=k;
  7377.     }
  7378.     PlaninarskiDom(PlaninarskiDom &p)
  7379.     {
  7380.         strcpy(ime,p.ime);
  7381.         cenaSezona[0]=p.cenaSezona[0];
  7382.         cenaSezona[1]=p.cenaSezona[1];
  7383.         klasa=p.klasa;
  7384.         imaZichara=p.imaZichara;
  7385.         pok=p.pok;
  7386.     }
  7387.     PlaninarskiDom& operator = (PlaninarskiDom &p)
  7388.     {
  7389.         strcpy(ime,p.ime);
  7390.         cenaSezona[0]=p.cenaSezona[0];
  7391.         cenaSezona[1]=p.cenaSezona[1];
  7392.         klasa=p.klasa;
  7393.         imaZichara=p.imaZichara;
  7394.         pok=p.pok;
  7395.         return *this;
  7396.     }
  7397.     void setZichara(Zichara &p)
  7398.     {
  7399.         pok=&p;
  7400.         imaZichara=1;
  7401.     }
  7402.     PlaninarskiDom& operator --()
  7403.     {
  7404.         if(klasa<'F')
  7405.            klasa++;
  7406.         return *this;
  7407.     }
  7408.     friend ostream& operator << (ostream &os,const PlaninarskiDom &p)
  7409.     {
  7410.         if(p.imaZichara)
  7411.             os<<p.ime<<" klasa:"<<p.klasa<<" so Zichara"<<endl;
  7412.         else
  7413.             os<<p.ime<<" klasa:"<<p.klasa<<endl;
  7414.         return os;
  7415.     }
  7416.     bool operator <= (char znak)
  7417.     {
  7418.         if(klasa>=znak)
  7419.             return true;
  7420.         else
  7421.             return false;
  7422.     }
  7423.     void presmetajDnevenPrestoj(int den, int mesec, int &cena)
  7424.     {
  7425.         if(mesec<1 || mesec>12)
  7426.             throw mesec;
  7427.         else if(den<1 || den>12)
  7428.             throw den;
  7429.         else
  7430.         {
  7431.             if(mesec>3&&mesec<9)
  7432.                 {
  7433.                     if(imaZichara)
  7434.                         cena=cenaSezona[0]+pok->getCena();
  7435.                     else
  7436.                         cena=cenaSezona[0];
  7437.                 }
  7438.             else
  7439.                 {
  7440.                     if(imaZichara)
  7441.                         cena=cenaSezona[1]+pok->getCena();
  7442.                     else
  7443.                         cena=cenaSezona[1];
  7444.                 }
  7445.         }
  7446.  
  7447.     }
  7448.  
  7449. };
  7450.  
  7451. int main()
  7452. {
  7453.  
  7454.     PlaninarskiDom p; //креирање на нов објект од класата планинарски дом
  7455.  
  7456.     //во следниот дел се вчитуваат информации за планинарскиот дом
  7457.     char imePlaninarskiDom[15],mestoZichara[30],klasa;
  7458.     int ceni[12];
  7459.     int dnevnakartaZichara;
  7460.     bool daliZichara;
  7461.     cin>>imePlaninarskiDom;
  7462.     for (int i=0; i<2; i++) cin>>ceni[i];
  7463.     cin>>klasa;
  7464.     cin>>daliZichara;
  7465.  
  7466.     //во следниот дел се внесуваат информации и за жичарата ако постои
  7467.     if (daliZichara)
  7468.     {
  7469.         cin>>mestoZichara>>dnevnakartaZichara;
  7470.         PlaninarskiDom pom(imePlaninarskiDom,ceni,klasa);
  7471.         Zichara r(mestoZichara,dnevnakartaZichara);
  7472.         pom.setZichara(r);
  7473.         p=pom;
  7474.     }
  7475.     else
  7476.     {
  7477.         PlaninarskiDom *pok=new PlaninarskiDom(imePlaninarskiDom,ceni,klasa);
  7478.         p=*pok;
  7479.     }
  7480.  
  7481.     //се намалува класата на планинарскиот дом за 2
  7482.     --p;
  7483.     --p;
  7484.  
  7485.     int cena;
  7486.     int den,mesec;
  7487.     cin>>den>>mesec;
  7488.     try
  7489.     {
  7490.         p.presmetajDnevenPrestoj(den,mesec,cena); //тука се користи функцијата presmetajDnevenPrestoj
  7491.         cout<<"Informacii za PlaninarskiDomot:"<<endl;
  7492.         cout<<p;
  7493.         if (p<='D')
  7494.             cout<<"Planinarskiot dom za koj se vneseni informaciite ima klasa poniska ili ista so D\n";
  7495.  
  7496.         cout<<"Cenata za "<<den<<"."<<mesec<<" e "<<cena; //се печати цената за дадениот ден и месец
  7497.     }
  7498.     catch (int)
  7499.     {
  7500.         cout<<"Mesecot ili denot e greshno vnesen!";
  7501.     }
  7502. }
  7503.  
  7504. //38. Фактура C
  7505. #include <stdio.h>
  7506. #include <string.h>
  7507.  
  7508. typedef struct Proizvod
  7509. {      
  7510.     char kod[20];
  7511.     int cena;
  7512.     int kolichina;
  7513. }Proizvod;
  7514.  
  7515. typedef struct Narachka
  7516. {
  7517.     char ime[15];
  7518.     Proizvod proizvodi[10];
  7519.     int kolichina[10];
  7520.     int n;
  7521. }Narachka;
  7522.  
  7523. void swapProizvod(Proizvod *a, Proizvod *b)
  7524. {
  7525.     char pom[20];
  7526.     int c, k;
  7527.     strcpy(pom,a->kod);
  7528.     strcpy(a->kod,b->kod);
  7529.     strcpy(b->kod,pom);
  7530.     c=a->cena;
  7531.     a->cena=b->cena;
  7532.     b->cena=c;    
  7533. }
  7534.  
  7535. void pecatiFaktura(Narachka n)
  7536. {
  7537.     int i, j;
  7538.     printf("Faktura za %s\n",n.ime);
  7539.     for(i=0; i<n.n; i++ )
  7540.         if(n.kolichina[i]>n.proizvodi[i].kolichina)
  7541.             {
  7542.                 printf("Fakturata ne moze da se izgotvi\n");
  7543.                 return;
  7544.             }
  7545.     int suma=0;
  7546.     for(i=0; i<n.n-1; i++)
  7547.     {    
  7548.        
  7549.         for(j=i+1; j<n.n; j++)
  7550.         {    
  7551.             if(strcmp(n.proizvodi[i].kod,n.proizvodi[j].kod)>0)
  7552.             {
  7553.                 swapProizvod(&n.proizvodi[i], &n.proizvodi[j]);
  7554.             }
  7555.         }
  7556.     }
  7557.     for(i=0; i<n.n; i++)
  7558.     {
  7559.         suma+=n.kolichina[i]*n.proizvodi[i].cena;
  7560.         printf("%s %d %d %d\n", n.proizvodi[i].kod, n.proizvodi[i].cena, n.kolichina[i], n.kolichina[i]*n.proizvodi[i].cena );
  7561.     }
  7562.     printf("Vkupnata suma na fakturata e %d", suma);
  7563. }
  7564.              
  7565. int main() {
  7566.  
  7567.     Narachka narachka;
  7568.  
  7569.     // внеси го името лицето кое ја прави нарачката
  7570.     scanf("%s", narachka.ime);
  7571.     // внеси го бројот на порачани производи во нарачката
  7572.     scanf("%d", &narachka.n);
  7573.     int i;
  7574.     //за секој од нарачаните производи се внесуваат информации
  7575.     for (i = 0; i < narachka.n; ++i) {
  7576.         // внеси код
  7577.         scanf("%s", narachka.proizvodi[i].kod);
  7578.         // внеси единицчна цена
  7579.         scanf("%d", &narachka.proizvodi[i].cena);
  7580.         // внеси број на производи во магацин
  7581.         scanf("%d", &narachka.proizvodi[i].kolichina);
  7582.     }
  7583.     //за секој производ се внесува колку такви производи се порачани во нарачката
  7584.     int j;
  7585.     for (j = 0; j < narachka.n; ++j) {
  7586.        //се внесува број на производи во нарачката
  7587.         scanf("%d", &narachka.kolichina[j]);
  7588.     }
  7589.  
  7590.  
  7591.     // повик на функцијата pecatiFaktura
  7592.     pecatiFaktura(narachka);
  7593.  
  7594.  
  7595.     return 0;
  7596. }
  7597. //39. Воз
  7598. #include<iostream>
  7599. #include<cstring>
  7600. #include<cmath>
  7601. using namespace std;
  7602.  
  7603. class Patnik {
  7604.  
  7605. private:
  7606.     char ime [100];
  7607.     int klasa;
  7608.     bool velosiped;
  7609. public:
  7610.     Patnik() {}
  7611.     Patnik (char *i, int k, bool v) {
  7612.         strcpy(ime, i);
  7613.         klasa=k;
  7614.         velosiped=v;
  7615.     }
  7616.     Patnik(Patnik &p) {
  7617.         strcpy(ime,p.ime);
  7618.         klasa=p.klasa;
  7619.         velosiped=p.velosiped;
  7620.     }
  7621.     Patnik& operator = (Patnik &p) {
  7622.         if(this!=&p) {
  7623.             strcpy(ime,p.ime);
  7624.             klasa=p.klasa;
  7625.             velosiped=p.velosiped;
  7626.         }
  7627.         return *this;
  7628.     }
  7629.     friend ostream& operator << (ostream& os, const Patnik &p) {
  7630.         os << p.ime << "\n" << p.klasa << "\n" <<p.velosiped<<endl;
  7631.         return os;
  7632.     }
  7633.     int getKlasa() {
  7634.         return klasa;
  7635.     }
  7636.     bool getVelosiped() {
  7637.         return velosiped;
  7638.     }
  7639.     ~Patnik() {}
  7640. };
  7641.  
  7642. class Voz {
  7643.  
  7644. private:
  7645.     char destinacija [100];
  7646.     Patnik *patnici;
  7647.     int elementi;
  7648.     int maxv;
  7649. public:
  7650.     Voz() {
  7651.         patnici=new Patnik[0];
  7652.     }
  7653.     Voz(char *d, int m) {
  7654.         strcpy(destinacija, d);
  7655.         maxv=m;
  7656.         patnici=new Patnik[0];
  7657.         elementi=0;
  7658.     }
  7659.     Voz(char *d, Patnik *p, int e, int m) {
  7660.         strcpy(destinacija, d);
  7661.         maxv=m;
  7662.         elementi=e;
  7663.         patnici=new Patnik[e];
  7664.         for(int i=0; i<e; i++) {
  7665.             patnici[i]=p[i];
  7666.         }
  7667.     }
  7668.     Voz& operator += (Patnik &p) {
  7669.         if((maxv==0&&p.getVelosiped()==false)||(maxv>0))
  7670.         {
  7671.             int i;
  7672.             Patnik *pom=new Patnik[elementi];
  7673.             for(i=0; i<elementi; i++)
  7674.                 pom[i]=patnici[i];
  7675.             delete [] patnici;
  7676.             patnici=new Patnik[elementi+1];
  7677.             for(i=0; i<elementi; i++)
  7678.                 patnici[i]=pom[i];
  7679.             patnici[i]=p;
  7680.             ++elementi;
  7681.             delete [] pom;
  7682.             return *this;
  7683.         }
  7684.         return *this;
  7685.     }
  7686.  
  7687.     friend ostream& operator << (ostream &os, const Voz &v) {
  7688.         os << v.destinacija<<"\n";
  7689.         for(int i=0; i<v.elementi; i++) {
  7690.             os<<v.patnici[i]<<endl;
  7691.         }
  7692.         return os;
  7693.     }
  7694.  
  7695.     void patniciNemaMesto() {
  7696.         int vkupnoPrva=0, vkupnoVtora=0;
  7697.         int Prva,Vtora;
  7698.         for(int i=0; i<elementi; i++)
  7699.         {
  7700.             if(patnici[i].getKlasa()==1&&patnici[i].getVelosiped()==true)
  7701.                 vkupnoPrva++;
  7702.             if(patnici[i].getKlasa()==2&&patnici[i].getVelosiped()==true)
  7703.                 vkupnoVtora++;
  7704.         }
  7705.         if(vkupnoPrva<=maxv)
  7706.         {
  7707.             Prva=0;
  7708.             maxv-=vkupnoPrva;
  7709.             if(vkupnoVtora<=maxv)
  7710.                 Vtora=0;
  7711.             else
  7712.                 Vtora=abs(maxv-vkupnoVtora);
  7713.         }
  7714.         else
  7715.         {
  7716.             Prva=abs(maxv-vkupnoPrva);
  7717.             Vtora=vkupnoVtora;
  7718.         }
  7719.        
  7720.         cout << "Brojot na patnici od 1-va klasa koi ostanale bez mesto e: "<<Prva<<endl;
  7721.         cout << "Brojot na patnici od 2-ra klasa koi ostanale bez mesto e: "<<Vtora<<endl;
  7722.     }
  7723.     ~Voz()
  7724.     {
  7725.         delete [] patnici;
  7726.     }
  7727. };
  7728.  
  7729.  
  7730. int main() {
  7731.     Patnik p;
  7732.     char ime[100], destinacija[100];
  7733.     int n;
  7734.     bool velosiped;
  7735.     int klasa;
  7736.     int maxv;
  7737.     cin >> destinacija >> maxv;
  7738.     cin >> n;
  7739.     Voz v(destinacija, maxv);
  7740.     //cout<<v<<endl;
  7741.     for (int i = 0; i < n; i++) {
  7742.         cin >> ime >> klasa >> velosiped;
  7743.         Patnik p(ime, klasa, velosiped);
  7744.         //cout<<p<<endl;
  7745.         v += p;
  7746.     }
  7747.     cout << v;
  7748.     v.patniciNemaMesto();
  7749.  
  7750.     return 0;
  7751. }
  7752.  
  7753. //40. Работни часови C
  7754. #include <stdio.h>
  7755. #include <string.h>
  7756. #define NEDELI 4
  7757. #define DENOVI 5
  7758.  
  7759. struct RabotnaNedela
  7760. {
  7761.     int casovi[DENOVI];
  7762.     int broj;
  7763. };
  7764. typedef struct RabotnaNedela RN;
  7765.  
  7766. struct Rabotnik
  7767. {
  7768.     char ime[50];
  7769.     RN nedeli[NEDELI];  
  7770. };
  7771.  
  7772. typedef struct Rabotnik R;
  7773.  
  7774. int maxNedela(R *r)
  7775. {
  7776.     int i, j;
  7777.     int maxrab=0, sum=0, maxbr=0;
  7778.     for(i=0; i<NEDELI; i++)
  7779.     {  
  7780.         sum=0;
  7781.         for(j=0; j<DENOVI; j++)
  7782.         {
  7783.             sum+=r->nedeli[i].casovi[j];
  7784.         }
  7785.         if(maxrab<sum)
  7786.         {
  7787.             maxrab=sum;
  7788.             maxbr=i;
  7789.         }
  7790.     }
  7791.     return maxbr+1;
  7792. }
  7793.  
  7794. void table(R *r, int n)
  7795. {
  7796.     int i, j, k;
  7797.     int vkNed, vkRab;
  7798.     printf("Rab\t1\t2\t3\t4\tVkupno\n");
  7799.     for(i=0; i<n; i++)
  7800.     {
  7801.         printf("%s\t", r[i].ime);
  7802.         vkRab=0;
  7803.         for(j=0; j<NEDELI; j++)
  7804.         {
  7805.             vkNed=0;
  7806.             for(k=0; k<DENOVI; k++)
  7807.             {
  7808.                 vkNed+=r[i].nedeli[j].casovi[k];
  7809.             }
  7810.             printf("%d\t",vkNed);
  7811.             vkRab+=vkNed;
  7812.         }
  7813.         printf("%d\n",vkRab);
  7814.     }
  7815. }
  7816.  
  7817. int main() {
  7818.     int n;
  7819.     scanf("%d", &n);
  7820.     R rabotnici[n];
  7821.     int i;
  7822.     for (i = 0; i < n; ++i) {
  7823.         scanf("%s", rabotnici[i].ime);
  7824.         int j;
  7825.         for (j = 0; j < NEDELI; ++j) {
  7826.             int k;
  7827.             for (k = 0; k < DENOVI; ++k) {
  7828.                 scanf("%d", &rabotnici[i].nedeli[j].casovi[k]);
  7829.             }
  7830.  
  7831.         }
  7832.     }
  7833.     printf("TABLE\n");
  7834.     table(rabotnici, n);
  7835.     printf("MAX NEDELA NA RABOTNIK: %s\n", rabotnici[n / 2].ime);
  7836.     printf("%d\n", maxNedela(&rabotnici[n / 2]));
  7837.     return 0;
  7838. }
  7839.  
  7840. //41. Танчери
  7841. #include<iostream>
  7842. #include<cstring>
  7843. using namespace std;
  7844.  
  7845. struct Tanc {
  7846.     char ime[15];
  7847.     char zemja[15];
  7848. };
  7849. struct Tancer {
  7850.     char ime[20];
  7851.     char prezime[20];
  7852.     Tanc niza[5];
  7853. };
  7854. void tancuvanje(Tancer *t, int n, char *zemja) {
  7855.     int i;
  7856.     int j;
  7857.     for(i=0; i<n; i++) {
  7858.         for(j=0; j<5; j++) {
  7859.             if(strcmp(t[i].niza[j].zemja,zemja)==0) {
  7860.                 cout<<t[i].ime<<" "<<t[i].prezime<<", "<<t[i].niza[j].ime<<endl;
  7861.                 break;
  7862.             }
  7863.         }
  7864.     }
  7865. }
  7866. int main() {
  7867.     int i, j, n;
  7868.     char zemja[15];
  7869.     Tancer tanceri[5];
  7870.     cin >> n;
  7871.     for(i = 0; i < n; i++) {
  7872.         cin >> tanceri[i].ime;
  7873.         cin >> tanceri[i].prezime;
  7874.         for(j = 0; j < 3; j++) {
  7875.             cin >> tanceri[i].niza[j].ime;
  7876.             cin >> tanceri[i].niza[j].zemja;
  7877.         }
  7878.     }
  7879.     cin >> zemja;
  7880.     tancuvanje(tanceri, n, zemja);
  7881.     return 0;
  7882. }
  7883. //42. Работни часови (40 поени) C
  7884. #include <stdio.h>
  7885. #include <string.h>
  7886. #define NEDELI 4
  7887. #define DENOVI 5
  7888.  
  7889. struct RabotnaNedela
  7890. {
  7891.     int casovi[DENOVI];
  7892.     int broj;
  7893. };
  7894. typedef struct RabotnaNedela RN;
  7895.  
  7896. struct Rabotnik
  7897. {
  7898.     char ime[50];
  7899.     RN nedeli[NEDELI];  
  7900. };
  7901.  
  7902. typedef struct Rabotnik R;
  7903.  
  7904. int maxNedela(R *r)
  7905. {
  7906.     int i, j;
  7907.     int maxrab=0, sum=0, maxbr=0;
  7908.     for(i=0; i<NEDELI; i++)
  7909.     {  
  7910.         sum=0;
  7911.         for(j=0; j<DENOVI; j++)
  7912.         {
  7913.             sum+=r->nedeli[i].casovi[j];
  7914.         }
  7915.         if(maxrab<sum)
  7916.         {
  7917.             maxrab=sum;
  7918.             maxbr=i;
  7919.         }
  7920.     }
  7921.     return maxbr+1;
  7922. }
  7923.  
  7924. void table(R *r, int n)
  7925. {
  7926.     int i, j, k;
  7927.     int vkNed, vkRab;
  7928.     printf("Rab\t1\t2\t3\t4\tVkupno\n");
  7929.     for(i=0; i<n; i++)
  7930.     {
  7931.         printf("%s\t", r[i].ime);
  7932.         vkRab=0;
  7933.         for(j=0; j<NEDELI; j++)
  7934.         {
  7935.             vkNed=0;
  7936.             for(k=0; k<DENOVI; k++)
  7937.             {
  7938.                 vkNed+=r[i].nedeli[j].casovi[k];
  7939.             }
  7940.             printf("%d\t",vkNed);
  7941.             vkRab+=vkNed;
  7942.         }
  7943.         printf("%d\n",vkRab);
  7944.     }
  7945. }
  7946.  
  7947. int main() {
  7948.     int n;
  7949.     scanf("%d", &n);
  7950.     R rabotnici[n];
  7951.     int i;
  7952.     for (i = 0; i < n; ++i) {
  7953.         scanf("%s", rabotnici[i].ime);
  7954.         int j;
  7955.         for (j = 0; j < NEDELI; ++j) {
  7956.             int k;
  7957.             for (k = 0; k < DENOVI; ++k) {
  7958.                 scanf("%d", &rabotnici[i].nedeli[j].casovi[k]);
  7959.             }
  7960.  
  7961.         }
  7962.     }
  7963.     printf("TABLE\n");
  7964.     table(rabotnici, n);
  7965.     printf("MAX NEDELA NA RABOTNIK: %s\n", rabotnici[n / 2].ime);
  7966.     printf("%d\n", maxNedela(&rabotnici[n / 2]));
  7967.     return 0;
  7968. }
  7969.  
  7970. //43. Структура во C C
  7971. #include<stdio.h>
  7972. #include<string.h>
  7973. struct Pacient
  7974. {
  7975.     char ime[100];
  7976.     int zdrastveno;
  7977.     int pregledi;
  7978. };
  7979.  
  7980. typedef struct MaticenDoktor
  7981. {
  7982.     char ime[100];
  7983.     int br_pac;
  7984.     struct Pacient niza[200];
  7985.     float cena;
  7986.    
  7987. } doktor;
  7988.  
  7989. void najuspesen_doktor (doktor *md, int n)
  7990. {
  7991.     float suma=0, maxsuma=0;
  7992.     char ID[100];
  7993.     int maxpac=0, i, j, preg;
  7994.     for(i=0; i<n; i++)
  7995.     {
  7996.         suma=0;
  7997.         preg=0;
  7998.         for(j=0; j<md[i].br_pac; j++)
  7999.         {
  8000.             if(md[i].niza[j].zdrastveno==0)
  8001.             {
  8002.                 suma+=md[i].cena*md[i].niza[j].pregledi;
  8003.             }
  8004.             preg+=md[i].niza[j].pregledi;
  8005.         }
  8006.         if(maxsuma<suma)
  8007.         {
  8008.             maxsuma=suma;
  8009.             strcpy(ID, md[i].ime);
  8010.             maxpac=preg;
  8011.         }
  8012.         else if(maxsuma==suma)
  8013.         {
  8014.             if(maxpac<preg)
  8015.             {
  8016.                 maxpac=preg;
  8017.                 maxsuma=suma;
  8018.                 strcpy(ID, md[i].ime);
  8019.             }
  8020.         }
  8021.     }
  8022.     printf("%s %.2f %d", ID, maxsuma , maxpac);
  8023. }
  8024.  
  8025. int main()
  8026. {
  8027.     int i, j, n, broj;
  8028.     doktor md[200];
  8029.     scanf("%d", &n);
  8030.     for (i = 0; i < n; i++){
  8031.         //ime na doktor
  8032.         scanf("%s", md[i].ime);
  8033.         //broj na pacienti
  8034.         scanf("%d", &md[i].br_pac);
  8035.         //cena na pregled
  8036.         scanf("%f", &md[i].cena);
  8037.  
  8038.         for (j = 0; j < md[i].br_pac; j++){
  8039.             scanf("%s", md[i].niza[j].ime);
  8040.             scanf("%d", &md[i].niza[j].zdrastveno);
  8041.             scanf("%d", &md[i].niza[j].pregledi);
  8042.         }
  8043.     }
  8044.     najuspesen_doktor(md, n);
  8045.  
  8046.     return 0;
  8047. }
  8048.  
  8049. //44. Акции
  8050. #include<iostream>
  8051. #include<cstring>
  8052. using namespace std;
  8053.  
  8054. class StockRecord {
  8055.     char ID[12];
  8056.     char ime[50];
  8057.     double cenaKupovna;
  8058.     double cenaMomentalna;
  8059.     int brojKupeni;
  8060. public:
  8061.     StockRecord() {}
  8062.     StockRecord(const char *id, const char *i, double cK, int br) {
  8063.         strcpy(ID,id);
  8064.         strcpy(ime,i);
  8065.         cenaKupovna=cK;
  8066.         brojKupeni=br;
  8067.         cenaMomentalna=0;
  8068.     }
  8069.     StockRecord(StockRecord &s) {
  8070.         strcpy(ID,s.ID);
  8071.         strcpy(ime,s.ime);
  8072.         cenaKupovna=s.cenaKupovna;
  8073.         brojKupeni=s.brojKupeni;
  8074.         cenaMomentalna=s.cenaMomentalna;
  8075.     }
  8076.     StockRecord& operator = (StockRecord &s) {
  8077.         strcpy(ID,s.ID);
  8078.         strcpy(ime,s.ime);
  8079.         cenaKupovna=s.cenaKupovna;
  8080.         brojKupeni=s.brojKupeni;
  8081.         cenaMomentalna=s.cenaMomentalna;
  8082.         return *this;
  8083.     }
  8084.     double value() {
  8085.         return brojKupeni * cenaMomentalna;
  8086.     }
  8087.     double profit() {
  8088.         return brojKupeni * (cenaMomentalna-cenaKupovna);
  8089.     }
  8090.  
  8091.     friend ostream& operator << (ostream &os, StockRecord &s) {
  8092.         os<<s.ime<<" "<<s.brojKupeni<<" "<<s.cenaKupovna;
  8093.         os<<" "<<s.cenaMomentalna<<" "<<s.profit()<<endl;
  8094.         return os;
  8095.     }
  8096.  
  8097.     void setNewPrice(double c) {
  8098.         cenaMomentalna=c;
  8099.     }
  8100.  
  8101. };
  8102.  
  8103. class Client {
  8104.     char ime[60];
  8105.     int ID;
  8106.     StockRecord *kompanii;
  8107.     int elementi;
  8108. public:
  8109.     Client(char *i, int id) {
  8110.         strcpy(ime,i);
  8111.         ID=id;
  8112.         kompanii=new StockRecord[0];
  8113.         elementi=0;
  8114.     }
  8115.     Client(Client &c) {
  8116.         strcpy(ime,c.ime);
  8117.         ID=c.ID;
  8118.         kompanii=new StockRecord[c.elementi];
  8119.         for(int i=0; i<c.elementi; i++) {
  8120.             kompanii[i]=c.kompanii[i];
  8121.         }
  8122.         elementi=c.elementi;
  8123.     }
  8124.     double totalValue() {
  8125.         int total=0;
  8126.         for(int i=0; i<elementi; i++) {
  8127.             total+=kompanii[i].value();
  8128.         }
  8129.         return total;
  8130.     }
  8131.     Client& operator = (Client &c) {
  8132.         delete [] kompanii;
  8133.         strcpy(ime,c.ime);
  8134.         ID=c.ID;
  8135.         kompanii=new StockRecord[c.elementi];
  8136.         for(int i=0; i<c.elementi; i++) {
  8137.             kompanii[i]=c.kompanii[i];
  8138.         }
  8139.         elementi=c.elementi;
  8140.         return *this;
  8141.     }
  8142.     Client& operator += (StockRecord &s) {
  8143.         StockRecord *temp=new StockRecord[elementi];
  8144.         for(int i=0; i<elementi; i++) {
  8145.             temp[i]=kompanii[i];
  8146.         }
  8147.         delete [] kompanii;
  8148.         kompanii=new StockRecord[elementi+1];
  8149.         for(int i=0; i<elementi; i++) {
  8150.             kompanii[i]=temp[i];
  8151.         }
  8152.         kompanii[elementi]=s;
  8153.         elementi++;
  8154.         delete [] temp;
  8155.         return *this;
  8156.     }
  8157.     friend ostream& operator << (ostream &os, Client &c) {
  8158.         os<<c.ID<<" "<<c.totalValue()<<endl;
  8159.         for(int i=0; i<c.elementi; i++) {
  8160.             os<<c.kompanii[i];
  8161.         }
  8162.         return os;
  8163.     }
  8164.     ~Client() {
  8165.         delete [] kompanii;
  8166.     }
  8167. };
  8168.  
  8169. // ne menuvaj vo main-ot
  8170.  
  8171. int main() {
  8172.  
  8173.     int test;
  8174.     cin >> test;
  8175.  
  8176.     if(test == 1) {
  8177.         double price;
  8178.         cout << "=====TEST NA KLASATA StockRecord=====" << endl;
  8179.         StockRecord sr("1", "Microsoft", 60.0, 100);
  8180.         cout << "Konstruktor OK" << endl;
  8181.         cin >> price;
  8182.         sr.setNewPrice(price);
  8183.         cout << "SET metoda OK" << endl;
  8184.     } else if(test == 2) {
  8185.         cout << "=====TEST NA METODITE I OPERATOR << OD KLASATA StockRecord=====" << endl;
  8186.         char id[12], company[50];
  8187.         double price, newPrice;
  8188.         int n, shares;
  8189.         cin >> n;
  8190.         for(int i = 0; i < n; ++i) {
  8191.             cin >> id;
  8192.             cin >> company;
  8193.             cin >> price;
  8194.             cin >> newPrice;
  8195.             cin >> shares;
  8196.             StockRecord sr(id, company, price, shares);
  8197.             sr.setNewPrice(newPrice);
  8198.             cout << sr.value() << endl;
  8199.             cout << sr;
  8200.         }
  8201.     } else if(test == 3) {
  8202.         cout << "=====TEST NA KLASATA Client=====" << endl;
  8203.         char companyID[12], companyName[50], clientName[50];
  8204.         int clientID, n, shares;
  8205.         double oldPrice, newPrice;
  8206.         bool flag = true;
  8207.         cin >> clientName;
  8208.         cin >> clientID;
  8209.         cin >> n;
  8210.         Client c(clientName, clientID);
  8211.         cout << "Konstruktor OK" << endl;
  8212.         for(int i = 0; i < n; ++i) {
  8213.             cin >> companyID;
  8214.             cin >> companyName;
  8215.             cin >> oldPrice;
  8216.             cin >> newPrice;
  8217.             cin >> shares;
  8218.             StockRecord sr(companyID, companyName, oldPrice, shares);
  8219.             sr.setNewPrice(newPrice);
  8220.             c += sr;
  8221.             if(flag) {
  8222.                 cout << "Operator += OK" << endl;
  8223.                 flag = false;
  8224.             }
  8225.         }
  8226.         cout << c;
  8227.         cout << "Operator << OK" << endl;
  8228.     }
  8229.     return 0;
  8230.  
  8231. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement