Advertisement
MikiStrail

ООП Задачи од Exercises

Apr 11th, 2019
156
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 57.33 KB | None | 0 0
  1. 1. Компјутерска игра
  2. #include <iostream>
  3. using namespace std;
  4. struct Igrac{
  5.     char korisnickoime[15];
  6.     int nivo;
  7.     int poeni;
  8. };
  9. struct KompjuterskaIgra{
  10.     char ime[20];
  11.     Igrac lista[30];
  12.     int n;
  13. };
  14. void najdobarIgrac(KompjuterskaIgra *lista, int n){
  15.     int IndexNajmnoguIgraci=0, IndexMax=0, IndexNivo=0;
  16.     for(int i=1;i<n;i++){
  17.     if(lista[i].n>lista[IndexNajmnoguIgraci].n){
  18.         IndexNajmnoguIgraci=i;
  19.     }
  20.     }
  21.     KompjuterskaIgra najpopularna=lista[IndexNajmnoguIgraci];
  22.     for(int i=1;i<najpopularna.n;i++){
  23.         if(najpopularna.lista[i].poeni>najpopularna.lista[IndexMax].poeni){
  24.             IndexMax=i;
  25.         }
  26.         else if(najpopularna.lista[i].poeni==najpopularna.lista[IndexMax].poeni){
  27.             if(najpopularna.lista[i].nivo>najpopularna.lista[IndexMax].poeni){
  28.                 IndexMax=i;
  29.             }
  30.         }
  31.     }
  32.     cout<<"Najdobar igrac e igracot so korisnicko ime ";
  33.     cout<<najpopularna.lista[IndexMax].korisnickoime;
  34.     cout<<" koj ja igra igrata ";
  35.     cout<<najpopularna.ime;
  36. }
  37. int main(){
  38.     int n,m;
  39.     char ime[20];
  40.     cin>>n;
  41.     KompjuterskaIgra poleigri[100];
  42.     for (int i=0; i<n; i++) {
  43.         KompjuterskaIgra nova;
  44.         cin>>nova.ime>>nova.n;
  45.         Igrac pole[30];
  46.         for (int j=0; j<nova.n; j++) {
  47.             Igrac nov;
  48.             cin>>nov.korisnickoime>>nov.nivo>>nov.poeni;
  49.             nova.lista[j]=nov;
  50.         }
  51.         poleigri[i]=nova;
  52.     }
  53.     najdobarIgrac(poleigri,n);
  54.     return 0;
  55. }
  56.  
  57. 2. Скијачки центар
  58. #include<stdio.h>
  59. #include<string.h>
  60. typedef struct SkiLift{
  61.     char ime[15];
  62.     int max;
  63.     int voUpotreba;
  64. }SkiLift;
  65. typedef struct SkiCenter{
  66.     char ime[20];
  67.     char drzava[20];
  68.     SkiLift lift[20];
  69.     int n;
  70. }SkiCenter;
  71. void najgolemKapacitet(SkiCenter *sc, int n){
  72.     int vkupno=0,max=0,IndexI;
  73.     for(int i=0;i<n;i++){
  74.         for(int j=0;j<sc[i].n;j++){
  75.             if(sc[i].lift[j].voUpotreba==1){
  76.             vkupno+=sc[i].lift[j].max;
  77.                 if(vkupno>=max){
  78.                     max=vkupno;
  79.                     IndexI=i;
  80.                 }
  81.             }
  82.         }
  83.         vkupno=0;
  84.     }
  85.     printf("%s\n%s\n%d",sc[IndexI].ime,sc[IndexI].drzava,max);
  86. }
  87. int main()
  88. {
  89.     int n,i,j,broj;
  90.     SkiCenter sc[20];
  91.     scanf("%d", &n);    
  92.     for (i = 0; i < n; i++){
  93.         //vnesi ime
  94.         scanf("%s",sc[i].ime);
  95.         //vnesi drzava
  96.         scanf("%s",sc[i].drzava);
  97.         //vnesi broj na liftovi
  98.         scanf("%d",&sc[i].n);
  99.         //za sekoj ski lift vnesi:
  100.         for(j=0;j<sc[i].n;j++){
  101.             //vnesi ime
  102.             scanf("%s",sc[i].lift[j].ime);
  103.             //vnesi maksimalen broj korisnici
  104.             scanf("%d",&sc[i].lift[j].max);
  105.             //vnesi dali e pusten vo funkcija
  106.             scanf("%d",&sc[i].lift[j].voUpotreba);
  107.         }
  108.     }  
  109.     //povik na funkcijata najgolemKapacitet
  110.     najgolemKapacitet(sc,n);
  111.     return 0;
  112. }
  113. 3. CD
  114. #include <iostream>
  115. #include <cstring>
  116. using namespace std;
  117.  
  118. enum tip { pop, rap, rok };
  119. class Pesna{
  120.     private:
  121.     char *ime;
  122.     int vremetraenje;
  123.     tip kojtip;
  124.     public:
  125.     Pesna() {ime = new char[0];}
  126.     Pesna(char* ime, int vremetraenje, tip kojtip){
  127.         this->ime = new char[strlen(ime)+1];
  128.         strcpy(this->ime,ime);
  129.         this->vremetraenje=vremetraenje;
  130.         this->kojtip=kojtip;
  131.     }
  132.     Pesna(const Pesna &p){
  133.         this->ime = new char[strlen(p.ime)+1];
  134.         strcpy(this->ime,p.ime);
  135.         this->vremetraenje=p.vremetraenje;
  136.         this->kojtip=p.kojtip;
  137.     }
  138.     Pesna &operator=(const Pesna &p){
  139.         if(this!=&p){
  140.             delete [] ime;
  141.             this->ime = new char[strlen(p.ime)+1];
  142.             strcpy(this->ime,p.ime);
  143.             this->vremetraenje=p.vremetraenje;
  144.             this->kojtip=p.kojtip;
  145.         }
  146.         return *this;
  147.     }
  148.     ~Pesna(){
  149.         delete [] ime;
  150.     }
  151.     void pecati(){
  152.         cout<<"\""<<ime<<"\"-"<<vremetraenje<<"min"<<endl;
  153.     }
  154.     void setIme(char *ime){
  155.         strcpy(this->ime,ime);
  156.     }
  157.     void setVremetraenje(int vremetraenje){
  158.         this->vremetraenje=vremetraenje;
  159.     }
  160.     void setTip(tip kojtip){
  161.         this->kojtip=kojtip;
  162.     }
  163.     char *getIme(){
  164.         return ime;
  165.     }
  166.     int getVremetraenje(){
  167.         return vremetraenje;
  168.     }
  169.     tip getTip(){
  170.         return kojtip;
  171.     }
  172. };
  173. class CD{
  174. private:
  175.     Pesna pesni[10];
  176.     int n;
  177.     int maxVremetraenje;
  178.     public:
  179.     CD(Pesna *pesni=0, int n=0, int maxVremetraenje=0){
  180.         for(int i=0;i<n;i++)
  181.         this->pesni[i] = pesni[i];
  182.         this->n=n;
  183.         this->maxVremetraenje=maxVremetraenje;
  184.     }
  185.     CD(int maxVremetraenje){
  186.         this->n=0;
  187.         this->maxVremetraenje=maxVremetraenje;
  188.     }
  189.     CD(const CD &c){
  190.         this->n=c.n;
  191.         for(int i=0;i<n;i++)
  192.         this->pesni[i] = c.pesni[i];
  193.         this->maxVremetraenje=c.maxVremetraenje;
  194.     }
  195.     CD &operator=(const CD &c){
  196.         if(this!=&c){
  197.         this->n=c.n;
  198.         for(int i=0;i<n;i++)
  199.         this->pesni[i] = c.pesni[i];
  200.         this->maxVremetraenje=c.maxVremetraenje;
  201.         }
  202.         return *this;
  203.     }
  204.     ~CD(){}
  205.     Pesna getPesna(int i){
  206.         return pesni[i];
  207.     }
  208.     int getBroj(){
  209.         return n;
  210.     }
  211.     CD& dodadiPesna(Pesna p){
  212.         int vkupnovreme=0;
  213.         for(int i=0;i<n;i++){
  214.             vkupnovreme+=pesni[i].getVremetraenje();
  215.         }
  216.         if(n<10&&maxVremetraenje>=(vkupnovreme+p.getVremetraenje())){
  217.             pesni[n++]=p;
  218.         }
  219.         return *this;
  220.     }
  221.     void pecatiPesniPoTip(tip t){
  222.         for(int i=0;i<n;i++){
  223.             if(pesni[i].getTip()==t){
  224.                 pesni[i].pecati();
  225.             }
  226.         }      
  227.     }
  228. };
  229.  
  230. int main() {
  231.     // se testira zadacata modularno
  232.     int testCase;
  233.     cin >> testCase;
  234.    
  235.     int n, minuti, kojtip;
  236.     char ime[50];
  237.    
  238.     if(testCase == 1) {
  239.         cout << "===== Testiranje na klasata Pesna ======" << endl;
  240.         cin >> ime;
  241.         cin >> minuti;
  242.         cin >> kojtip; //se vnesuva 0 za POP,1 za RAP i 2 za ROK
  243.         Pesna p(ime,minuti,(tip)kojtip);
  244.         p.pecati();
  245.     } else if(testCase == 2) {
  246.         cout << "===== Testiranje na klasata CD ======" << endl;
  247.         CD omileno(20);
  248.         cin>>n;
  249.             for (int i=0;i<n;i++){
  250.                 cin >> ime;
  251.                 cin >> minuti;
  252.                 cin >> kojtip; //se vnesuva 0 za POP,1 za RAP i 2 za ROK
  253.                 Pesna p(ime,minuti,(tip)kojtip);
  254.                 omileno.dodadiPesna(p);
  255.             }
  256.             for (int i=0; i<n; i++)
  257.                 (omileno.getPesna(i)).pecati();
  258.     }
  259.     else if(testCase == 3) {
  260.         cout << "===== Testiranje na metodot dodadiPesna() od klasata CD ======" << endl;
  261.         CD omileno(20);
  262.         cin>>n;
  263.             for (int i=0;i<n;i++){
  264.                 cin >> ime;
  265.                 cin >> minuti;
  266.                 cin >> kojtip; //se vnesuva 0 za POP,1 za RAP i 2 za ROK
  267.                 Pesna p(ime,minuti,(tip)kojtip);
  268.                 omileno.dodadiPesna(p);
  269.             }
  270.             for (int i=0; i<omileno.getBroj(); i++)
  271.                 (omileno.getPesna(i)).pecati();
  272.     }
  273.     else if(testCase == 4) {
  274.         cout << "===== Testiranje na metodot pecatiPesniPoTip() od klasata CD ======" << endl;
  275.         CD omileno(20);
  276.         cin>>n;
  277.             for (int i=0;i<n;i++){
  278.                 cin >> ime;
  279.                 cin >> minuti;
  280.                 cin >> kojtip; //se vnesuva 0 za POP,1 za RAP i 2 za ROK
  281.                 Pesna p(ime,minuti,(tip)kojtip);
  282.                 omileno.dodadiPesna(p);
  283.             }
  284.         cin>>kojtip;
  285.         omileno.pecatiPesniPoTip((tip)kojtip);
  286.            
  287.     }
  288.     else if(testCase == 5) {
  289.         cout << "===== Testiranje na metodot pecatiPesniPoTip() od klasata CD ======" << endl;
  290.         CD omileno(20);
  291.         cin>>n;
  292.             for (int i=0;i<n;i++){
  293.                 cin >> ime;
  294.                 cin >> minuti;
  295.                 cin >> kojtip; //se vnesuva 0 za POP,1 za RAP i 2 za ROK
  296.                 Pesna p(ime,minuti,(tip)kojtip);
  297.                 omileno.dodadiPesna(p);
  298.             }
  299.         cin>>kojtip;
  300.         omileno.pecatiPesniPoTip((tip)kojtip);
  301.            
  302.     }
  303. return 0;
  304. }
  305. 4. Железничка станица
  306. #include<iostream>
  307. #include <cstring>
  308. using namespace std;
  309. struct Voz{
  310.     char relacija[50];
  311.     float km;
  312.     int patnici;
  313. };
  314. struct ZeleznickaStanica{
  315.     char grad[20];
  316.     Voz voz[30];
  317.     int n;
  318. };
  319. int isSubString(char *l, char *r)
  320. {
  321.     int lenL=strlen(l), lenR=strlen(r), count=0;
  322.     for(int i=0; i<lenR; i++)
  323.     {
  324.         if(l[i]==r[i])
  325.         {
  326.             count++;
  327.         }
  328.         else
  329.         {
  330.             break;
  331.         }
  332.     }
  333.     return count==lenR;
  334. }
  335. void najkratkaRelacija(ZeleznickaStanica* z, int n, char* grad){
  336.     int IndexI, IndexJ, min=99999;
  337.     for(int i=0;i<n;i++){
  338.         for(int j=0;j<z[i].n;j++){
  339.             if(isSubString(z[i].voz[j].relacija, grad)){
  340.             if(z[i].voz[j].km<=min){
  341.                 min=z[i].voz[j].km;
  342.                 IndexI=i;
  343.                 IndexJ=j;
  344.             }
  345.     }
  346.     }
  347.     }
  348.     cout<<"Najkratka relacija: "<<z[IndexI].voz[IndexJ].relacija<<" ("<<min<<" km)";
  349. }
  350. int main(){
  351.    
  352.     int n;
  353.     cin>>n; //se cita brojot na zelezlnichki stanici
  354.     ZeleznickaStanica zStanica[100];
  355.     for (int i=0;i<n;i++){
  356.         //se citaat infomracii za n zelezlnichkite stanici i se zacuvuvaat vo poleto zStanica
  357.         cin>>zStanica[i].grad;
  358.         cin>>zStanica[i].n;
  359.         for(int j=0;j<zStanica[i].n;j++){
  360.             cin>>zStanica[i].voz[j].relacija;
  361.             cin>>zStanica[i].voz[j].km;
  362.             cin>>zStanica[i].voz[j].patnici;
  363.         }
  364.     }
  365.     char grad[25];
  366.     cin>>grad;
  367.     najkratkaRelacija(zStanica,n,grad);
  368.     return 0;
  369. }
  370.  
  371. 5. Пицерија
  372. #include <iostream>
  373. #include <cstring>
  374.  
  375. using namespace std;
  376. class Pica {
  377. private:
  378.     char ime[15];
  379.     int cena;
  380.     char *sostojki;
  381.     int namaluvanje;
  382. public:
  383.     Pica(const char *ime = "", int cena = 0, const char *sostojki = "", int namaluvanje = 0) {
  384.         strcpy(this->ime,ime);
  385.         this->cena=cena;
  386.         this->sostojki = new char[strlen(sostojki)+1];
  387.         strcpy(this->sostojki,sostojki);
  388.         this->namaluvanje=namaluvanje;
  389.     }
  390.     Pica(const Pica &p) {
  391.         strcpy(ime,p.ime);
  392.         cena=p.cena;
  393.         sostojki = new char[strlen(p.sostojki)+1];
  394.         strcpy(sostojki,p.sostojki);
  395.         namaluvanje=p.namaluvanje;
  396.     }
  397.     ~Pica() {
  398.         delete [] sostojki;
  399.     }
  400.     Pica &operator=(Pica &p) {
  401.         if(this!=&p) {
  402.             strcpy(ime,p.ime);
  403.             cena=p.cena;
  404.             delete [] sostojki;
  405.             sostojki = new char[strlen(p.sostojki)+1];
  406.             strcpy(sostojki,p.sostojki);
  407.             namaluvanje=p.namaluvanje;
  408.         }
  409.         return *this;
  410.     }
  411.     void pecati() {
  412.         cout<<ime<<" - "<<sostojki<<", "<<cena<<" ";
  413.     }
  414.     bool istiSe(Pica p) {
  415.         if(strcmp(sostojki, p.sostojki)==0) {
  416.             return true;
  417.         } else
  418.             return false;
  419.     }
  420.     int getNamaluvanje() {
  421.         return namaluvanje;
  422.     }
  423.     int getCena() {
  424.         return cena;
  425.     }
  426.  
  427. };
  428. class Picerija {
  429. private:
  430.     char ime[15];
  431.     Pica* pici;
  432.     int n;
  433. public:
  434.     Picerija(const char *ime = "") {
  435.         strncpy(this->ime,ime,14);
  436.         this->ime[14]=0;
  437.         pici=NULL;
  438.         n = 0;
  439.     }
  440.     Picerija(const char *ime,Pica* pici, int n) {
  441.         strncpy(this->ime,ime,14);
  442.         this->ime[14]=0;
  443.         this->n=n;
  444.         this->pici = new Pica[n];
  445.         for(int i=0; i<n; i++)
  446.             this->pici[i]=pici[i];
  447.     }
  448.     Picerija(const Picerija &p) {
  449.         strcpy(ime,p.ime);
  450.         n=p.n;
  451.         pici = new Pica[n];
  452.         for(int i=0; i<n; i++)
  453.             pici[i]=p.pici[i];
  454.     }
  455.     Picerija& operator= (const Picerija &p) {
  456.         if(this!=&p) {
  457.             strcpy(ime,p.ime);
  458.             n=p.n;
  459.             delete [] pici;
  460.             pici = new Pica[n];
  461.             for(int i=0; i<n; i++)
  462.                 pici[i]=p.pici[i];
  463.         }
  464.         return *this;
  465.     }
  466.     ~Picerija() {
  467.         delete [] pici;
  468.     }
  469.     Picerija& operator+=(Pica &p) {
  470.         int isti=0;
  471.         for(int i=0; i<n; i++) {
  472.             if(pici[i].istiSe(p)==true) {
  473.                 isti=1;
  474.             }
  475.         }
  476.         if(!isti) {
  477.             Pica *tmp = new Pica[n+1];
  478.             for(int i=0; i<n; i++)
  479.                 tmp[i]=pici[i];
  480.             tmp[n++]=p;
  481.             delete [] pici;
  482.             pici = tmp;
  483.         }
  484.         return *this;
  485.     }
  486.     void piciNaPromocija() {
  487.         for(int i=0; i<n; i++) {
  488.             if(pici[i].getNamaluvanje()!=0) {
  489.                 pici[i].pecati();
  490.                 cout<<(float)pici[i].getCena()-(((float)pici[i].getCena()/100)*pici[i].getNamaluvanje())<<endl;
  491.             }
  492.         }
  493.     }
  494.     void setIme(const char *ime) {
  495.         strncpy(this->ime,ime,14);
  496.         this->ime[14] = 0;
  497.     }
  498.     const char *getIme() {
  499.         return ime;
  500.     }
  501. };
  502. int main() {
  503.  
  504.     int n;
  505.     char ime[15];
  506.     cin >> ime;
  507.     cin >> n;
  508.  
  509.     Picerija p1(ime);
  510.     for (int i = 0; i < n; i++) {
  511.         char imp[100];
  512.         cin.get();
  513.         cin.getline(imp, 100);
  514.         int cena;
  515.         cin >> cena;
  516.         char sostojki[100];
  517.         cin.get();
  518.         cin.getline(sostojki, 100);
  519.         int popust;
  520.         cin >> popust;
  521.         Pica p(imp, cena, sostojki, popust);
  522.         p1+=p;
  523.     }
  524.  
  525.     Picerija p2 = p1;
  526.     cin >> ime;
  527.     p2.setIme(ime);
  528.     char imp[100];
  529.     cin.get();
  530.     cin.getline(imp, 100);
  531.     int cena;
  532.     cin >> cena;
  533.     char sostojki[100];
  534.     cin.get();
  535.     cin.getline(sostojki, 100);
  536.     int popust;
  537.     cin >> popust;
  538.     Pica p(imp, cena, sostojki, popust);
  539.     p2+=p;
  540.  
  541.     cout << p1.getIme() << endl;
  542.     cout << "Pici na promocija:" << endl;
  543.     p1.piciNaPromocija();
  544.  
  545.     cout << p2.getIme() << endl;
  546.     cout << "Pici na promocija:" << endl;
  547.     p2.piciNaPromocija();
  548.  
  549.     return 0;
  550. }
  551.  
  552. 6. Маратон
  553. // vashiot kod ovde
  554. #include <iostream>
  555. #include <cstring>
  556. using namespace std;
  557.  
  558. class Ucesnik{
  559. private:
  560.     char *ime;
  561.     bool pol;
  562.     int vozrast;
  563.     public:
  564.     Ucesnik(const char *ime="", bool pol=0, int vozrast=0){
  565.         this->ime=new char[strlen(ime)+1];
  566.         strcpy(this->ime,ime);
  567.         this->pol=pol;
  568.         this->vozrast=vozrast;
  569.     }
  570.     Ucesnik(const Ucesnik &p){
  571.         this->ime=new char[strlen(p.ime)+1];
  572.         strcpy(this->ime,p.ime);
  573.         this->pol=p.pol;
  574.         this->vozrast=p.vozrast;
  575.     }
  576.     Ucesnik &operator=(Ucesnik &p){
  577.         if(this!=&p){
  578.         delete [] ime;
  579.         this->ime=new char[strlen(p.ime)+1];
  580.         strcpy(this->ime,p.ime);
  581.         this->pol=p.pol;
  582.         this->vozrast=p.vozrast;
  583.         }
  584.         return *this;        
  585.     }
  586.     ~Ucesnik(){
  587.         delete [] ime;
  588.     }
  589.     bool operator>(Ucesnik &p){
  590.         return this->vozrast>p.vozrast;
  591.     }
  592.     friend ostream &operator<<(ostream &out, Ucesnik &p){
  593.         out<<p.ime<<endl;
  594.         if(p.pol==0)
  595.             out<<"zhenski"<<endl;
  596.         else
  597.             out<<"mashki"<<endl;
  598.         out<<p.vozrast<<endl;
  599.         return out;        
  600.     }
  601.     int getVozrast(){
  602.         return vozrast;
  603.     }
  604. };
  605. class Maraton{
  606. private:
  607.     char lokacija[100];
  608.     Ucesnik *ucesnici;
  609.     int n;
  610.     public:
  611.     Maraton(char *lokacija){
  612.         strncpy(this->lokacija,lokacija,strlen(lokacija)+1);
  613.         ucesnici=new Ucesnik[0];
  614.         n=0;
  615.     }
  616.     ~Maraton(){
  617.         delete [] ucesnici;
  618.     }
  619.     Maraton &operator+=(Ucesnik &p){
  620.             Ucesnik *tmp = new Ucesnik[n+1];
  621.             for(int i=0; i<this->n; i++)
  622.                 tmp[i]=this->ucesnici[i];
  623.             delete [] ucesnici;
  624.             ucesnici=new Ucesnik[n+1];
  625.             for(int i=0; i<this->n; i++)
  626.                 this->ucesnici[i]=tmp[i];
  627.             this->ucesnici[n]=p;
  628.             delete [] tmp;
  629.             n++;
  630.         return *this;
  631.     }
  632.     float prosecnoVozrast(){
  633.         float vkupno=0.0;
  634.         for(int i=0;i<n;i++){
  635.             vkupno+=ucesnici[i].getVozrast();
  636.         }
  637.         return vkupno/n;
  638.     }
  639.     void pecatiPomladi(Ucesnik &u){
  640.         for(int i=0;i<n;i++){
  641.             if(u.getVozrast()>this->ucesnici[i].getVozrast()){
  642.                 cout<<this->ucesnici[i];
  643.             }
  644.         }
  645.     }
  646. };
  647. int main() {
  648.     char ime[100];
  649.     bool maski;
  650.     int vozrast, n;
  651.     cin >> n;
  652.     char lokacija[100];
  653.     cin >> lokacija;
  654.     Maraton m(lokacija);
  655.     Ucesnik **u = new Ucesnik*[n];
  656.     for(int i = 0; i < n; ++i) {
  657.         cin >> ime >> maski >> vozrast;
  658.         u[i] = new Ucesnik(ime, maski, vozrast);
  659.         m += *u[i];
  660.     }
  661.     m.pecatiPomladi(*u[n - 1]);
  662.     cout << m.prosecnoVozrast() << endl;
  663.     for(int i = 0; i < n; ++i) {
  664.         delete u[i];
  665.     }
  666.     delete [] u;
  667.     return 0;
  668. }
  669.  
  670. 7. Сладолед
  671. #include <iostream>
  672. #include <cstring>
  673. using namespace std;
  674. // vashiot kod ovde
  675. class IceCream{
  676. private:
  677.     char *ime;
  678.     char sostav[100];
  679.     float cena;
  680.     int popust;
  681.     public:
  682.     IceCream(){
  683.         ime = new char[15];
  684.         popust=0;
  685.     }
  686.     IceCream(const char *ime,const char *sostav,float cena){
  687.         this->ime=new char[strlen(ime)+1];
  688.         strcpy(this->ime,ime);
  689.         strcpy(this->sostav,sostav);
  690.         this->cena=cena;
  691.         popust=0;
  692.     }
  693.     IceCream(const IceCream &ic){
  694.         this->ime=new char[strlen(ic.ime)+1];
  695.         strcpy(this->ime,ic.ime);
  696.         strcpy(this->sostav,ic.sostav);
  697.         this->cena=ic.cena;
  698.         popust=ic.popust;
  699.     }
  700.     IceCream &operator=(const IceCream &ic){
  701.         if(this!=&ic){
  702.         this->ime=new char[strlen(ic.ime)+1];
  703.         strcpy(this->ime,ic.ime);
  704.         strcpy(this->sostav,ic.sostav);
  705.         this->cena=ic.cena;
  706.         popust=ic.popust;
  707.         }
  708.         return *this;
  709.     }
  710.     ~IceCream(){
  711.         delete [] ime;
  712.     }
  713.     friend ostream &operator<<(ostream &out, const IceCream &ic){
  714.         out<<ic.ime<<": ";
  715.         out<<ic.sostav<<" ";
  716.         out<<ic.cena<<" ";
  717.         if(ic.popust>0)
  718.         out<<"("<<ic.cena-((ic.cena/100)*ic.popust)<<")";
  719.         return out;    
  720.     }
  721.     IceCream &operator++(){
  722.         popust+=5;
  723.         return *this;
  724.     }
  725.     IceCream &operator+(char *niza){
  726.         char *temp;
  727.         temp = new char[strlen(ime)+1];
  728.         strcpy(temp,ime);
  729.         delete [] ime;
  730.         ime = new char[strlen(temp)+strlen(niza)+4];
  731.         strcpy(ime,temp);
  732.         strcat(ime," + ");
  733.         strcat(ime,niza);
  734.         cena+=10;
  735.         delete [] temp;
  736.         return *this;
  737.     }    
  738.     void setDiscount(int dis){
  739.         if(dis>=0&&dis<=100)
  740.         popust=dis;
  741.     }
  742.     void setName(char* name){
  743.         ime=new char[strlen(name)+1];
  744.         strcpy(ime,name);
  745.     }
  746. };
  747. class IceCreamShop{
  748. private:
  749.     char ime[50];
  750.     IceCream *shop;
  751.     int n;
  752.     public:
  753.     IceCreamShop(){
  754.         n=0;
  755.         shop = new IceCream[n];
  756.     }
  757.     IceCreamShop(const char *ime){
  758.         n=0;
  759.         strcpy(this->ime,ime);
  760.         shop = new IceCream[n];        
  761.     }
  762.     IceCreamShop(const IceCreamShop &ics){
  763.         strcpy(this->ime,ics.ime);
  764.         this->shop = new IceCream[ics.n];
  765.         for(int i=0;i<ics.n;i++){
  766.             this->shop[i]=ics.shop[i];
  767.         }
  768.         this->n=ics.n;        
  769.     }
  770.     ~IceCreamShop(){
  771.         delete [] shop;    
  772.     }
  773.     IceCreamShop &operator+=(const IceCream &ic){
  774.         IceCream *temp;
  775.         temp = new IceCream[n];
  776.         for(int i=0;i<n;i++){
  777.             temp[i]=shop[i];
  778.         }
  779.         delete [] shop;
  780.         shop = new IceCream[n+1];
  781.         for(int i=0;i<n;i++){
  782.             shop[i]=temp[i];           
  783.         }
  784.         shop[n]=ic;
  785.         delete [] temp;
  786.         n++;
  787.         return *this;
  788.     }
  789.     friend ostream &operator<<(ostream &out, const IceCreamShop &ics){
  790.         out<<ics.ime<<endl;
  791.         for(int i=0;i<ics.n;i++){
  792.             out<<ics.shop[i]<<endl;
  793.         }
  794.         return out;
  795.     }    
  796. };
  797.  
  798. // zabraneto e menuvanje na main funkcijata
  799. int main() {
  800.     char name[100];
  801.     char ingr[100];
  802.     float price;
  803.     int discount;
  804.  
  805.     int testCase;
  806.  
  807.     cin >> testCase;
  808.     cin.get();
  809.     if(testCase == 1) {
  810.         cout << "====== TESTING IceCream CLASS ======" << endl;
  811.         cin.getline(name,100);
  812.         cin.getline(ingr,100);
  813.         cin >> price;
  814.         cin >> discount;
  815.         cout << "CONSTRUCTOR" << endl;
  816.         IceCream ic1(name, ingr, price);
  817.         ic1.setDiscount(discount);
  818.         cin.get();
  819.         cin.getline(name,100);
  820.         cin.getline(ingr,100);
  821.         cin >> price;
  822.         cin >> discount;
  823.         IceCream ic2(name, ingr, price);
  824.         ic2.setDiscount(discount);
  825.         cout << "OPERATOR <<" << endl;
  826.         cout << ic1 << endl;
  827.         cout << ic2 << endl;
  828.         cout << "OPERATOR ++" << endl;
  829.         ++ic1;
  830.         cout << ic1 << endl;
  831.         cout << "OPERATOR +" << endl;
  832.         IceCream ic3 = ic2 + "chocolate";
  833.         cout << ic3 << endl;
  834.     } else if(testCase == 2) {
  835.         cout << "====== TESTING IceCream CONSTRUCTORS ======" << endl;
  836.         cin.getline(name,100);
  837.         cin.getline(ingr,100);
  838.         cin >> price;
  839.         cout << "CONSTRUCTOR" << endl;
  840.         IceCream ic1(name, ingr, price);
  841.         cout << ic1 << endl;
  842.         cout << "COPY CONSTRUCTOR" << endl;
  843.         IceCream ic2(ic1);
  844.         cin.get();
  845.         cin.getline(name,100);
  846.         ic2.setName(name);
  847.         cout << ic1 << endl;
  848.         cout << ic2 << endl;
  849.         cout << "OPERATOR =" << endl;
  850.         ic1 = ic2;
  851.         cin.getline(name,100);
  852.         ic2.setName(name);
  853.         cout << ic1 << endl;
  854.         cout << ic2 << endl;
  855.        
  856.         cin >> discount;
  857.         ic1.setDiscount(discount);
  858.  
  859.  
  860.     } else if(testCase == 3) {
  861.         cout << "====== TESTING IceCreamShop ======" << endl;
  862.         char icsName[50];
  863.         cin.getline(icsName,100);
  864.         cout << "CONSTRUCTOR" << endl;
  865.         IceCreamShop ics(icsName);
  866.         int n;
  867.         cin >> n;
  868.         cout << "OPERATOR +=" << endl;
  869.         for(int i = 0; i < n; ++i) {
  870.             cin.get();
  871.             cin.getline(name,100);
  872.             cin.getline(ingr,100);
  873.             cin >> price;
  874.             IceCream ic(name, ingr, price);
  875.             ics += ic;
  876.         }
  877.         cout << ics;
  878.     } else if(testCase == 4) {
  879.         cout << "====== TESTING IceCreamShop CONSTRUCTORS ======" << endl;
  880.         char icsName[50];
  881.         cin.getline(icsName,100);
  882.         IceCreamShop ics(icsName);
  883.         int n;
  884.         cin >> n;
  885.         for(int i = 0; i < n; ++i) {
  886.             cin.get();
  887.             cin.getline(name,100);
  888.             cin.getline(ingr,100);
  889.             cin >> price;
  890.             IceCream ic(name, ingr, price);
  891.             ics += ic;
  892.         }
  893.         IceCream x("FINKI fruits", "strawberry ice cream, raspberry ice cream, blueberry ice cream", 60);
  894.         IceCreamShop icp = ics;
  895.         ics+=x;
  896.         cout << ics << endl;
  897.         cout << icp << endl;
  898.     }
  899.  
  900.  
  901.     return 0;
  902. }
  903.  
  904. 8. Планинарски дом
  905. #include<iostream>
  906. #include<string.h>
  907. using namespace std;
  908.  
  909. //ова е место за вашиот код
  910. class Zichara {
  911. private:
  912.     char *place;
  913.     int dayPrice;
  914. public:
  915.     Zichara() {
  916.         place = new char[0];
  917.     }
  918.     Zichara(char *place, int price) {
  919.         this->place = new char[strlen(place)+1];
  920.         strcpy(this->place,place);
  921.         dayPrice = price;
  922.     }
  923.     ~Zichara() {
  924.         delete [] place;
  925.     }
  926.     Zichara(const Zichara &z) {
  927.         place = new char[strlen(z.place)+1];
  928.         strcpy(place,z.place);
  929.         dayPrice = z.dayPrice;
  930.     }
  931.     Zichara& operator=(const Zichara &z) {
  932.         if(this != &z){
  933.             delete [] place;
  934.             place = new char[strlen(z.place)+1];
  935.             dayPrice = z.dayPrice;
  936.         }
  937.         return *this;
  938.     }
  939.     int getPrice () {
  940.         return dayPrice;
  941.     }
  942. };
  943.  
  944. class PlaninarskiDom {
  945. private:
  946.     char name[15];
  947.     int prices [2];
  948.     char clas;
  949.     bool itHas;
  950.     Zichara zichara;
  951. public:
  952.     PlaninarskiDom() {
  953.         itHas = false;
  954.     }
  955.     PlaninarskiDom (char *name, int *prices, char clas) {
  956.         strcpy(this->name,name);
  957.         for(int i=0; i<2; i++)
  958.             this->prices[i] = prices[i];
  959.         this->clas = clas;
  960.     }
  961.     ~PlaninarskiDom() {}
  962.     PlaninarskiDom& operator=(const PlaninarskiDom &p) {
  963.         if(this != &p){
  964.             strcpy(name,p.name);
  965.             for(int i=0; i<2; i++)
  966.                 prices[i] = p.prices[i];
  967.             clas = p.clas;
  968.             itHas = p.itHas;
  969.             zichara = p.zichara;
  970.         }
  971.         return *this;
  972.     }
  973.     PlaninarskiDom& operator--() {
  974.         if(clas != 'F') {
  975.             ++clas;            
  976.         }
  977.         return *this;
  978.     }
  979.     friend ostream& operator<< (ostream &out, PlaninarskiDom &p) {
  980.         out << p.name << " klasa:" << p.clas;
  981.         if(p.itHas)
  982.             out << " so Zichara" << endl;
  983.         else
  984.             out << endl;        
  985.         return out;
  986.     }
  987.     bool operator <= (char znak) {
  988.         return clas > znak;
  989.     }
  990.     void setZichara (Zichara z) {
  991.         zichara = z;
  992.         itHas = true;        
  993.     }
  994.     void presmetajDnevenPrestoj(int den, int mesec, int &cena) {
  995.         if(den < 1 || den > 31 || mesec < 1 || mesec > 12) {
  996.             throw 5;
  997.         }
  998.         if (itHas)
  999.             cena += zichara.getPrice();
  1000.         if ((den >= 1&&mesec >= 4&&mesec < 9) || (mesec == 9&&den == 1)) {
  1001.             cena += prices[0];            
  1002.         }
  1003.         else {
  1004.             cena += prices[1];
  1005.         }
  1006.     }
  1007. };
  1008. int main(){
  1009.  
  1010.    PlaninarskiDom p; //креирање на нов објект од класата планинарски дом
  1011.  
  1012.    //во следниот дел се вчитуваат информации за планинарскиот дом
  1013.    char imePlaninarskiDom[15],mestoZichara[30],klasa;
  1014.    int ceni[12];
  1015.    int dnevnakartaZichara;
  1016.    bool daliZichara;
  1017.    cin>>imePlaninarskiDom;
  1018.    for (int i=0;i<2;i++) cin>>ceni[i];
  1019.    cin>>klasa;
  1020.    cin>>daliZichara;
  1021.  
  1022.    //во следниот дел се внесуваат информации и за жичарата ако постои
  1023.    if (daliZichara) {
  1024.       cin>>mestoZichara>>dnevnakartaZichara;
  1025.       PlaninarskiDom pom(imePlaninarskiDom,ceni,klasa);
  1026.       Zichara r(mestoZichara,dnevnakartaZichara);
  1027.       pom.setZichara(r);
  1028.       p=pom;
  1029.    }
  1030.    else{
  1031.       PlaninarskiDom *pok=new PlaninarskiDom(imePlaninarskiDom,ceni,klasa);
  1032.       p=*pok;
  1033.    }
  1034.  
  1035.    //се намалува класата на планинарскиот дом за 2
  1036.    --p;
  1037.    --p;
  1038.  
  1039.    int cena;
  1040.    int den,mesec;
  1041.    cin>>den>>mesec;
  1042.    try{
  1043.    p.presmetajDnevenPrestoj(den,mesec,cena); //тука се користи функцијата presmetajDnevenPrestoj
  1044.    cout<<"Informacii za PlaninarskiDomot:"<<endl;
  1045.    cout<<p;
  1046.    if (p<='D')
  1047.        cout<<"Planinarskiot dom za koj se vneseni informaciite ima klasa poniska ili ista so D\n";
  1048.        
  1049.    cout<<"Cenata za "<<den<<"."<<mesec<<" e "<<cena; //се печати цената за дадениот ден и месец
  1050.    }
  1051.    catch (int){
  1052.       cout<<"Mesecot ili denot e greshno vnesen!";
  1053.    }
  1054. }
  1055.  
  1056. 9. Податочен систем
  1057. #include<iostream>
  1058. #include<cstring>
  1059.  
  1060. using namespace std;
  1061. enum Extension{txt,pdf,exe};
  1062.  
  1063. class File{
  1064.  
  1065. char *ime;
  1066.  Extension eks;
  1067.  char *sopstvenik;
  1068.   int gol;
  1069. public:
  1070.     File(){}
  1071.     File(char *i,char*s,int g,Extension e){
  1072.     ime=new char[strlen(i)+1];
  1073.         strcpy(ime,i);
  1074.         sopstvenik=new char[strlen(s)+1];
  1075.         strcpy(sopstvenik,s);
  1076.         gol=g;
  1077.         eks=e;
  1078.      }
  1079.  
  1080.     File(const File &f){
  1081.      ime=new char[strlen(f.ime)+1];
  1082.         strcpy(ime,f.ime);
  1083.         sopstvenik=new char[strlen(f.sopstvenik)+1];
  1084.         strcpy(sopstvenik,f.sopstvenik);
  1085.         gol=f.gol;
  1086.         eks=f.eks;
  1087.  
  1088.     }
  1089.  
  1090.     File &operator=(const File &f){
  1091.      ime=new char[strlen(f.ime)+1];
  1092.         strcpy(ime,f.ime);
  1093.         sopstvenik=new char[strlen(f.sopstvenik)+1];
  1094.         strcpy(sopstvenik,f.sopstvenik);
  1095.         gol=f.gol;
  1096.         eks=f.eks;
  1097.   return *this;
  1098.     }
  1099.  
  1100.     ~File(){delete[]ime; delete[]sopstvenik;}
  1101.     void print(){
  1102.         cout<<"File name: "<<ime;
  1103.         if(eks==0) cout<<".pdf"<<endl;
  1104.         else if(eks==1) cout<<".txt"<<endl;
  1105.             else cout<<".exe"<<endl;
  1106.     cout<<"File owner: "<<sopstvenik<<endl;
  1107.         cout<<"File size: "<<gol<<endl;
  1108.    
  1109.     }
  1110.  
  1111.     bool equals(const File & that){
  1112.    
  1113.     return strcmp(ime,that.ime)==0&&strcmp(sopstvenik,that.sopstvenik)==0&&eks==that.eks;
  1114.    
  1115.     }
  1116.     bool equalsType(const File & that){
  1117.     return strcmp(ime,that.ime)==0&&eks==that.eks;
  1118.     }
  1119.  
  1120.  
  1121. };
  1122.  
  1123. class Folder{
  1124.  
  1125. char * ime;
  1126. File * niza;
  1127.  int n;
  1128.  
  1129. public:
  1130.     Folder(){}
  1131.     Folder(const char* name){
  1132.     ime=new char[strlen(name)+1];
  1133.         strcpy(ime,name);
  1134.         n=0;
  1135.         niza=NULL;
  1136.     }
  1137.     Folder(const Folder &f){
  1138.    
  1139.     ime=new char[strlen(f.ime)+1];
  1140.         strcpy(ime,f.ime);
  1141.     niza=new File[f.n];
  1142.         for(int i=0;i<f.n;i++){
  1143.         niza[i]=f.niza[i];
  1144.         }
  1145.     n=f.n;
  1146.     }
  1147.    
  1148.        Folder &operator=(const Folder &f){
  1149.    
  1150.     ime=new char[strlen(f.ime)+1];
  1151.         strcpy(ime,f.ime);
  1152.     niza=new File[f.n];
  1153.         for(int i=0;i<f.n;i++){
  1154.         niza[i]=f.niza[i];
  1155.         }
  1156.          n=f.n;
  1157.            return *this;
  1158.     }
  1159.    
  1160.     ~Folder(){delete[]niza; delete[]ime;}
  1161.  
  1162.     void print(){
  1163.     cout<<"Folder name: "<<ime<<endl;
  1164.         for(int i=0;i<n;i++){
  1165.         niza[i].print();
  1166.         }
  1167.     }
  1168.     void remove(const File & file){
  1169.     int zname=0,prv;
  1170.         for(int i=0;i<n;i++){
  1171.             if(niza[i].equals(file)){
  1172.             zname=1; prv=i;
  1173.             }
  1174.          }
  1175.         if(zname){
  1176.         File *temp=niza;
  1177.             niza=new File[n-1];
  1178.             int j=0;
  1179.             for(int i=0;i<n;i++){
  1180.                 if(i!=prv){
  1181.              niza[j]=temp[i];
  1182.                     j++;}}
  1183.         delete []temp;
  1184.               n=j;
  1185.         }
  1186.          
  1187.            
  1188.           }
  1189.    
  1190.     void add(const File & file){
  1191.    
  1192.     File *temp=niza;
  1193.         niza=new File[n+1];
  1194.         for(int i=0;i<n;i++){
  1195.         niza[i]=temp[i];
  1196.        
  1197.         }
  1198.     niza[n++]=file;
  1199.         delete[]temp;
  1200.    
  1201.    }
  1202.    
  1203. };
  1204.  
  1205.  
  1206. int main() {
  1207.     char fileName[20];
  1208.     char fileOwner[20];
  1209.     int ext;
  1210.     int fileSize;
  1211.  
  1212.     int testCase;
  1213.     cin >> testCase;
  1214.     if (testCase == 1) {
  1215.         cout << "======= FILE CONSTRUCTORS AND = OPERATOR =======" << endl;
  1216.         cin >> fileName;
  1217.         cin >> fileOwner;
  1218.         cin >> fileSize;
  1219.         cin >> ext;
  1220.  
  1221.         File created = File(fileName, fileOwner, fileSize, (Extension) ext);
  1222.         File copied = File(created);
  1223.         File assigned = created;
  1224.  
  1225.         cout << "======= CREATED =======" << endl;
  1226.         created.print();
  1227.         cout << endl;
  1228.         cout << "======= COPIED =======" << endl;
  1229.         copied.print();
  1230.         cout << endl;
  1231.         cout << "======= ASSIGNED =======" << endl;
  1232.         assigned.print();
  1233.     }
  1234.     else if (testCase == 2) {
  1235.         cout << "======= FILE EQUALS & EQUALS TYPE =======" << endl;
  1236.         cin >> fileName;
  1237.         cin >> fileOwner;
  1238.         cin >> fileSize;
  1239.         cin >> ext;
  1240.  
  1241.         File first(fileName, fileOwner, fileSize, (Extension) ext);
  1242.         first.print();
  1243.  
  1244.         cin >> fileName;
  1245.         cin >> fileOwner;
  1246.         cin >> fileSize;
  1247.         cin >> ext;
  1248.  
  1249.         File second(fileName, fileOwner, fileSize, (Extension) ext);
  1250.         second.print();
  1251.  
  1252.         cin >> fileName;
  1253.         cin >> fileOwner;
  1254.         cin >> fileSize;
  1255.         cin >> ext;
  1256.  
  1257.         File third(fileName, fileOwner, fileSize, (Extension) ext);
  1258.         third.print();
  1259.  
  1260.         bool equals = first.equals(second);
  1261.         cout << "FIRST EQUALS SECOND: ";
  1262.         if (equals)
  1263.             cout << "TRUE" << endl;
  1264.         else
  1265.             cout << "FALSE" << endl;
  1266.  
  1267.         equals = first.equals(third);
  1268.         cout << "FIRST EQUALS THIRD: ";
  1269.         if (equals)
  1270.             cout << "TRUE" << endl;
  1271.         else
  1272.             cout << "FALSE" << endl;
  1273.  
  1274.         bool equalsType = first.equalsType(second);
  1275.         cout << "FIRST EQUALS TYPE SECOND: ";
  1276.         if (equalsType)
  1277.             cout << "TRUE" << endl;
  1278.         else
  1279.             cout << "FALSE" << endl;
  1280.  
  1281.         equalsType = second.equals(third);
  1282.         cout << "SECOND EQUALS TYPE THIRD: ";
  1283.         if (equalsType)
  1284.             cout << "TRUE" << endl;
  1285.         else
  1286.             cout << "FALSE" << endl;
  1287.  
  1288.     }
  1289.     else if (testCase == 3) {
  1290.         cout << "======= FOLDER CONSTRUCTOR =======" << endl;
  1291.         cin >> fileName;
  1292.         Folder folder(fileName);
  1293.         folder.print();
  1294.  
  1295.     }
  1296.     else if (testCase == 4) {
  1297.         cout << "======= ADD FILE IN FOLDER =======" << endl;
  1298.         char name[20];
  1299.         cin >> name;
  1300.         Folder folder(name);
  1301.  
  1302.         int iter;
  1303.         cin >> iter;
  1304.  
  1305.         while (iter > 0) {
  1306.             cin >> fileName;
  1307.             cin >> fileOwner;
  1308.             cin >> fileSize;
  1309.             cin >> ext;
  1310.  
  1311.             File file(fileName, fileOwner, fileSize, (Extension) ext);
  1312.             folder.add(file);
  1313.             iter--;
  1314.         }
  1315.         folder.print();
  1316.     }
  1317.     else {
  1318.         cout << "======= REMOVE FILE FROM FOLDER =======" << endl;
  1319.         char name[20];
  1320.         cin >> name;
  1321.         Folder folder(name);
  1322.  
  1323.         int iter;
  1324.         cin >> iter;
  1325.  
  1326.         while (iter > 0) {
  1327.             cin >> fileName;
  1328.             cin >> fileOwner;
  1329.             cin >> fileSize;
  1330.             cin >> ext;
  1331.  
  1332.             File file(fileName, fileOwner, fileSize, (Extension) ext);
  1333.             folder.add(file);
  1334.             iter--;
  1335.         }
  1336.         cin >> fileName;
  1337.         cin >> fileOwner;
  1338.         cin >> fileSize;
  1339.         cin >> ext;
  1340.  
  1341.         File file(fileName, fileOwner, fileSize, (Extension) ext);
  1342.         folder.remove(file);
  1343.         folder.print();
  1344.     }
  1345.     return 0;
  1346. }
  1347.  
  1348. 10. Фактура
  1349. #include <stdio.h>
  1350. #include <string.h>
  1351.  
  1352. //место за вашиот код
  1353. typedef struct Proizvod{
  1354.     char kod[20];
  1355.     int cena;
  1356.     int n; 
  1357. } Proizvod;
  1358. typedef struct Narachka{
  1359.     char ime[15];
  1360.     Proizvod p[10];
  1361.     int broj[10];
  1362.     int brojnarachani;
  1363. } Narachka;
  1364. void pecatiFaktura(Narachka n){
  1365.     printf("Faktura za %s\n",n.ime);
  1366.     Proizvod tmp[20];
  1367.     for(int i=0;i<n.brojnarachani;i++){
  1368.         if(n.brojnarachani>n.p[i].n){
  1369.             printf("Fakturata ne moze da se izgotvi");
  1370.             return;        
  1371.         }
  1372.     }
  1373.    
  1374.     for(int i=0;i<n.brojnarachani-1;i++){
  1375.         for(int j=i+1;j<n.brojnarachani;j++){
  1376.             if(strcmp(n.p[i].kod,n.p[j].kod)>0){
  1377.                 tmp[i]=n.p[j];
  1378.                 n.p[j]=n.p[i];
  1379.                 n.p[i]=tmp[i];
  1380.             }
  1381.         }
  1382.     }
  1383.     int vkupno=0;
  1384.    
  1385.     for(int i=0;i<n.brojnarachani;i++){
  1386.         if(n.p[i].n>n.broj[i]){
  1387.             n.p[i].n=n.broj[i];
  1388.             printf("%s %d %d %d\n",n.p[i].kod,n.p[i].cena,n.p[i].n,n.p[i].cena*n.p[i].n);
  1389.             vkupno+=n.p[i].cena*n.p[i].n;
  1390.         }
  1391.     }
  1392.     printf("Vkupnata suma na fakturata e %d",vkupno);
  1393. }
  1394. int main() {
  1395.     Narachka narachka;
  1396.     // внеси го името лицето кое ја прави нарачката
  1397.     scanf("%s",narachka.ime);
  1398.     // внеси го бројот на порачани производи во нарачката
  1399.     scanf("%d",&narachka.brojnarachani);
  1400.     int i;
  1401.     //за секој од нарачаните производи се внесуваат информации
  1402.     for (i = 0; i < narachka.brojnarachani; ++i) {
  1403.         // внеси код
  1404.         scanf("%s",narachka.p[i].kod);
  1405.         // внеси единицчна цена
  1406.         scanf("%d",&narachka.p[i].cena);
  1407.         // внеси број на производи во магацин
  1408.         scanf("%d",&narachka.p[i].n);
  1409.     }
  1410.     //за секој производ се внесува колку такви производи се порачани во нарачката
  1411.     int j;
  1412.     for (j = 0; j < narachka.brojnarachani; ++j) {
  1413.        //се внесува број на производи во нарачката
  1414.         scanf("%d",&narachka.broj[j]);        
  1415.     }
  1416.     // повик на функцијата pecatiFaktura
  1417.     pecatiFaktura(narachka);
  1418.     return 0;
  1419. }
  1420.  
  1421. 11. Воз
  1422. #include<iostream>
  1423. #include<cstring>
  1424. using namespace std;
  1425.  
  1426. class Patnik {
  1427. private:
  1428.     char ime[100];
  1429.     int klasa;
  1430.     bool velosiped;
  1431. public:
  1432.     Patnik(const char *ime="", int klasa=0, bool velosiped=false) {
  1433.         strcpy(this->ime,ime);
  1434.         this->klasa=klasa;
  1435.         this->velosiped=velosiped;
  1436.     }
  1437.     Patnik(const Patnik &p) {
  1438.         strcpy(this->ime,p.ime);
  1439.         this->klasa=p.klasa;
  1440.         this->velosiped=p.velosiped;
  1441.     }
  1442.     Patnik &operator=(const Patnik &p) {
  1443.         if(this!=&p){
  1444.         strcpy(this->ime,p.ime);
  1445.         this->klasa=p.klasa;
  1446.         this->velosiped=p.velosiped;
  1447.         }
  1448.         return *this;
  1449.     }
  1450.     ~Patnik() {}
  1451.     void pecati() {
  1452.         cout<<ime<<endl<<klasa<<endl<<velosiped<<endl;
  1453.         cout<<endl;
  1454.     }
  1455.     int getKlasa(){
  1456.         return klasa;
  1457.     }
  1458.     bool getVelosiped(){
  1459.         return velosiped;
  1460.     }
  1461. };
  1462. class Voz {
  1463. private:
  1464.     char destinacija[100];
  1465.     Patnik *patnici;
  1466.     int n;
  1467.     int maxvelosipedi;
  1468. public:
  1469.     Voz(const char *destinacija="", int n=0, Patnik *patnici=0, int maxvelosipedi=0) {
  1470.         strcpy(this->destinacija,destinacija);
  1471.         this->maxvelosipedi=maxvelosipedi;
  1472.         this->n=n;
  1473.         this->patnici = new Patnik [this->n];
  1474.         for(int i=0; i<this->n; i++) {
  1475.             this->patnici[i]=patnici[i];
  1476.         }
  1477.     }
  1478.     Voz(char *destinacija, int maxvelosipedi) {
  1479.         strcpy(this->destinacija, destinacija);
  1480.         this->maxvelosipedi = maxvelosipedi;
  1481.         patnici = NULL;
  1482.         n = 0;
  1483.     }
  1484.     Voz(const Voz &v) {
  1485.         strcpy(this->destinacija,v.destinacija);
  1486.         this->maxvelosipedi=v.maxvelosipedi;
  1487.         this->n=v.n;
  1488.         this->patnici = new Patnik [this->n];
  1489.         for(int i=0; i<n; i++) {
  1490.             this->patnici[i]=v.patnici[i];
  1491.         }
  1492.     }
  1493.     Voz &operator=(const Voz &v) {
  1494.         if(this!=&v) {
  1495.             strcpy(this->destinacija,v.destinacija);
  1496.             this->maxvelosipedi=v.maxvelosipedi;
  1497.             this->n=v.n;
  1498.             delete [] patnici;
  1499.             for(int i=0; i<n; i++) {
  1500.                 this->patnici[i]=v.patnici[i];
  1501.             }
  1502.             this->patnici = new Patnik [this->n];
  1503.         }
  1504.         return *this;
  1505.     }
  1506.     ~Voz() {
  1507.         delete [] patnici;
  1508.     }
  1509.     Voz dodadiPatnik(Patnik p) {
  1510.         if ((!p.getVelosiped()&&maxvelosipedi == 0) || maxvelosipedi != 0) {
  1511.             Patnik *tmp = new Patnik[n + 1];
  1512.             for (int i = 0; i < n; i++) {
  1513.                 tmp[i] = patnici[i];
  1514.             }
  1515.             delete[]patnici;
  1516.             patnici = new Patnik[n + 1];
  1517.             for (int i = 0; i < n; i++) {
  1518.                 patnici[i] = tmp[i];
  1519.             }
  1520.             patnici[n] = p;
  1521.             n++;
  1522.         }
  1523.         return *this;
  1524.     }
  1525.     void pecatiVoz(Voz v){
  1526.         cout<<v.destinacija<<endl;
  1527.         for(int i=0;i<v.n;i++)
  1528.             v.patnici[i].pecati();
  1529.     }
  1530.     void patniciNemaMesto(){
  1531.         int brPrva=0,brVtora=0;
  1532.         for(int i=0;i<n;i++){
  1533.             if(patnici[i].getKlasa()==1 && patnici[i].getVelosiped()==true){
  1534.                 brPrva++;                
  1535.             }
  1536.             if(patnici[i].getKlasa()==2 && patnici[i].getVelosiped()==true){
  1537.                 brVtora++;                
  1538.             }
  1539.         }
  1540.         if(brPrva>=maxvelosipedi){
  1541.             brPrva-=maxvelosipedi;             
  1542.         }
  1543.         else{
  1544.             maxvelosipedi-=brPrva;
  1545.             brPrva=0;
  1546.         if(brVtora>=maxvelosipedi){
  1547.             brVtora-=maxvelosipedi;
  1548.         }
  1549.         else{
  1550.             brVtora=0;
  1551.         }
  1552.         }
  1553.         cout<<"Brojot na patnici od 1-va klasa koi ostanale bez mesto e: "<<brPrva<<endl;
  1554.         cout<<"Brojot na patnici od 2-ra klasa koi ostanale bez mesto e: "<<brVtora;
  1555.     }
  1556. };
  1557. int main() {
  1558.     Patnik p;
  1559.     char ime[100], destinacija[100];
  1560.     int n;
  1561.     bool velosiped;
  1562.     int klasa;
  1563.     int maxv;
  1564.     cin >> destinacija >> maxv;
  1565.     cin >> n;
  1566.     Voz v(destinacija, maxv);
  1567.     //cout<<v<<endl;
  1568.     for (int i = 0; i < n; i++) {
  1569.         cin >> ime >> klasa >> velosiped;
  1570.         Patnik p(ime, klasa, velosiped);
  1571.         //cout<<p<<endl;
  1572.         v.dodadiPatnik(p);
  1573.     }
  1574.     v.pecatiVoz(v);
  1575.     v.patniciNemaMesto();
  1576.     return 0;
  1577. }
  1578.  
  1579. 12. Работни часови
  1580. #include <stdio.h>
  1581. #include <string.h>
  1582. #define NEDELI 4
  1583. #define DENOVI 5
  1584.  
  1585. // ovde strukturata RabotnaNedela
  1586.  
  1587. typedef struct RabotnaNedela{
  1588.     int casovi[5];
  1589.     int nedela;
  1590.  
  1591. }RN;
  1592.  
  1593. // ovde strukturata Rabotnik
  1594.  
  1595. typedef struct Rabotnik{
  1596.     char ime[50];
  1597.     RN nedeli[4];  
  1598. }R;
  1599.  
  1600. // ovde funkciite
  1601. int maxNedela(R *r){
  1602.     int vkupnocasovi=0,max=0,maxindex=0;
  1603.     for(int i=0;i<4;i++){
  1604.         for(int j=0;j<5;j++){
  1605.             vkupnocasovi+=r->nedeli[i].casovi[j];
  1606.         }
  1607.         if(vkupnocasovi>max){
  1608.             max=vkupnocasovi;
  1609.             maxindex=i;
  1610.         }
  1611.         vkupnocasovi=0;
  1612.     }
  1613.     return maxindex+1;    
  1614. }
  1615. void table(R *r, int n){
  1616.     int vkupnonedela[4]={0},vkupno=0;
  1617.     printf("Rab\t1\t2\t3\t4\tVkupno\n");
  1618.     for(int i=0;i<n;i++){
  1619.         printf("%s\t",r[i].ime);
  1620.         for(int j=0;j<4;j++){
  1621.             for(int k=0;k<5;k++){
  1622.                 vkupnonedela[j]+=r[i].nedeli[j].casovi[k];
  1623.             }
  1624.         }
  1625.         vkupno=vkupnonedela[0]+vkupnonedela[1]+vkupnonedela[2]+vkupnonedela[3];
  1626.         printf("%d\t%d\t%d\t%d\t%d\n",vkupnonedela[0],vkupnonedela[1],vkupnonedela[2],vkupnonedela[3],vkupno);
  1627.         vkupno=0;
  1628.         for(int m=0;m<4;m++)
  1629.             vkupnonedela[m]=0;
  1630.     }
  1631. }
  1632. int main() {
  1633.     int n;
  1634.     scanf("%d", &n);
  1635.     R rabotnici[n];
  1636.     int i;
  1637.     for (i = 0; i < n; ++i) {
  1638.         scanf("%s", rabotnici[i].ime);
  1639.         int j;
  1640.         for (j = 0; j < NEDELI; ++j) {
  1641.             int k;
  1642.             for (k = 0; k < DENOVI; ++k) {
  1643.                 scanf("%d", &rabotnici[i].nedeli[j].casovi[k]);
  1644.             }
  1645.  
  1646.         }
  1647.     }
  1648.     printf("TABLE\n");
  1649.     table(rabotnici, n);
  1650.     printf("MAX NEDELA NA RABOTNIK: %s\n", rabotnici[n / 2].ime);
  1651.     printf("%d\n", maxNedela(&rabotnici[n / 2]));
  1652.     return 0;
  1653. }
  1654.  
  1655. 13. Танчери
  1656. #include<iostream>
  1657. #include<cstring>
  1658. using namespace std;
  1659. struct Tanc{
  1660.     char ime[15];
  1661.     char zemja[15];
  1662. };
  1663. struct Tancer{
  1664.     char ime[20];
  1665.     char prezime[20];
  1666.     Tanc niza[5];  
  1667. };
  1668. void tancuvanje(Tancer *t, int n, char *zemja){
  1669.     for(int i=0;i<n;i++){
  1670.         for(int j=0;j<n;j++){
  1671.             if(strcmp(zemja,t[i].niza[j].zemja)==0){
  1672.                 cout<<t[i].ime<<" "<<t[i].prezime<<", "<<t[i].niza[j].ime<<endl;
  1673.                 break;
  1674.             }
  1675.         }
  1676.     }
  1677. }
  1678. int main()
  1679. {
  1680.     int i, j, n;
  1681.     char zemja[15];
  1682.     Tancer tanceri[5];
  1683.     cin >> n;
  1684.     for(i = 0; i < n; i++){
  1685.         cin >> tanceri[i].ime;
  1686.         cin >> tanceri[i].prezime;
  1687.         for(j = 0; j < 3; j++){
  1688.             cin >> tanceri[i].niza[j].ime;
  1689.             cin >> tanceri[i].niza[j].zemja;
  1690.         }
  1691.     }
  1692.     cin >> zemja;
  1693.     tancuvanje(tanceri, n, zemja);
  1694.     return 0;
  1695. }
  1696.  
  1697. 14. Структура во C
  1698. #include<stdio.h>
  1699. #include<string.h>
  1700. typedef struct Pacient{
  1701.     char ime[100];
  1702.     int zdrastveno;
  1703.     int pregledi;
  1704. }Pacient;
  1705. typedef struct doktor{
  1706.     char ime[100];
  1707.     int br_pac;
  1708.     Pacient niza[200];
  1709.     float cena;
  1710. }doktor;
  1711. void najuspesen_doktor(doktor *md, int n){
  1712.     float vkupno[100]={0.0},maxvkupno=0;
  1713.     int maxvkupnop=0,maxindex,maxvkupnopregledi=0,vkupnopregledi[100]={0},vkupnop[100]={0};
  1714.     for(int i=0;i<n;i++){
  1715.         for(int j=0;j<md[i].br_pac;j++){
  1716.             vkupnop[i]+=md[i].niza[j].pregledi;
  1717.             if(md[i].niza[j].zdrastveno==0){
  1718.                 ++vkupnopregledi[i];
  1719.                     vkupnopregledi[i]*=md[i].niza[j].pregledi;
  1720.                     vkupno[i]+=md[i].cena*vkupnopregledi[i];
  1721.                     if(j==n-1){
  1722.                     if(vkupno[i]>maxvkupno){
  1723.                     maxvkupno=vkupno[i];
  1724.                     maxindex=i;
  1725.                     maxvkupnopregledi=vkupnopregledi[i];
  1726.                     }
  1727.                 }
  1728.             }
  1729.         }
  1730.     }
  1731.     for(int i=0;i<n;i++){
  1732.         if(vkupno[i]==maxvkupno){
  1733.               if(vkupnop[i]>vkupnop[maxindex])
  1734.                     maxindex=i;                    
  1735.         }
  1736.     }
  1737.     printf("%s %.2f %d", md[maxindex].ime,maxvkupno,vkupnop[maxindex]);
  1738. }
  1739.    
  1740.  
  1741. int main()
  1742. {
  1743.     int i, j, n, broj;
  1744.     doktor md[200];
  1745.     scanf("%d", &n);
  1746.     for (i = 0; i < n; i++){
  1747.         //ime na doktor
  1748.         scanf("%s", md[i].ime);
  1749.         //broj na pacienti
  1750.         scanf("%d", &md[i].br_pac);
  1751.         //cena na pregled
  1752.         scanf("%f", &md[i].cena);
  1753.  
  1754.         for (j = 0; j < md[i].br_pac; j++){
  1755.             scanf("%s", md[i].niza[j].ime);
  1756.             scanf("%d", &md[i].niza[j].zdrastveno);
  1757.             scanf("%d", &md[i].niza[j].pregledi);
  1758.         }
  1759.     }
  1760.     najuspesen_doktor(md, n);
  1761.  
  1762.     return 0;
  1763. }
  1764.  
  1765. 15. Акции
  1766. #include<iostream>
  1767. #include<cstring>
  1768. using namespace std;
  1769.  
  1770. // vasiot kod za klasite ovde
  1771. class StockRecord{
  1772.     private:
  1773.     char ID[12];
  1774.     char ime[50];
  1775.     double cena;
  1776.     double momcena;
  1777.     int broj;
  1778.     public:
  1779.     StockRecord(char *ID="",char *ime="",double cena=0,int broj=0){
  1780.         strcpy(this->ID,ID);
  1781.         strcpy(this->ime,ime);
  1782.         this->cena=cena;
  1783.         this->broj=broj;
  1784.         this->momcena=0;        
  1785.     }
  1786.     StockRecord(const StockRecord &sr){
  1787.         strcpy(this->ID,sr.ID);
  1788.         strcpy(this->ime,sr.ime);
  1789.         this->cena=sr.cena;
  1790.         this->broj=sr.broj;
  1791.         this->momcena=sr.momcena;
  1792.     }
  1793.     StockRecord &operator=(const StockRecord &sr){
  1794.         if(this!=&sr){
  1795.         strcpy(this->ID,sr.ID);
  1796.         strcpy(this->ime,sr.ime);
  1797.         this->cena=sr.cena;
  1798.         this->broj=sr.broj;
  1799.         this->momcena=sr.momcena;
  1800.         }
  1801.         return *this;
  1802.     }
  1803.     ~StockRecord(){}
  1804.     void setNewPrice(double c){
  1805.         this->momcena=c;
  1806.     }
  1807.     double value(){
  1808.         return broj*momcena;
  1809.     }
  1810.     double profit(){
  1811.         return broj*(momcena-cena);
  1812.     }
  1813.     void print(){
  1814.         cout<<ime<<" "<<broj<<" "<<cena<<" "<<momcena<<" "<<profit()<<endl;
  1815.     }
  1816. };
  1817. class Client{
  1818.     private:
  1819.     char ime[60];
  1820.     int ID;
  1821.     StockRecord *comp;
  1822.     int n;    
  1823.     public:
  1824.     Client(char *ime="",int ID=0){
  1825.         strcpy(this->ime,ime);
  1826.         this->ID=ID;
  1827.         this->comp=NULL;
  1828.         this->n=0;
  1829.     }
  1830.     Client(const Client &c){
  1831.         strcpy(this->ime,c.ime);
  1832.         this->ID=c.ID;
  1833.         this->n=c.n;
  1834.         for(int i=0;i<n;i++)
  1835.             this->comp[i]=c.comp[i];
  1836.     }
  1837.     Client &operator=(const Client &c){
  1838.         if(this!=&c){
  1839.         strcpy(this->ime,c.ime);
  1840.         this->ID=c.ID;
  1841.         this->n=c.n;
  1842.         for(int i=0;i<n;i++)
  1843.             this->comp[i]=c.comp[i];
  1844.         }
  1845.         return *this;
  1846.     }
  1847.     ~Client(){
  1848.         delete [] comp;
  1849.     }
  1850.     double totalValue(){
  1851.         double vkupno=0;
  1852.         for(int i=0;i<n;i++){
  1853.             vkupno+=comp[i].value();
  1854.         }
  1855.         return vkupno;
  1856.     }
  1857.     void dodadi(StockRecord & sr){
  1858.         StockRecord *tmp = new StockRecord[n+1];
  1859.         for(int i=0;i<n;i++)
  1860.             tmp[i]=comp[i];
  1861.         tmp[n++]=sr;
  1862.         delete [] comp;
  1863.         comp=tmp;                  
  1864.     }
  1865.     void print(){
  1866.         cout<<ID<<" "<<totalValue()<<endl;
  1867.         for(int i=0;i<n;i++){
  1868.             comp[i].print();
  1869.         }
  1870.     }
  1871. };
  1872.  
  1873.  
  1874. // ne menuvaj vo main-ot
  1875.  
  1876. int main(){
  1877.    
  1878.     int test;
  1879.     cin >> test;
  1880.    
  1881.     if(test == 1){
  1882.         double price;
  1883.         cout << "=====TEST NA KLASATA StockRecord=====" << endl;
  1884.         StockRecord sr("1", "Microsoft", 60.0, 100);
  1885.         cout << "Konstruktor OK" << endl;
  1886.         cin >> price;
  1887.         sr.setNewPrice(price);
  1888.         cout << "SET metoda OK" << endl;
  1889.     }
  1890.     else if(test == 2){
  1891.         cout << "=====TEST NA METODITE I OPERATOR << OD KLASATA StockRecord=====" << endl;
  1892.         char id[12], company[50];
  1893.         double price, newPrice;
  1894.         int n, shares;
  1895.         cin >> n;
  1896.         for(int i = 0; i < n; ++i){
  1897.             cin >> id;
  1898.             cin >> company;
  1899.             cin >> price;
  1900.             cin >> newPrice;
  1901.             cin >> shares;
  1902.             StockRecord sr(id, company, price, shares);
  1903.             sr.setNewPrice(newPrice);
  1904.             cout << sr.value() << endl;
  1905.             sr.print();
  1906.         }
  1907.     }
  1908.     else if(test == 3){
  1909.         cout << "=====TEST NA KLASATA Client=====" << endl;
  1910.         char companyID[12], companyName[50], clientName[50];
  1911.         int clientID, n, shares;
  1912.         double oldPrice, newPrice;
  1913.         bool flag = true;
  1914.         cin >> clientName;
  1915.         cin >> clientID;
  1916.         cin >> n;
  1917.         Client c(clientName, clientID);
  1918.         cout << "Konstruktor OK" << endl;
  1919.         for(int i = 0; i < n; ++i){
  1920.             cin >> companyID;
  1921.             cin >> companyName;
  1922.             cin >> oldPrice;
  1923.             cin >> newPrice;
  1924.             cin >> shares;
  1925.             StockRecord sr(companyID, companyName, oldPrice, shares);
  1926.             sr.setNewPrice(newPrice);
  1927.             c.dodadi(sr);
  1928.             if(flag){
  1929.                 cout << "Operator += OK" << endl;
  1930.                 flag = false;
  1931.             }
  1932.         }
  1933.         c.print();
  1934.         cout << "Operator << OK" << endl;
  1935.     }
  1936.     return 0;
  1937.  
  1938. }
  1939.  
  1940. 16. Забавен парк
  1941. #include <stdio.h>
  1942. #include <string.h>
  1943. typedef struct Vozenje {
  1944.     char ime[100];
  1945.     int traenje;
  1946.     float cena;
  1947.     int daliPopust;
  1948. } Vozenje;
  1949. typedef struct ZabavenPark {
  1950.     char ime[100];
  1951.     char lokacija[100];
  1952.     Vozenje niza[100];
  1953.     int n;
  1954. } ZabavenPark;
  1955. void pecati(ZabavenPark *niza, int n) {
  1956.     for(int i=0; i<n; i++) {
  1957.         printf("%s %s\n",niza[i].ime,niza[i].lokacija);
  1958.         for(int j=0; j<niza[i].n; j++) {
  1959.             printf("%s %d %.2f\n",niza[i].niza[j].ime,niza[i].niza[j].traenje,niza[i].niza[j].cena);
  1960.         }
  1961.     }
  1962. }
  1963. void najdobar_park(ZabavenPark *niza, int n) {
  1964.     int i,j,k,maxi=0,br=0,maxbr=0,vkupno[100]= {0};
  1965.     for(i=0; i<n; i++) {
  1966.         for(j=0; j<niza[i].n; j++) {
  1967.             vkupno[i]+=niza[i].niza[j].traenje;
  1968.             if(niza[i].niza[j].daliPopust==1) {
  1969.                 br++;
  1970.             }
  1971.             if(br>maxbr) {
  1972.                 maxbr=br;
  1973.                 maxi=i;
  1974.             }
  1975.         }
  1976.     }    
  1977.     for(i=0; i<n; i++) {
  1978.     if(br==maxbr) {
  1979.         if(vkupno[i]>vkupno[maxi]) {
  1980.             maxi=i;
  1981.         }
  1982.     }
  1983.     }
  1984.     printf("Najdobar park: %s %s",niza[maxi].ime,niza[maxi].lokacija);
  1985. }
  1986. int main() {
  1987.     int i, j, n, broj;
  1988.     //kreiraj niza od maksimum 100 zabavni parkovi
  1989.     ZabavenPark ff[100];
  1990.     scanf("%d", &n);
  1991.     //citanje na podatocite
  1992.     for (i = 0; i < n; i++) {
  1993.         //ime na festivalot
  1994.         scanf("%s", ff[i].ime);
  1995.         //mesto
  1996.         scanf("%s", ff[i].lokacija);
  1997.         //broj na filmovi
  1998.         scanf("%d", &ff[i].n);
  1999.         for (j = 0; j < ff[i].n; j++) {
  2000.             scanf("%s", ff[i].niza[j].ime);             /* Ime na filmot */
  2001.             scanf("%d", &ff[i].niza[j].traenje);        /* Vremetraenje   */
  2002.             scanf("%f", &ff[i].niza[j].cena);   /* Cena */
  2003.             scanf("%d", &ff[i].niza[j].daliPopust); /* Popust */
  2004.  
  2005.         }
  2006.     }
  2007.     pecati(ff,n);
  2008.     najdobar_park(ff,n);
  2009.  
  2010.     return 0;
  2011. }
  2012.  
  2013. 17. Гитари
  2014. #include <iostream>
  2015. #include <cstring>
  2016. using namespace std;
  2017.  
  2018. class Gitara{
  2019. private:
  2020.     char seriski[25];
  2021.     double nabavna;
  2022.     int godinaProizvodstvo;
  2023.     char tip[40];
  2024.     public:
  2025.         Gitara(char *tip="",char * seriski ="",int godinaProizvodstvo=0,double nabavna =0)
  2026.         {
  2027.             strcpy(this->tip,tip);
  2028.             strcpy(this->seriski,seriski);
  2029.             this->godinaProizvodstvo = godinaProizvodstvo;
  2030.             this->nabavna = nabavna;
  2031.         }
  2032.         Gitara(const Gitara &g)
  2033.         {
  2034.             strcpy(this->tip,g.tip);
  2035.             strcpy(this->seriski,g.seriski);
  2036.             this->godinaProizvodstvo = g.godinaProizvodstvo;
  2037.             this->nabavna = g.nabavna;
  2038.         }
  2039.         Gitara & operator=(const Gitara &g)
  2040.         {
  2041.             strcpy(this->tip,g.tip);
  2042.             strcpy(this->seriski,g.seriski);
  2043.             this->godinaProizvodstvo = g.godinaProizvodstvo;
  2044.             this->nabavna = g.nabavna;
  2045.             return *this;
  2046.         }
  2047.         ~Gitara()
  2048.         {
  2049.         }
  2050.         bool daliIsti(Gitara &g)
  2051.         {
  2052.          return strcmp(this->seriski,g.seriski)==0;
  2053.         }
  2054.         void pecati()
  2055.         {
  2056.             cout<<seriski<<" "<<tip<<" "<<nabavna<<endl;
  2057.         }
  2058.         double getNabavna()
  2059.         {
  2060.             return nabavna;
  2061.         }
  2062.         char * getTip()
  2063.         {
  2064.             return tip;
  2065.         }
  2066.         char * getSeriski()
  2067.         {
  2068.             return seriski;
  2069.         }
  2070.         int getGodina()
  2071.         {
  2072.             return godinaProizvodstvo;
  2073.         }
  2074. };
  2075.  
  2076. class Magacin{
  2077. private:
  2078.     char lokacija[60];
  2079.     char ime[50];
  2080.     int godinaOtvaranje;
  2081.     Gitara * niza;
  2082.     int brGitari;
  2083.     public:
  2084.         Magacin(char * ime="",char * lokacija="",int godinaOtvaranje=0)
  2085.         {
  2086.             strcpy(this->lokacija,lokacija);
  2087.             strcpy(this->ime,ime);
  2088.             this->godinaOtvaranje = godinaOtvaranje;
  2089.             niza = NULL;
  2090.             brGitari = 0;
  2091.         }
  2092.         Magacin(const Magacin & m)
  2093.         {
  2094.             strcpy(this->lokacija,m.lokacija);
  2095.             strcpy(this->ime,m.ime);
  2096.             this->godinaOtvaranje = m.godinaOtvaranje;
  2097.             niza = new Gitara[m.brGitari];
  2098.             for(int i =0;i<m.brGitari;i++)
  2099.                 niza[i] = m.niza[i];
  2100.             brGitari = m.brGitari;
  2101.         }
  2102.  
  2103.         Magacin & operator=(const Magacin & m)
  2104.         {
  2105.             delete [] niza;
  2106.             strcpy(this->lokacija,m.lokacija);
  2107.             strcpy(this->ime,m.ime);
  2108.             this->godinaOtvaranje = m.godinaOtvaranje;
  2109.             niza = new Gitara[m.brGitari];
  2110.             for(int i =0;i<m.brGitari;i++)
  2111.                 niza[i] = m.niza[i];
  2112.             brGitari = m.brGitari;
  2113.             return *this;
  2114.         }
  2115.         ~Magacin(){delete [] niza;}
  2116.         double vrednost()
  2117.         {
  2118.             double sum=0;
  2119.             for(int i=0;i<brGitari;i++)
  2120.                 sum+=niza[i].getNabavna();
  2121.                 return sum;
  2122.  
  2123.         }
  2124.         void dodadi(Gitara & g)
  2125.         {
  2126.             Gitara * tmp = new Gitara[brGitari +1];
  2127.             for(int i=0;i<brGitari;i++)
  2128.                 tmp[i] = niza[i];
  2129.             tmp[brGitari++]=g;
  2130.             delete [] niza;
  2131.             niza=tmp;
  2132.  
  2133.         }
  2134.         void prodadi(Gitara & g)
  2135.         {
  2136.             int newBr = 0;
  2137.             for(int i=0;i<brGitari;i++)
  2138.             {
  2139.                 if(niza[i].daliIsti(g)==false)
  2140.                 {
  2141.                     newBr++;
  2142.                 }
  2143.             }
  2144.             Gitara * tmp = new Gitara[newBr];
  2145.             int j=0;
  2146.             for(int i=0;i<brGitari;i++)
  2147.             {
  2148.                 if(niza[i].daliIsti(g)==false)
  2149.                 {
  2150.                    tmp[j] = niza[i];
  2151.                    j++;
  2152.                 }
  2153.             }
  2154.             delete [] niza;
  2155.             niza = tmp;
  2156.             brGitari = newBr;
  2157.         }
  2158.         void pecati(bool daliNovi)
  2159.         {
  2160.             cout<<ime<<" "<< lokacija<<endl;
  2161.             for(int i=0;i<brGitari;i++)
  2162.             {
  2163.                 if(daliNovi==true&&niza[i].getGodina()>godinaOtvaranje)
  2164.                 {
  2165.                     niza[i].pecati();
  2166.                 }
  2167.                 else if(daliNovi==false){
  2168.                    niza[i].pecati();
  2169.                 }
  2170.             }
  2171.         }
  2172. };
  2173.     int main() {
  2174.     // se testira zadacata modularno
  2175.     int testCase;
  2176.     cin >> testCase;
  2177.  
  2178.     int n, godina;
  2179.     float cena;
  2180.     char seriski[50],tip[50];
  2181.  
  2182.     if(testCase == 1) {
  2183.         cout << "===== Testiranje na klasata Gitara ======" << endl;
  2184.         cin>>tip;
  2185.         cin>>seriski;
  2186.         cin >> godina;
  2187.         cin >> cena;
  2188.         Gitara g(tip,seriski, godina,cena);
  2189.         cout<<g.getTip()<<endl;
  2190.         cout<<g.getSeriski()<<endl;
  2191.         cout<<g.getGodina()<<endl;
  2192.         cout<<g.getNabavna()<<endl;
  2193.     } else if(testCase == 2){
  2194.         cout << "===== Testiranje na klasata Magacin so metodot print() ======" << endl;
  2195.         Magacin kb("Magacin1","Lokacija1");
  2196.         kb.pecati(false);
  2197.     }
  2198.     else if(testCase == 3) {
  2199.         cout << "===== Testiranje na klasata Magacin so metodot dodadi() ======" << endl;
  2200.         Magacin kb("Magacin1","Lokacija1",2005);
  2201.         cin>>n;
  2202.             for (int i=0;i<n;i++){
  2203.                 cin>>tip;
  2204.                 cin>>seriski;
  2205.                 cin >> godina;
  2206.                 cin >> cena;
  2207.                 Gitara g(tip,seriski, godina,cena);
  2208.                 cout<<"gitara dodadi"<<endl;
  2209.                 kb.dodadi(g);
  2210.             }
  2211.         kb.pecati(true);
  2212.     }
  2213.  
  2214.     else if(testCase == 4) {
  2215.         cout << "===== Testiranje na klasata Magacin so metodot prodadi() ======" << endl;
  2216.         Magacin kb("Magacin1","Lokacija1",2012);
  2217.             cin>>n;
  2218.             Gitara brisi;
  2219.             for (int i=0;i<n;i++){
  2220.                 cin>>tip;
  2221.                 cin>>seriski;
  2222.                 cin >> godina;
  2223.                 cin >> cena;
  2224.  
  2225.                 Gitara g(tip,seriski, godina,cena);
  2226.                 if(i==2)
  2227.                     brisi=g;
  2228.                 cout<<"gitara dodadi"<<endl;
  2229.                 kb.dodadi(g);
  2230.             }
  2231.         kb.pecati(false);
  2232.         kb.prodadi(brisi);
  2233.         kb.pecati(false);
  2234.     }
  2235.     else if(testCase == 5) {
  2236.         cout << "===== Testiranje na klasata Magacin so metodot prodadi() i pecati(true) ======" << endl;
  2237.         Magacin kb("Magacin1","Lokacija1",2011);
  2238.             cin>>n;
  2239.             Gitara brisi;
  2240.             for (int i=0;i<n;i++){
  2241.                 cin>>tip;
  2242.                 cin>>seriski;
  2243.                 cin >> godina;
  2244.                 cin >> cena;
  2245.  
  2246.                 Gitara g(tip,seriski, godina,cena);
  2247.                 if(i==2)
  2248.                     brisi=g;
  2249.                 cout<<"gitara dodadi"<<endl;
  2250.                 kb.dodadi(g);
  2251.             }
  2252.         kb.pecati(true);
  2253.         kb.prodadi(brisi);
  2254.         cout<<"Po brisenje:"<<endl;
  2255.         Magacin kb3;
  2256.         kb3=kb;
  2257.         kb3.pecati(true);
  2258.     }
  2259.    else if(testCase ==6)
  2260.         {
  2261.         cout << "===== Testiranje na klasata Magacin so metodot vrednost()======" << endl;
  2262.         Magacin kb("Magacin1","Lokacija1",2011);
  2263.             cin>>n;
  2264.             Gitara brisi;
  2265.             for (int i=0;i<n;i++){
  2266.                 cin>>tip;
  2267.                 cin>>seriski;
  2268.                 cin >> godina;
  2269.                 cin >> cena;
  2270.  
  2271.                 Gitara g(tip,seriski, godina,cena);
  2272.                 if(i==2)
  2273.                     brisi=g;
  2274.                 kb.dodadi(g);
  2275.             }
  2276.         cout<<kb.vrednost()<<endl;
  2277.         kb.prodadi(brisi);
  2278.         cout<<"Po brisenje:"<<endl;
  2279.         cout<<kb.vrednost();
  2280.         Magacin kb3;
  2281.         kb3=kb;
  2282.         }
  2283.     return 0;
  2284. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement