Advertisement
HeatPulse

Vezbi za prv kolokvium

Apr 11th, 2019
713
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 69.15 KB | None | 0 0
  1. 1.KOMPJUTERSKA IGRA
  2. #include<iostream>
  3. using namespace std;
  4. struct Igrac {
  5. char korisnickoIme[15];
  6. int nivo;
  7. int poeni;
  8.  
  9. };
  10. struct KompjuterskaIgra {
  11. char ime[20];
  12. Igrac lista[30];
  13. int n;
  14. };
  15. void najdobarIgrac(KompjuterskaIgra *igri,int n) {
  16. int indeksNajmnoguIgraci=0;
  17. for (int i=1; i<n; i++) {
  18. if (igri[i].n>igri[indeksNajmnoguIgraci].n)
  19. indeksNajmnoguIgraci=i;
  20. }
  21.  
  22. KompjuterskaIgra najpopularna=igri[indeksNajmnoguIgraci];
  23. int indeksmax=0;
  24. for (int i=1; i<najpopularna.n; i++) {
  25. if (najpopularna.lista[i].poeni>najpopularna.lista[indeksmax].poeni)
  26. indeksmax=i;
  27. else if (najpopularna.lista[i].poeni==najpopularna.lista[indeksmax].poeni) {
  28. if (najpopularna.lista[i].nivo>najpopularna.lista[indeksmax].nivo)
  29. indeksmax=i;
  30. }
  31. }
  32. cout<<"Najdobar igrac e igracot so korisnicko ime ";
  33. cout<<najpopularna.lista[indeksmax].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.  
  54. najdobarIgrac(poleigri,n);
  55. return 0;
  56. }
  57. 2.SKIJACKI CENTAR
  58. //STARTER
  59. /*
  60. #include<stdio.h>
  61. #include<string.h>
  62.  
  63.  
  64. int main()
  65. {
  66. scanf("%d", &n);
  67. for (i = 0; i < n; i++){
  68. //vnesi ime
  69. //vnesi drzava
  70. //vnesi broj na liftovi
  71.  
  72.  
  73. //za sekoj ski lift vnesi:
  74. //vnesi ime
  75. //vnesi maksimalen broj korisnici
  76. //vnesi dali e pusten vo funkcija
  77. }
  78.  
  79. //povik na funkcijata najgolemKapacitet
  80.  
  81. return 0;
  82. }
  83. */
  84. //RESENIE
  85. #include<stdio.h>
  86. #include<string.h>
  87.  
  88. typedef struct SkiLift{
  89. char ime[20];
  90. int max_skijaci;
  91. int voUpotreba;
  92. }skiLift;
  93.  
  94. typedef struct SkiCenter {
  95. char ime[20];
  96. char drzava[20];
  97. skiLift niza[20];
  98. int br_lifts;
  99. }skiCenter;
  100.  
  101. int kapacitet(skiCenter sc)
  102. {
  103. int i;
  104. int tmp = 0;
  105. for (i = 0; i < sc.br_lifts; i++)
  106. {
  107. if (sc.niza[i].voUpotreba == 1)
  108. {
  109. tmp += sc.niza[i].max_skijaci;
  110. }
  111. }
  112. return tmp;
  113.  
  114. }
  115. void najgolemKapacitet(skiCenter *sc, int n)
  116. {
  117. int tmp, i, j, max, max_ind;
  118. max = 0;
  119. max_ind = 0;
  120. for (i = 0; i < n; i++)
  121. {
  122. tmp = kapacitet(sc[i]);
  123. if ((tmp > max) || (tmp == max&&sc[i].br_lifts > sc[max_ind].br_lifts)) { max = tmp; max_ind = i; }
  124. }
  125. printf("%s\n%s\n%d\n", sc[max_ind].ime, sc[max_ind].drzava, max);
  126. }
  127.  
  128. int main()
  129. {
  130. int i, j, n, broj;
  131. skiCenter sc[20];
  132. scanf("%d", &n);
  133. for (i = 0; i < n; i++){
  134. //printf("Ime:");
  135. scanf("%s", sc[i].ime);
  136. //printf("\nDrzava:");
  137. scanf("%s", sc[i].drzava);
  138. scanf("%d", &sc[i].br_lifts);
  139.  
  140. for (j = 0; j < sc[i].br_lifts; j++){
  141. scanf("%s", sc[i].niza[j].ime);
  142. scanf("%d", &sc[i].niza[j].max_skijaci);
  143. scanf("%d", &sc[i].niza[j].voUpotreba);
  144. }
  145. }
  146. najgolemKapacitet(sc, n);
  147.  
  148. return 0;
  149. }
  150. 3.CD
  151. #include<iostream>
  152. #include<cstring>
  153. using namespace std;
  154. enum tip {
  155. POP,RAP,ROK
  156. };
  157. class Pesna {
  158. private:
  159. char *ime;
  160. int vremetraenje;
  161. tip tipPesna;
  162. public:
  163. Pesna(char *ime=" ", int vremetraenje=0, tip tipPesna=POP)
  164. {
  165. this->ime=new char[strlen(ime)+1];
  166. strcpy(this->ime, ime);
  167. this->vremetraenje=vremetraenje;
  168. this->tipPesna=tipPesna;
  169. }
  170. ~Pesna(){
  171. delete [] ime;
  172. }
  173. Pesna(const Pesna &p)
  174. {
  175. this->ime=new char[strlen(p.ime)+1];
  176. strcpy(this->ime, p.ime);
  177. this->vremetraenje=p.vremetraenje;
  178. this->tipPesna=p.tipPesna;
  179. }
  180. Pesna & operator=(Pesna &p)
  181. {
  182. if(this!=&p)
  183. {
  184. delete [] ime;
  185. this->ime=new char[strlen(p.ime)+1];
  186. strcpy(this->ime, p.ime);
  187. this->vremetraenje=p.vremetraenje;
  188. this->tipPesna=p.tipPesna;
  189. }
  190. return *this;
  191. }
  192. void pecati()
  193. {
  194. cout<<"\""<<ime<<"\""<<"-"<<vremetraenje<<"min"<<endl;
  195. }
  196. friend class CD;
  197. };
  198.  
  199. class CD {
  200. private:
  201. Pesna pesni[10];
  202. int n;
  203. int maxVremetraenje;
  204. public:
  205. CD(int maxVremetraenje=0)
  206. {
  207. this->maxVremetraenje=maxVremetraenje;
  208. n=0;
  209. }
  210.  
  211. void dodadiPesna(Pesna p)
  212. {
  213. int momentalnoVremetraenje=0;
  214. for(int i=0;i<n;i++)
  215. momentalnoVremetraenje +=pesni[i].vremetraenje;
  216. if(momentalnoVremetraenje+p.vremetraenje>maxVremetraenje)
  217. {
  218. //cout<<"Nadminato e max vremetraenje"<<endl;
  219. return;
  220. }
  221. if(n==10)
  222. {
  223. //cout<<"Nema vekje prostor vo nizata"<<endl;
  224. return;
  225. }
  226. pesni[n]=p;
  227. n++;
  228. }
  229. void pecatiPesniPoTip(tip Pesna)
  230. {
  231. for (int i=0;i<n;i++)
  232. {
  233. if (pesni[i].tipPesna==Pesna)
  234. {
  235. pesni[i].pecati();
  236. }
  237. }
  238. }
  239. Pesna getPesna(int i)
  240. {
  241. return pesni[i];
  242. }
  243. int getBroj(){
  244. return n;
  245. }
  246.  
  247. };
  248.  
  249. int main() {
  250. // se testira zadacata modularno
  251. int testCase;
  252. cin >> testCase;
  253.  
  254. int n, minuti, kojtip;
  255. char ime[50];
  256.  
  257. if(testCase == 1) {
  258. cout << "===== Testiranje na klasata Pesna ======" << endl;
  259. cin >> ime;
  260. cin >> minuti;
  261. cin >> kojtip; //se vnesuva 0 za POP,1 za RAP i 2 za ROK
  262. Pesna p(ime,minuti,(tip)kojtip);
  263. p.pecati();
  264. } else if(testCase == 2) {
  265. cout << "===== Testiranje na klasata CD ======" << endl;
  266. CD omileno(20);
  267. cin>>n;
  268. for (int i=0;i<n;i++){
  269. cin >> ime;
  270. cin >> minuti;
  271. cin >> kojtip; //se vnesuva 0 za POP,1 za RAP i 2 za ROK
  272. Pesna p(ime,minuti,(tip)kojtip);
  273. omileno.dodadiPesna(p);
  274. }
  275. for (int i=0; i<n; i++)
  276. (omileno.getPesna(i)).pecati();
  277. }
  278. else if(testCase == 3) {
  279. cout << "===== Testiranje na metodot dodadiPesna() od klasata CD ======" << endl;
  280. CD omileno(20);
  281. cin>>n;
  282. for (int i=0;i<n;i++){
  283. cin >> ime;
  284. cin >> minuti;
  285. cin >> kojtip; //se vnesuva 0 za POP,1 za RAP i 2 za ROK
  286. Pesna p(ime,minuti,(tip)kojtip);
  287. omileno.dodadiPesna(p);
  288. }
  289. for (int i=0; i<omileno.getBroj(); i++)
  290. (omileno.getPesna(i)).pecati();
  291. }
  292. else if(testCase == 4) {
  293. cout << "===== Testiranje na metodot pecatiPesniPoTip() od klasata CD ======" << endl;
  294. CD omileno(20);
  295. cin>>n;
  296. for (int i=0;i<n;i++){
  297. cin >> ime;
  298. cin >> minuti;
  299. cin >> kojtip; //se vnesuva 0 za POP,1 za RAP i 2 za ROK
  300. Pesna p(ime,minuti,(tip)kojtip);
  301. omileno.dodadiPesna(p);
  302. }
  303. cin>>kojtip;
  304. omileno.pecatiPesniPoTip((tip)kojtip);
  305.  
  306. }
  307. else if(testCase == 5) {
  308. cout << "===== Testiranje na metodot pecatiPesniPoTip() od klasata CD ======" << endl;
  309. CD omileno(20);
  310. cin>>n;
  311. for (int i=0;i<n;i++){
  312. cin >> ime;
  313. cin >> minuti;
  314. cin >> kojtip; //se vnesuva 0 za POP,1 za RAP i 2 za ROK
  315. Pesna p(ime,minuti,(tip)kojtip);
  316. omileno.dodadiPesna(p);
  317. }
  318. cin>>kojtip;
  319. omileno.pecatiPesniPoTip((tip)kojtip);
  320.  
  321. }
  322.  
  323. return 0;
  324. }
  325. 4.ZELEZNICKA STANICA
  326. #include<iostream>
  327. #include <cstring>
  328. using namespace std;
  329. struct Voz{
  330. char relacija[50];
  331. float kilometri;
  332. int patnici;
  333.  
  334.  
  335.  
  336.  
  337.  
  338. };
  339. struct ZeleznickaStanica{
  340. char grad[20];
  341. Voz vozovi[30];
  342. int broj_na_vozovi;
  343.  
  344.  
  345.  
  346. };
  347.  
  348. void najkratkaRelacija(ZeleznickaStanica* zs, int n, char* grad)
  349. {
  350. int tmp1=0,tmp2=0; int flag=1; int pom=0;
  351. for(int i=0;i<n;i++)
  352. {
  353. if(strcmp(zs[i].grad,grad)==0)
  354. {
  355.  
  356. for(int j=0;j<zs[i].broj_na_vozovi;j++)
  357. {
  358.  
  359. if (flag)
  360. {
  361.  
  362. pom=zs[i].vozovi[j].kilometri;
  363. flag=0;
  364. }
  365.  
  366. if(pom>= zs[i].vozovi[j].kilometri)
  367. {
  368. tmp1=i;
  369. tmp2=j;
  370. pom=zs[i].vozovi[j].kilometri;
  371.  
  372. }
  373.  
  374. }
  375.  
  376.  
  377. }
  378.  
  379. }
  380.  
  381. cout<<"Najkratka relacija: "<<zs[tmp1].vozovi[tmp2].relacija<<" ("<<zs[tmp1].vozovi[tmp2].kilometri<<" km)";
  382. }
  383. int main(){
  384.  
  385. int n;
  386. cin>>n; //se cita brojot na zelezlnichki stanici
  387.  
  388. ZeleznickaStanica zStanica[100];
  389. for (int i=0;i<n;i++){
  390. //se citaat infomracii za n zelezlnichkite stanici i se zacuvuvaat vo poleto zStanica
  391.  
  392. cin>>zStanica[i].grad;
  393. cin>>zStanica[i].broj_na_vozovi;
  394. for(int j=0;j<zStanica[i].broj_na_vozovi;j++)
  395. {
  396. cin>>zStanica[i].vozovi[j].relacija;
  397. cin>>zStanica[i].vozovi[j].kilometri;
  398. cin>>zStanica[i].vozovi[j].patnici;
  399. }
  400.  
  401.  
  402.  
  403.  
  404. }
  405.  
  406. char grad[25];
  407. cin>>grad;
  408.  
  409. najkratkaRelacija(zStanica,n,grad);
  410. return 0;
  411. }
  412. 5.PICERIJA
  413. #include <iostream>
  414. #include <cstring>
  415.  
  416. using namespace std;
  417.  
  418. class Pica {
  419. private:
  420. char ime[15];
  421. int cena;
  422. char* sostojki;
  423. int namaluvanje;
  424. public:
  425.  
  426. Pica(const char* ime = "", int cena = 0, const char* sostojki = "", int namaluvanje = 0) {
  427.  
  428. strcpy(this->ime, ime);
  429. this->cena = cena;
  430. this->sostojki = new char[strlen(sostojki) + 1];
  431. strcpy(this->sostojki, sostojki);
  432. this->namaluvanje = namaluvanje;
  433. }
  434.  
  435. Pica(const Pica& p) {
  436. strcpy(ime, p.ime);
  437. cena = p.cena;
  438. sostojki = new char[strlen(p.sostojki) + 1];
  439. strcpy(sostojki, p.sostojki);
  440. namaluvanje = p.namaluvanje;
  441. }
  442.  
  443. ~Pica() {
  444. delete[] sostojki;
  445. }
  446.  
  447. Pica& operator= (Pica& p) {
  448. if (this != &p) {
  449. strcpy(ime, p.ime);
  450. cena = p.cena;
  451. delete[] sostojki;
  452. sostojki = new char[strlen(p.sostojki) + 1];
  453. strcpy(sostojki, p.sostojki);
  454. namaluvanje = p.namaluvanje;
  455. }
  456. return *this;
  457. }
  458. void pecati(){
  459. cout << ime << " - " << sostojki << ", " << cena;
  460. }
  461.  
  462. bool istiSe(Pica p){
  463. return (strcmp(sostojki, p.sostojki) == 0);
  464. }
  465. int getNamaluvanje(){
  466. return namaluvanje;
  467. }
  468. int getCena(){
  469. return cena;
  470. }
  471. };
  472.  
  473. class Picerija {
  474.  
  475. private:
  476. char ime[15];
  477. Pica* pici;
  478. int br;
  479.  
  480. public:
  481. Picerija(const char *ime = ""){
  482. strncpy(this->ime, ime, 14);
  483. this->ime[14] = 0;
  484. pici = NULL;
  485. br = 0;
  486. }
  487. Picerija(const char *ime, Pica* pici, int br) {
  488. strncpy(this->ime, ime, 14);
  489. this->ime[14] = 0;
  490. this->br = br;
  491. this->pici = new Pica[br];
  492. for (int i = 0; i < br; i++)
  493. this->pici[i] = pici[i];
  494. }
  495.  
  496. Picerija(const Picerija &p) {
  497. strcpy(ime, p.ime);
  498. br = p.br;
  499. pici = new Pica[br];
  500. for (int i = 0; i < br; i++)
  501. pici[i] = p.pici[i];
  502. }
  503. Picerija& operator= (const Picerija &p) {
  504. if (this != &p) {
  505. strcpy(ime, p.ime);
  506. br = p.br;
  507. delete[] pici;
  508. pici = new Pica[br];
  509. for (int i = 0; i < br; i++)
  510. pici[i] = p.pici[i];
  511. }
  512. return *this;
  513. }
  514. ~Picerija() {
  515. delete[] pici;
  516. }
  517.  
  518. Picerija& operator+=(Pica &p){
  519. bool imaIsta = false;
  520. for (int i = 0; i < br; i++)
  521. if (pici[i].istiSe(p))
  522. imaIsta = true;
  523. if (!imaIsta)
  524. {
  525. Pica* tmp = new Pica[br + 1];
  526. for (int i = 0; i < br; i++)
  527. tmp[i] = pici[i];
  528. tmp[br++] = p;
  529. delete[] pici;
  530. pici = tmp;
  531. }
  532. return *this;
  533. }
  534.  
  535. void piciNaPromocija() {
  536. for (int i = 0; i < br; i++){
  537. if (pici[i].getNamaluvanje() != 0){
  538. pici[i].pecati();
  539. cout << " " << pici[i].getCena() * (1 - pici[i].getNamaluvanje() / 100.0) << endl;
  540. }
  541. }
  542.  
  543. }
  544. const char* getIme(){
  545. return ime;
  546. }
  547. void setIme(const char* ime){
  548. strncpy(this->ime, ime, 14);
  549. this->ime[14] = 0;
  550. }
  551.  
  552. };
  553. int main() {
  554.  
  555. int n;
  556. char ime[15];
  557. cin >> ime;
  558. cin >> n;
  559.  
  560. Picerija p1(ime);
  561. for (int i = 0; i < n; i++){
  562. char imp[100];
  563. cin.get();
  564. cin.getline(imp, 100);
  565. int cena;
  566. cin >> cena;
  567. char sostojki[100];
  568. cin.get();
  569. cin.getline(sostojki, 100);
  570. int popust;
  571. cin >> popust;
  572. Pica p(imp, cena, sostojki, popust);
  573. p1+=p;
  574. }
  575.  
  576. Picerija p2 = p1;
  577. cin >> ime;
  578. p2.setIme(ime);
  579. char imp[100];
  580. cin.get();
  581. cin.getline(imp, 100);
  582. int cena;
  583. cin >> cena;
  584. char sostojki[100];
  585. cin.get();
  586. cin.getline(sostojki, 100);
  587. int popust;
  588. cin >> popust;
  589. Pica p(imp, cena, sostojki, popust);
  590. p2+=p;
  591.  
  592. cout << p1.getIme() << endl;
  593. cout << "Pici na promocija:" << endl;
  594. p1.piciNaPromocija();
  595.  
  596. cout << p2.getIme() << endl;
  597. cout << "Pici na promocija:" << endl;
  598. p2.piciNaPromocija();
  599.  
  600. return 0;
  601. }
  602. 4.MARATON
  603. #include <iostream>
  604. #include <cstring>
  605. using namespace std;
  606.  
  607. class Ucesnik
  608. {
  609. private:
  610. char *ime;
  611. bool pol;
  612. int vozrast;
  613.  
  614. public:
  615. Ucesnik(const char *ime="",bool pol=false,int vozrast=0)
  616. {
  617. this->ime= new char[strlen(ime)+1];
  618. strcpy(this->ime,ime);
  619. this->pol=pol;
  620. this->vozrast=vozrast;
  621. }
  622. Ucesnik(const Ucesnik &u)
  623. {
  624. this->ime= new char[strlen(u.ime)+1];
  625. strcpy(this->ime,u.ime);
  626. this->pol=u.pol;
  627. this->vozrast=u.vozrast;
  628. }
  629. Ucesnik &operator=(const Ucesnik &u)
  630. {
  631. if(this!=&u)
  632. {
  633. delete []ime;
  634. this->ime= new char[strlen(u.ime)+1];
  635. strcpy(this->ime,u.ime);
  636. this->pol=u.pol;
  637. this->vozrast=u.vozrast;
  638. }
  639. return *this;
  640. }
  641. bool sporedi(Ucesnik &u)
  642. {
  643. return (vozrast>u.vozrast);
  644. }
  645.  
  646. void pecati()
  647. {
  648. if(pol==true)
  649. cout<<ime<<"\n"<<"mashki"<<"\n"<<vozrast<<endl;
  650. else
  651. cout<<ime<<"\n"<<"zhenski"<<"\n"<<vozrast<<endl;
  652. }
  653.  
  654. int getVozrast()
  655. {
  656. return vozrast;
  657. }
  658.  
  659. ~Ucesnik()
  660. {
  661. delete []ime;
  662. }
  663.  
  664. };
  665.  
  666. class Maraton
  667. {
  668. private:
  669. char lokacija[100];
  670. Ucesnik *ucesnici;
  671. int br_ucesnici;
  672.  
  673. public:
  674.  
  675. Maraton(char *lokacija)
  676. {
  677. strcpy(this->lokacija,lokacija);
  678. this->br_ucesnici=0;
  679. this->ucesnici= new Ucesnik [br_ucesnici];
  680.  
  681. }
  682. Maraton(const Maraton &m)
  683. {
  684. strcpy(this->lokacija,m.lokacija);
  685. this->br_ucesnici=m.br_ucesnici;
  686. this->ucesnici=new Ucesnik [m.br_ucesnici];
  687. for(int i=0;i<br_ucesnici;i++)
  688. {
  689. this->ucesnici[i]=m.ucesnici[i];
  690. }
  691. }
  692. Maraton &operator=(const Maraton &m)
  693. {
  694. if(this!=&m)
  695. {
  696. strcpy(this->lokacija,m.lokacija);
  697. this->br_ucesnici=m.br_ucesnici;
  698. delete []ucesnici;
  699. this->ucesnici=new Ucesnik [m.br_ucesnici];
  700. for(int i=0;i<br_ucesnici;i++)
  701. {
  702. this->ucesnici[i]=m.ucesnici[i];
  703. }
  704. }
  705. return *this;
  706. }
  707. void dodadi(Ucesnik &u)
  708. {
  709. Ucesnik *temp;
  710. temp = new Ucesnik[br_ucesnici+1];
  711. for(int i=0;i<br_ucesnici;i++)
  712. {
  713. temp[i]=ucesnici[i];
  714. }
  715. temp[br_ucesnici++]=u;
  716.  
  717. delete []ucesnici;
  718. ucesnici=temp;
  719.  
  720. }
  721. double prosecnoVozrast()
  722. {
  723. double suma=0.0;
  724. for(int i=0;i<br_ucesnici;i++)
  725. {
  726. suma+=ucesnici[i].getVozrast();
  727.  
  728. }
  729.  
  730. return (double)suma/br_ucesnici;
  731. }
  732.  
  733. void pecatiPomladi(Ucesnik &u)
  734. {
  735.  
  736. for(int i=0;i<br_ucesnici;i++)
  737. {
  738. if(ucesnici[i].getVozrast()<u.getVozrast())
  739. ucesnici[i].pecati();
  740.  
  741. }
  742.  
  743. }
  744. ~Maraton()
  745. {
  746. delete []ucesnici;
  747. }
  748.  
  749. };
  750.  
  751. int main()
  752. {
  753. char ime[100];
  754. bool maski;
  755. int vozrast, n;
  756. cin >> n;
  757. char lokacija[100];
  758. cin >> lokacija;
  759. Maraton m(lokacija);
  760. Ucesnik **u = new Ucesnik*[n];
  761. for(int i = 0; i < n; ++i) {
  762. cin >> ime >> maski >> vozrast;
  763. u[i] = new Ucesnik(ime, maski, vozrast);
  764. //m += *u[i];
  765. m.dodadi(*u[i]);
  766.  
  767. }
  768. m.pecatiPomladi(*u[n - 1]);
  769. cout << m.prosecnoVozrast() << endl;
  770. for(int i = 0; i < n; ++i) {
  771. delete u[i];
  772. }
  773. delete [] u;
  774. return 0;
  775. }
  776. 4.REPOZITORIUM
  777. #include <iostream>
  778. #include <string.h>
  779. using namespace std;
  780. enum Tip {LINUX,UNIX,WINDOWS};
  781. class OperativenSistem
  782. {
  783. private:
  784. char *imeOs;
  785. float verzija;
  786. Tip tip;
  787. float golemina;
  788. public:
  789. OperativenSistem()
  790. {
  791. imeOs=new char[0];
  792. verzija=0;
  793.  
  794. golemina=0;
  795. }
  796. OperativenSistem(char *imeOs, float verzija,enum Tip tip, float golemina)
  797. {
  798. this->imeOs=new char[strlen(imeOs)+1];
  799. strcpy(this->imeOs,imeOs);
  800. this->verzija=verzija;
  801. this->tip=tip;
  802. this->golemina=golemina;
  803. }
  804. OperativenSistem(const OperativenSistem &os)
  805. {
  806. this->imeOs=new char[strlen(os.imeOs)+1];
  807. strcpy(this->imeOs,os.imeOs);
  808. this->verzija=os.verzija;
  809. this->tip=os.tip;
  810. this->golemina=os.golemina;
  811. }
  812. OperativenSistem &operator=(const OperativenSistem &os)
  813. {
  814. if(this!=&os)
  815. {
  816. delete []imeOs;
  817. this->imeOs=new char[strlen(os.imeOs)+1];
  818. strcpy(this->imeOs,os.imeOs);
  819. this->verzija=os.verzija;
  820. this->tip=os.tip;
  821. this->golemina=os.golemina;
  822. }
  823. return *this;
  824. }
  825. void pecati()
  826. {
  827. cout<<"Ime: "<<imeOs<<" Verzija: "<<verzija<<" Tip: "<<tip<<" Golemina:"<<golemina<<"GB"<<endl;
  828. }
  829. bool ednakviSe(const OperativenSistem &os)
  830. {
  831. return strcmp(imeOs,os.imeOs)==0&&verzija==os.verzija &&tip==os.tip&&golemina==os.golemina;
  832. }
  833. int sporediVerzija(const OperativenSistem &os)
  834. {
  835. if(verzija==os.verzija)
  836. {
  837. return 0;
  838. }
  839. else if(verzija<os.verzija)
  840. {
  841. return -1;
  842. }
  843. else
  844. {
  845. return 1;
  846. }
  847. }
  848. bool istaFamilija(const OperativenSistem &sporedba)
  849. {
  850. return (strcmp(imeOs,sporedba.imeOs)==0)&&(tip==sporedba.tip);
  851. }
  852. ~OperativenSistem()
  853. {
  854. delete []imeOs;
  855. }
  856. };
  857. class Repozitorium
  858. {
  859. private:
  860. char imeRe[20];
  861. OperativenSistem *os;
  862. int brOS;
  863. public:
  864.  
  865. Repozitorium(char *imeRe)
  866. {
  867. strcpy(this->imeRe,imeRe);
  868. brOS=0;
  869. os=new OperativenSistem[brOS];
  870. }
  871. Repozitorium(const Repozitorium &re)
  872. {
  873. strcpy(this->imeRe,re.imeRe);
  874. this->brOS=re.brOS;
  875. this->os=new OperativenSistem[brOS];
  876. for(int i=0; i<brOS; i++)
  877. {
  878. (this->os)[i]=re.os[i];
  879. }
  880. }
  881. Repozitorium& operator=(const Repozitorium &re)
  882. {
  883. if(this!=&re)
  884. {
  885. strcpy(this->imeRe,re.imeRe);
  886. this->brOS=re.brOS;
  887. delete []os;
  888. this->os=new OperativenSistem[brOS];
  889. for(int i=0; i<brOS; i++)
  890. {
  891. this->os[i]=re.os[i];
  892. }
  893. }
  894. return *this;
  895. }
  896. void pecatiOperativniSistemi()
  897. {
  898. cout<<"Repozitorium: "<<imeRe<<endl;
  899. for(int i=0;i<brOS;i++)
  900. {
  901. os[i].pecati();
  902. }
  903. }
  904. void izbrishi(const OperativenSistem &izbrisi)
  905. {
  906. int indeks=-1;
  907. for(int i=0;i<brOS;i++)
  908. {
  909. if(os[i].ednakviSe(izbrisi))
  910. {
  911. indeks=i;
  912.  
  913. }
  914. }
  915. if(indeks==-1)
  916. {
  917. return;
  918. }
  919. OperativenSistem *brisi=new OperativenSistem[brOS-1];
  920.  
  921. for(int i=0;i<brOS;i++)
  922. {
  923. if(i!=indeks)
  924. {
  925. brisi[i]=os[i];
  926.  
  927. }
  928. }
  929. brOS--;
  930. delete []os;
  931. os=brisi;
  932. }
  933. void dodadi (const OperativenSistem &nov)
  934. {
  935. for(int i=0;i<brOS;i++)
  936. {
  937. if(os[i].istaFamilija(nov)&&os[i].sporediVerzija(nov)==-1)
  938. {
  939. os[i]=nov;
  940. return;
  941. }
  942. }
  943. OperativenSistem *dodaden=new OperativenSistem[brOS+1];
  944. for(int i=0;i<brOS;i++)
  945. {
  946. dodaden[i]=os[i];
  947. }
  948. dodaden[brOS++]=nov;
  949. delete []os;
  950. os=dodaden;
  951.  
  952. }
  953. ~Repozitorium()
  954. {
  955. delete []os;
  956. }
  957.  
  958. };
  959.  
  960.  
  961. int main() {
  962. char repoName[20];
  963. cin>>repoName;
  964. Repozitorium repozitorium=Repozitorium(repoName);
  965. int brojOperativniSistemi = 0;
  966. cin>>brojOperativniSistemi;
  967. char ime[20];
  968. float verzija;
  969. int tip;
  970. float golemina;
  971. for (int i = 0; i<brojOperativniSistemi; i++){
  972. cin>>ime;
  973. cin>>verzija;
  974. cin>>tip;
  975. cin>>golemina;
  976. OperativenSistem os = OperativenSistem(ime, verzija, (Tip)tip, golemina);
  977. repozitorium.dodadi(os);
  978. }
  979.  
  980. repozitorium.pecatiOperativniSistemi();
  981. cin>>ime;
  982. cin>>verzija;
  983. cin>>tip;
  984. cin>>golemina;
  985. OperativenSistem os = OperativenSistem(ime, verzija, (Tip)tip, golemina);
  986. cout<<"=====Brishenje na operativen sistem====="<<endl;
  987. repozitorium.izbrishi(os);
  988. repozitorium.pecatiOperativniSistemi();
  989. return 0;
  990. }
  991. 5.SLADOLED
  992. #include <iostream>
  993. #include <cstring>
  994. using namespace std;
  995.  
  996. class IceCream {
  997. private:
  998. char *name;
  999. char ingredients[100];
  1000. float price;
  1001. int discount;
  1002. void copy(const IceCream &ic) {
  1003. name = new char[strlen(ic.name) + 1];
  1004. strcpy(name, ic.name);
  1005. strncpy(ingredients, ic.ingredients, 99);
  1006. ingredients[99] = '\0';
  1007. price = ic.price;
  1008. discount = ic.discount;
  1009. }
  1010. public:
  1011. IceCream(const char *nm = "", const char *ingr = "", float p = 0) {
  1012. name = new char[strlen(nm) + 1];
  1013. strcpy(name, nm);
  1014. strncpy(ingredients, ingr, 99);
  1015. ingredients[99] = '\0';
  1016. price = p;
  1017. discount = 0;
  1018. }
  1019.  
  1020. IceCream(const IceCream &ic) {
  1021. copy(ic);
  1022. }
  1023.  
  1024. IceCream& operator=(const IceCream &ic) {
  1025. if (this == &ic) return *this;
  1026. delete [] name;
  1027. copy(ic);
  1028. return *this;
  1029. }
  1030.  
  1031. friend ostream& operator<<(ostream &out, const IceCream &ic) {
  1032. out << ic.name << ": ";
  1033. out << ic.ingredients << " ";
  1034. out << ic.price << " ";
  1035. if (ic.discount > 0) {
  1036. out << "(" << ic.price * (100 - ic.discount) / 100 << ")";
  1037. }
  1038. return out;
  1039. }
  1040. void setName(char *n) {
  1041. delete [] name;
  1042. name = new char[strlen(n) + 1];
  1043. strcpy(name, n);
  1044. }
  1045.  
  1046. IceCream& operator++() {
  1047. discount += 5;
  1048. return *this;
  1049. }
  1050.  
  1051. IceCream operator+(const char* extra) {
  1052.  
  1053. char* newName = new char[strlen(name) + strlen(extra) + 4];
  1054. strcat(newName, name);
  1055. strcat(newName, " + ");
  1056. strcat(newName, extra);
  1057.  
  1058. IceCream res(newName, ingredients, price + 10);
  1059. res.setDiscount(discount);
  1060. return res;
  1061. }
  1062.  
  1063. void setName(const char* n) {
  1064. delete [] name;
  1065. name = new char[strlen(n) + 1];
  1066. strcpy(name, n);
  1067. }
  1068.  
  1069. void setDiscount(int d) {
  1070.  
  1071. if(d>=0&&d<=100)
  1072. discount = d;
  1073. }
  1074.  
  1075. ~IceCream() {
  1076. delete [] name;
  1077. }
  1078. };
  1079.  
  1080. class IceCreamShop {
  1081. private:
  1082. char name[50];
  1083. IceCream *icecreams;
  1084. int n;
  1085. void copy(const IceCreamShop &ics) {
  1086. strcpy(name, ics.name);
  1087. n = ics.n;
  1088. icecreams = new IceCream[n];
  1089. for (int i = 0; i < n; ++i) {
  1090. icecreams[i] = ics.icecreams[i];
  1091. }
  1092. }
  1093. public:
  1094. IceCreamShop(char* nm) {
  1095. strcpy(name, nm);
  1096. icecreams = NULL;
  1097. n = 0;
  1098. }
  1099. IceCreamShop(const IceCreamShop &ics) {
  1100. copy(ics);
  1101. }
  1102. IceCreamShop& operator=(const IceCreamShop &ics) {
  1103. if (this == &ics) return *this;
  1104. delete [] icecreams;
  1105. copy(ics);
  1106. return *this;
  1107. }
  1108. ~IceCreamShop() {
  1109. delete [] icecreams;
  1110. }
  1111.  
  1112. IceCreamShop& operator+= (IceCream &ic) {
  1113. IceCream *tmp = icecreams;
  1114. icecreams = new IceCream[n + 1];
  1115. for (int i = 0; i < n; ++i) {
  1116. icecreams[i] = tmp[i];
  1117. }
  1118. icecreams[n] = ic;
  1119. ++n;
  1120. delete [] tmp;
  1121. return *this;
  1122. }
  1123.  
  1124. friend ostream& operator<<(ostream &out, const IceCreamShop &ics) {
  1125. cout << ics.name << endl;
  1126. for (int i = 0; i < ics.n; ++i) {
  1127. out << ics.icecreams[i] << endl;
  1128. }
  1129. return out;
  1130. }
  1131.  
  1132. };
  1133.  
  1134. int main() {
  1135. char name[100];
  1136. char ingr[100];
  1137. float price;
  1138. int discount;
  1139.  
  1140. int testCase;
  1141.  
  1142. cin >> testCase;
  1143. cin.get();
  1144. if(testCase == 1) {
  1145. cout << "====== TESTING IceCream CLASS ======" << endl;
  1146. cin.getline(name,100);
  1147. cin.getline(ingr,100);
  1148. cin >> price;
  1149. cin >> discount;
  1150. cout << "CONSTRUCTOR" << endl;
  1151. IceCream ic1(name, ingr, price);
  1152. ic1.setDiscount(discount);
  1153. cin.get();
  1154. cin.getline(name,100);
  1155. cin.getline(ingr,100);
  1156. cin >> price;
  1157. cin >> discount;
  1158. IceCream ic2(name, ingr, price);
  1159. ic2.setDiscount(discount);
  1160. cout << "OPERATOR <<" << endl;
  1161. cout << ic1 << endl;
  1162. cout << ic2 << endl;
  1163. cout << "OPERATOR ++" << endl;
  1164. ++ic1;
  1165. cout << ic1 << endl;
  1166. cout << "OPERATOR +" << endl;
  1167. IceCream ic3 = ic2 + "chocolate";
  1168. cout << ic3 << endl;
  1169. } else if(testCase == 2) {
  1170. cout << "====== TESTING IceCream CONSTRUCTORS ======" << endl;
  1171. cin.getline(name,100);
  1172. cin.getline(ingr,100);
  1173. cin >> price;
  1174. //cin >> discount;
  1175. cout << "CONSTRUCTOR" << endl;
  1176. IceCream ic1(name, ingr, price);
  1177. cout << ic1 << endl;
  1178. cout << "COPY CONSTRUCTOR" << endl;
  1179. IceCream ic2(ic1);
  1180. cin.get();
  1181. cin.getline(name,100);
  1182. ic2.setName(name);
  1183. cout << ic1 << endl;
  1184. cout << ic2 << endl;
  1185. cout << "OPERATOR =" << endl;
  1186. ic1 = ic2;
  1187. cin.getline(name,100);
  1188. ic2.setName(name);
  1189. cout << ic1 << endl;
  1190. cout << ic2 << endl;
  1191.  
  1192. cin >> discount;
  1193. ic1.setDiscount(discount);
  1194.  
  1195.  
  1196. } else if(testCase == 3) {
  1197. cout << "====== TESTING IceCreamShop ======" << endl;
  1198. char icsName[50];
  1199. cin.getline(icsName,100);
  1200. cout << "CONSTRUCTOR" << endl;
  1201. IceCreamShop ics(icsName);
  1202. int n;
  1203. cin >> n;
  1204. cout << "OPERATOR +=" << endl;
  1205. for(int i = 0; i < n; ++i) {
  1206. cin.get();
  1207. cin.getline(name,100);
  1208. cin.getline(ingr,100);
  1209. cin >> price;
  1210. IceCream ic(name, ingr, price);
  1211. ics += ic;
  1212. }
  1213. cout << ics;
  1214. } else if(testCase == 4) {
  1215. cout << "====== TESTING IceCreamShop CONSTRUCTORS ======" << endl;
  1216. char icsName[50];
  1217. cin.getline(icsName,100);
  1218. IceCreamShop ics(icsName);
  1219. int n;
  1220. cin >> n;
  1221. for(int i = 0; i < n; ++i) {
  1222. cin.get();
  1223. cin.getline(name,100);
  1224. cin.getline(ingr,100);
  1225. cin >> price;
  1226. IceCream ic(name, ingr, price);
  1227. ics += ic;
  1228. }
  1229. IceCream x("FINKI fruits", "strawberry ice cream, raspberry ice cream, blueberry ice cream", 60);
  1230. IceCreamShop icp = ics;
  1231. ics+=x;
  1232. cout << ics << endl;
  1233. cout << icp << endl;
  1234. }
  1235.  
  1236.  
  1237. return 0;
  1238. }
  1239.  
  1240. //STARTER
  1241. /*#include <iostream>
  1242. #include <cstring>
  1243. using namespace std;
  1244.  
  1245.  
  1246. // vashiot kod ovde
  1247.  
  1248. // zabraneto e menuvanje na main funkcijata
  1249.  
  1250. int main() {
  1251. char name[100];
  1252. char ingr[100];
  1253. float price;
  1254. int discount;
  1255.  
  1256. int testCase;
  1257.  
  1258. cin >> testCase;
  1259. cin.get();
  1260. if(testCase == 1) {
  1261. cout << "====== TESTING IceCream CLASS ======" << endl;
  1262. cin.getline(name,100);
  1263. cin.getline(ingr,100);
  1264. cin >> price;
  1265. cin >> discount;
  1266. cout << "CONSTRUCTOR" << endl;
  1267. IceCream ic1(name, ingr, price);
  1268. ic1.setDiscount(discount);
  1269. cin.get();
  1270. cin.getline(name,100);
  1271. cin.getline(ingr,100);
  1272. cin >> price;
  1273. cin >> discount;
  1274. IceCream ic2(name, ingr, price);
  1275. ic2.setDiscount(discount);
  1276. cout << "OPERATOR <<" << endl;
  1277. cout << ic1 << endl;
  1278. cout << ic2 << endl;
  1279. cout << "OPERATOR ++" << endl;
  1280. ++ic1;
  1281. cout << ic1 << endl;
  1282. cout << "OPERATOR +" << endl;
  1283. IceCream ic3 = ic2 + "chocolate";
  1284. cout << ic3 << endl;
  1285. } else if(testCase == 2) {
  1286. cout << "====== TESTING IceCream CONSTRUCTORS ======" << endl;
  1287. cin.getline(name,100);
  1288. cin.getline(ingr,100);
  1289. cin >> price;
  1290. cout << "CONSTRUCTOR" << endl;
  1291. IceCream ic1(name, ingr, price);
  1292. cout << ic1 << endl;
  1293. cout << "COPY CONSTRUCTOR" << endl;
  1294. IceCream ic2(ic1);
  1295. cin.get();
  1296. cin.getline(name,100);
  1297. ic2.setName(name);
  1298. cout << ic1 << endl;
  1299. cout << ic2 << endl;
  1300. cout << "OPERATOR =" << endl;
  1301. ic1 = ic2;
  1302. cin.getline(name,100);
  1303. ic2.setName(name);
  1304. cout << ic1 << endl;
  1305. cout << ic2 << endl;
  1306.  
  1307. cin >> discount;
  1308. ic1.setDiscount(discount);
  1309.  
  1310.  
  1311. } else if(testCase == 3) {
  1312. cout << "====== TESTING IceCreamShop ======" << endl;
  1313. char icsName[50];
  1314. cin.getline(icsName,100);
  1315. cout << "CONSTRUCTOR" << endl;
  1316. IceCreamShop ics(icsName);
  1317. int n;
  1318. cin >> n;
  1319. cout << "OPERATOR +=" << endl;
  1320. for(int i = 0; i < n; ++i) {
  1321. cin.get();
  1322. cin.getline(name,100);
  1323. cin.getline(ingr,100);
  1324. cin >> price;
  1325. IceCream ic(name, ingr, price);
  1326. ics += ic;
  1327. }
  1328. cout << ics;
  1329. } else if(testCase == 4) {
  1330. cout << "====== TESTING IceCreamShop CONSTRUCTORS ======" << endl;
  1331. char icsName[50];
  1332. cin.getline(icsName,100);
  1333. IceCreamShop ics(icsName);
  1334. int n;
  1335. cin >> n;
  1336. for(int i = 0; i < n; ++i) {
  1337. cin.get();
  1338. cin.getline(name,100);
  1339. cin.getline(ingr,100);
  1340. cin >> price;
  1341. IceCream ic(name, ingr, price);
  1342. ics += ic;
  1343. }
  1344. IceCream x("FINKI fruits", "strawberry ice cream, raspberry ice cream, blueberry ice cream", 60);
  1345. IceCreamShop icp = ics;
  1346. ics+=x;
  1347. cout << ics << endl;
  1348. cout << icp << endl;
  1349. }
  1350.  
  1351.  
  1352. return 0;
  1353. }
  1354. */
  1355. 6.PLANINARSKI DOM
  1356. #include<iostream>
  1357. #include<string.h>
  1358.  
  1359. using namespace std;
  1360. class Zichara
  1361. {
  1362. private:
  1363. char *mesto;
  1364. int cena;
  1365. public:
  1366. Zichara()
  1367. {
  1368. mesto = new char[0];
  1369. }
  1370. Zichara(char mesto[],int cena)
  1371. {
  1372. this->mesto = new char[strlen(mesto)+1];
  1373. strcpy(this->mesto,mesto);
  1374. this->cena = cena;
  1375. }
  1376. Zichara(const Zichara &z)
  1377. {
  1378. this->mesto = new char[strlen(z.mesto)+1];
  1379. strcpy(this->mesto,z.mesto);
  1380. this->cena = z.cena;
  1381. }
  1382. Zichara& operator=(const Zichara &z)
  1383. {
  1384. if(this!=&z)
  1385. {
  1386. delete []mesto;
  1387. this->mesto = new char[strlen(z.mesto)+1];
  1388. strcpy(this->mesto,z.mesto);
  1389. this->cena = z.cena;
  1390. }
  1391. return *this;
  1392. }
  1393. int getCenaZichara()
  1394. {
  1395. return cena;
  1396. }
  1397. ~Zichara()
  1398. {
  1399. delete []mesto;
  1400. }
  1401.  
  1402. };
  1403. class PlaninarskiDom
  1404. {
  1405. private:
  1406. char ime[16];
  1407. int ceniSezoni[2];
  1408. char klasa;
  1409. bool daliZichara;
  1410. Zichara *z;
  1411. public:
  1412. PlaninarskiDom()
  1413. {
  1414. daliZichara =false;
  1415. z = NULL;
  1416. }
  1417. PlaninarskiDom(char ime[],int ceniSezoni[],char klasa)
  1418. {
  1419. strcpy(this->ime,ime);
  1420. for(int i=0;i<2;i++)
  1421. {
  1422. this->ceniSezoni[i] = ceniSezoni[i];
  1423. }
  1424. this->klasa = klasa;
  1425. daliZichara =false;
  1426. z = NULL;
  1427. }
  1428. PlaninarskiDom& operator--()
  1429. {
  1430. if(klasa<'F')
  1431. {
  1432. ++klasa;
  1433. }
  1434. return *this;
  1435. }
  1436. void setZichara(Zichara &zi)
  1437. {
  1438. this->z = &zi;
  1439. daliZichara=true;
  1440. }
  1441. friend ostream& operator<<(ostream &out, const PlaninarskiDom &p)
  1442. {
  1443. out<<p.ime<<" klasa:"<<p.klasa;
  1444. if(p.daliZichara)//if(p.daliZichara!=0) - isto
  1445. out<<" so Zichara"<<endl;
  1446. else
  1447. out<<endl;
  1448. return out;
  1449. }
  1450. bool operator<=(char znak)
  1451. {
  1452. return klasa >= znak;
  1453. }
  1454.  
  1455.  
  1456. void presmetajDnevenPrestoj(int den,int mesec,int &cena)
  1457. {
  1458. cena =0;
  1459. if(den<1 || den>31 || mesec<1 || mesec>12)
  1460. throw 1;
  1461.  
  1462. if(mesec>=4&&mesec<=8)
  1463. {
  1464. cena = cena + ceniSezoni[0];
  1465.  
  1466. }
  1467. else
  1468. {
  1469. cena = cena + ceniSezoni[1];
  1470. }
  1471. if(daliZichara)
  1472. cena = cena + z->getCenaZichara();
  1473. }
  1474. ~PlaninarskiDom(){}
  1475. };
  1476.  
  1477. int main(){
  1478.  
  1479. PlaninarskiDom p; //креирање на нов објект од класата планинарски дом
  1480.  
  1481. //во следниот дел се вчитуваат информации за планинарскиот дом
  1482. char imePlaninarskiDom[15],mestoZichara[30],klasa;
  1483. int ceni[12];
  1484. int dnevnakartaZichara;
  1485. bool daliZichara;
  1486. cin>>imePlaninarskiDom;
  1487. for (int i=0;i<2;i++) cin>>ceni[i];
  1488. cin>>klasa;
  1489. cin>>daliZichara;
  1490.  
  1491. //во следниот дел се внесуваат информации и за жичарата ако постои
  1492. if (daliZichara) {
  1493. cin>>mestoZichara>>dnevnakartaZichara;
  1494. PlaninarskiDom pom(imePlaninarskiDom,ceni,klasa);
  1495. Zichara r(mestoZichara,dnevnakartaZichara);
  1496. pom.setZichara(r);
  1497. p=pom;
  1498. }
  1499. else{
  1500. PlaninarskiDom *pok=new PlaninarskiDom(imePlaninarskiDom,ceni,klasa);
  1501. p=*pok;
  1502. }
  1503.  
  1504. //се намалува класата на планинарскиот дом за 2
  1505. --p;
  1506. --p;
  1507.  
  1508. int cena;
  1509. int den,mesec;
  1510. cin>>den>>mesec;
  1511. try{
  1512. p.presmetajDnevenPrestoj(den,mesec,cena); //тука се користи функцијата presmetajDnevenPrestoj
  1513. cout<<"Informacii za PlaninarskiDomot:"<<endl;
  1514. cout<<p;
  1515. if (p<='D')
  1516. cout<<"Planinarskiot dom za koj se vneseni informaciite ima klasa poniska ili ista so D\n";
  1517.  
  1518. cout<<"Cenata za "<<den<<"."<<mesec<<" e "<<cena; //се печати цената за дадениот ден и месец
  1519. }
  1520. catch (int){
  1521. cout<<"Mesecot ili denot e greshno vnesen!";
  1522. }
  1523. }
  1524. 6.PODATOCEN SISTEM
  1525. #include<iostream>
  1526. #include<cstring>
  1527.  
  1528. using namespace std;
  1529.  
  1530. enum Tip{pdf,txt,exe};
  1531.  
  1532. class File{
  1533. char *ime;
  1534. Tip tip;
  1535. char *sopstvenik;
  1536. int golemina;
  1537. public:
  1538. //File();
  1539. File(const char *ime=" ", const char *sopstvenik=" ", int golemina=0 ,Tip tip=txt)
  1540. {
  1541. this->ime= new char [strlen(ime)+1];
  1542. strcpy(this->ime,ime);
  1543. this->sopstvenik= new char [strlen(sopstvenik)+1];
  1544. strcpy(this->sopstvenik,sopstvenik);
  1545. this->tip=tip;
  1546. this->golemina=golemina;
  1547.  
  1548.  
  1549.  
  1550. }
  1551. File (const File &f)
  1552. {
  1553. this->ime= new char [strlen(f.ime)+1];
  1554. strcpy(this->ime,f.ime);
  1555. this->sopstvenik= new char [strlen(f.sopstvenik)+1];
  1556. strcpy(this->sopstvenik,f.sopstvenik);
  1557. this->tip=f.tip;
  1558. this->golemina=f.golemina;
  1559.  
  1560.  
  1561.  
  1562. }
  1563. File &operator= (const File &q)
  1564. {
  1565. if(this!=&q)
  1566. {
  1567. delete [] ime;
  1568. delete [] sopstvenik;
  1569. this->ime= new char [strlen(q.ime)+1];
  1570. strcpy(this->ime,q.ime);
  1571. this->sopstvenik= new char [strlen(q.sopstvenik)+1];
  1572. strcpy(this->sopstvenik,q.sopstvenik);
  1573. this->tip=q.tip;
  1574. this->golemina=q.golemina;
  1575.  
  1576.  
  1577.  
  1578.  
  1579. }
  1580. return *this;
  1581.  
  1582.  
  1583. }
  1584. ~File(){ delete [] ime; delete [] sopstvenik;}
  1585. void print()
  1586. {
  1587.  
  1588. cout<<"File name: "<<ime;
  1589. if(tip==0)
  1590. cout<<"."<<"pdf"<<endl;
  1591. else
  1592. {
  1593. if(tip==1)
  1594. cout<<"."<<"txt"<<endl;
  1595. else
  1596. cout<<"."<<"exe"<<endl;
  1597.  
  1598. }
  1599. cout<<"File owner: "<<sopstvenik<<endl<<"File size: "<<golemina<<endl;
  1600.  
  1601. }
  1602. bool equals(const File & that)
  1603. {
  1604. if(((strcmp(ime,that.ime))==0)&&(tip==that.tip)&&(strcmp(sopstvenik,that.sopstvenik)==0))
  1605. return true;
  1606. else
  1607. return false;
  1608.  
  1609.  
  1610. }
  1611. bool equalsType(const File & that)
  1612. {
  1613. if(tip==that.tip)
  1614. {
  1615. return true;
  1616.  
  1617. }
  1618. else
  1619. return false;
  1620.  
  1621.  
  1622. }
  1623.  
  1624. };
  1625. class Folder
  1626. {
  1627. char *ime;
  1628. int broj;
  1629. File *files;
  1630. public:
  1631. Folder (char *ime)
  1632. { this->ime= new char [strlen(ime)+1];
  1633. strcpy(this->ime,ime);
  1634. this->broj=0;
  1635. this->files= new File [broj];
  1636.  
  1637. }
  1638. Folder (const Folder &f)
  1639. {
  1640. this->ime= new char [strlen(f.ime)+1];
  1641. strcpy(this->ime,f.ime);
  1642. this->broj=f.broj;
  1643. this->files= new File [broj];
  1644. for(int i=0;i<broj;i++)
  1645. {
  1646. this->files[i]=files[i];
  1647.  
  1648. }
  1649.  
  1650. }
  1651.  
  1652. Folder operator= ( const Folder &f)
  1653. {
  1654. if(this!=&f)
  1655. {
  1656. delete [] ime; delete [] files;
  1657. this->ime= new char [strlen(f.ime)+1];
  1658. strcpy(this->ime,f.ime);
  1659. this->broj=f.broj;
  1660. this->files= new File [broj];
  1661. for(int i=0;i<broj;i++)
  1662. {
  1663. this->files[i]=files[i];
  1664.  
  1665. }
  1666.  
  1667.  
  1668.  
  1669.  
  1670. }
  1671.  
  1672. return *this;
  1673.  
  1674. }
  1675.  
  1676. void print()
  1677. {
  1678. cout<<"Folder name: "<<ime<<endl;
  1679. for (int i=0;i<broj;i++)
  1680. {
  1681.  
  1682. files[i].print();
  1683.  
  1684. }
  1685.  
  1686.  
  1687. }
  1688. void add(const File & file)
  1689. {
  1690.  
  1691.  
  1692. File *tmp= new File [broj+1];
  1693. for(int i=0; i<broj; i++) {
  1694. tmp[i]=files[i];
  1695. }
  1696. tmp[broj++]=file;
  1697. delete [] files;
  1698. files=tmp;
  1699. }
  1700.  
  1701.  
  1702. void remove(const File & ff){
  1703.  
  1704. int count=0;
  1705. for(int i=0; i<broj; i++) {
  1706. if(!(files[i].equals(ff))) {
  1707.  
  1708. count++;
  1709.  
  1710. }
  1711.  
  1712.  
  1713. }
  1714. File *tmp = new File[count];
  1715. count=0;
  1716. for(int i=0; i<broj; i++) {
  1717. if(!(files[i].equals(ff))) {
  1718. tmp[count++]=files[i];
  1719.  
  1720. }
  1721.  
  1722.  
  1723. }
  1724.  
  1725. delete [] files;
  1726. files=tmp;
  1727. broj=count;
  1728.  
  1729.  
  1730.  
  1731.  
  1732. }
  1733.  
  1734. };
  1735. int main() {
  1736. char fileName[20];
  1737. char fileOwner[20];
  1738. int ext;
  1739. int fileSize;
  1740.  
  1741. int testCase;
  1742. cin >> testCase;
  1743. if (testCase == 1) {
  1744. cout << "======= FILE CONSTRUCTORS AND = OPERATOR =======" << endl;
  1745. cin >> fileName;
  1746. cin >> fileOwner;
  1747. cin >> fileSize;
  1748. cin >> ext;
  1749.  
  1750. File created = File(fileName, fileOwner, fileSize, (Tip) ext);
  1751. File copied = File(created);
  1752. File assigned = created;
  1753.  
  1754. cout << "======= CREATED =======" << endl;
  1755. created.print();
  1756. cout << endl;
  1757. cout << "======= COPIED =======" << endl;
  1758. copied.print();
  1759. cout << endl;
  1760. cout << "======= ASSIGNED =======" << endl;
  1761. assigned.print();
  1762. }
  1763. else if (testCase == 2) {
  1764. cout << "======= FILE EQUALS & EQUALS TYPE =======" << endl;
  1765. cin >> fileName;
  1766. cin >> fileOwner;
  1767. cin >> fileSize;
  1768. cin >> ext;
  1769.  
  1770. File first(fileName, fileOwner, fileSize, (Tip) ext);
  1771. first.print();
  1772.  
  1773. cin >> fileName;
  1774. cin >> fileOwner;
  1775. cin >> fileSize;
  1776. cin >> ext;
  1777.  
  1778. File second(fileName, fileOwner, fileSize, (Tip) ext);
  1779. second.print();
  1780.  
  1781. cin >> fileName;
  1782. cin >> fileOwner;
  1783. cin >> fileSize;
  1784. cin >> ext;
  1785.  
  1786. File third(fileName, fileOwner, fileSize, (Tip) ext);
  1787. third.print();
  1788.  
  1789. bool equals = first.equals(second);
  1790. cout << "FIRST EQUALS SECOND: ";
  1791. if (equals)
  1792. cout << "TRUE" << endl;
  1793. else
  1794. cout << "FALSE" << endl;
  1795.  
  1796. equals = first.equals(third);
  1797. cout << "FIRST EQUALS THIRD: ";
  1798. if (equals)
  1799. cout << "TRUE" << endl;
  1800. else
  1801. cout << "FALSE" << endl;
  1802.  
  1803. bool equalsType = first.equalsType(second);
  1804. cout << "FIRST EQUALS TYPE SECOND: ";
  1805. if (equalsType)
  1806. cout << "TRUE" << endl;
  1807. else
  1808. cout << "FALSE" << endl;
  1809.  
  1810. equalsType = second.equals(third);
  1811. cout << "SECOND EQUALS TYPE THIRD: ";
  1812. if (equalsType)
  1813. cout << "TRUE" << endl;
  1814. else
  1815. cout << "FALSE" << endl;
  1816.  
  1817. }
  1818. else if (testCase == 3) {
  1819. cout << "======= FOLDER CONSTRUCTOR =======" << endl;
  1820. cin >> fileName;
  1821. Folder folder(fileName);
  1822. folder.print();
  1823.  
  1824. }
  1825. else if (testCase == 4) {
  1826. cout << "======= ADD FILE IN FOLDER =======" << endl;
  1827. char name[20];
  1828. cin >> name;
  1829. Folder folder(name);
  1830.  
  1831. int iter;
  1832. cin >> iter;
  1833.  
  1834. while (iter > 0) {
  1835. cin >> fileName;
  1836. cin >> fileOwner;
  1837. cin >> fileSize;
  1838. cin >> ext;
  1839.  
  1840. File file(fileName, fileOwner, fileSize, (Tip) ext);
  1841. folder.add(file);
  1842. iter--;
  1843. }
  1844. folder.print();
  1845. }
  1846. else {
  1847. cout << "======= REMOVE FILE FROM FOLDER =======" << endl;
  1848. char name[20];
  1849. cin >> name;
  1850. Folder folder(name);
  1851.  
  1852. int iter;
  1853. cin >> iter;
  1854.  
  1855. while (iter > 0) {
  1856. cin >> fileName;
  1857. cin >> fileOwner;
  1858. cin >> fileSize;
  1859. cin >> ext;
  1860.  
  1861. File file(fileName, fileOwner, fileSize, (Tip) ext);
  1862. folder.add(file);
  1863. iter--;
  1864. }
  1865. cin >> fileName;
  1866. cin >> fileOwner;
  1867. cin >> fileSize;
  1868. cin >> ext;
  1869.  
  1870. File file(fileName, fileOwner, fileSize, (Tip) ext);
  1871. folder.remove(file);
  1872. folder.print();
  1873. }
  1874. return 0;
  1875. }
  1876. 7.FAKTURA
  1877. #include <stdio.h>
  1878. #include <string.h>
  1879. #include <stdio.h>
  1880. #include <string.h>
  1881. typedef struct Proizvod {
  1882. char kod[20];
  1883. int cena;
  1884. int lager;
  1885. } Proizvod;
  1886.  
  1887. typedef struct Narachka {
  1888. char ime[15];
  1889. Proizvod proizvodi[10];
  1890. int narProizvodi[10];
  1891. int n;
  1892. } Narachka;
  1893.  
  1894. void pecatiFaktura(Narachka n) {
  1895. printf("Faktura za %s\n",n.ime);
  1896. int i,flag=0,j;
  1897. Proizvod temp;
  1898. for(i=0; i<n.n; i++) {
  1899. if(n.proizvodi[i].lager-n.narProizvodi[i]<0)
  1900. flag = 1;
  1901. }
  1902. if(flag)
  1903. printf("Fakturata ne moze da se izgotvi");
  1904. else {
  1905. for(i=0; i < n.n-1; i++) {
  1906. for(j=i+1; j< n.n; j++) {
  1907. if(strcmp(n.proizvodi[i].kod,n.proizvodi[j].kod )> 0) {
  1908. temp=n.proizvodi[i];
  1909. n.proizvodi[i]=n.proizvodi[j];
  1910. n.proizvodi[j]=temp;
  1911. }
  1912. }
  1913. }
  1914. int s=0;
  1915. for(i=0; i<n.n; i++) {
  1916. printf("%s %d %d %d\n",n.proizvodi[i].kod,n.proizvodi[i].cena,n.narProizvodi[i],n.proizvodi[i].cena*n.narProizvodi[i]);
  1917. s+=n.proizvodi[i].cena*n.narProizvodi[i];
  1918. }
  1919. printf("Vkupnata suma na fakturata e %d",s);
  1920. }
  1921. }
  1922. int main() {
  1923. char ime[15],kod[20];
  1924. int cena,lager,n,i,j;
  1925. Narachka narachka;
  1926. Proizvod proizvodi[30];
  1927. scanf("%s",narachka.ime);
  1928. scanf("%d",&narachka.n);
  1929. for (i = 0; i < narachka.n; ++i) {
  1930. scanf("%s",proizvodi[i].kod);
  1931. scanf("%d",&proizvodi[i].cena);
  1932. scanf("%d",&proizvodi[i].lager);
  1933. narachka.proizvodi[i]=proizvodi[i];
  1934. }
  1935. for (j = 0; j < narachka.n; ++j) {
  1936. scanf("%d",&narachka.narProizvodi[j]);
  1937. }
  1938. pecatiFaktura(narachka);
  1939. return 0;
  1940. }
  1941. //место за вашиот код
  1942.  
  1943. /*int main() {
  1944.  
  1945. Narachka narachka;
  1946.  
  1947. // внеси го името лицето кое ја прави нарачката
  1948. // внеси го бројот на порачани производи во нарачката
  1949.  
  1950. int i;
  1951. //за секој од нарачаните производи се внесуваат информации
  1952. for (i = 0; i < narachka.n; ++i) {
  1953. // внеси код
  1954. // внеси единицчна цена
  1955. // внеси број на производи во магацин
  1956. }
  1957. //за секој производ се внесува колку такви производи се порачани во нарачката
  1958. int j;
  1959. for (j = 0; j < narachka.n; ++j) {
  1960. //се внесува број на производи во нарачката
  1961. }
  1962.  
  1963.  
  1964. // повик на функцијата pecatiFaktura
  1965.  
  1966.  
  1967. return 0;
  1968. }*/
  1969. 8.VOZ(TOCNA E SAMO FALAT PRAZNI MESTA U PECATENJETO)
  1970. #include<iostream>
  1971. #include<cstring>
  1972. using namespace std;
  1973.  
  1974. class Patnik //od nego se pravi niza
  1975. {
  1976.  
  1977. public: //namerno se public so ogled na toa shto tupa zadacha dale
  1978. char ime[100];
  1979. int klasa;
  1980. bool velosiped;
  1981.  
  1982. Patnik() {}
  1983. Patnik(char *ime,int kl,bool v)
  1984. {
  1985. strcpy(this->ime,ime); //KOGA IMATE ISTI IMINJA: THIS->
  1986. klasa = kl;
  1987. velosiped = v;
  1988. }
  1989.  
  1990. // кај динамичка алокација секогаш мора да се оптовари доделувањето
  1991. // copy конструкторот да се напише и деструктор , сите три работи!
  1992. //copy-konstruktor:
  1993. Patnik ( const Patnik &p)
  1994. {
  1995. strcpy(ime, p.ime);
  1996. klasa=p.klasa;
  1997. velosiped=p.velosiped;
  1998. }
  1999.  
  2000. Patnik &operator =( const Patnik &p)
  2001. {
  2002. if(this!=&p)
  2003. {
  2004. strcpy(ime, p.ime);
  2005. klasa=p.klasa;
  2006. velosiped=p.velosiped;
  2007. }
  2008. return *this;
  2009. }
  2010.  
  2011.  
  2012.  
  2013. friend ostream &operator <<(ostream &o, Patnik &p)
  2014. {
  2015. o << p.ime<< endl;
  2016. o << p.klasa <<endl;
  2017. o << p.velosiped << endl;
  2018. return o;
  2019. }
  2020. ~Patnik() {}
  2021. };
  2022.  
  2023. class Voz
  2024. {
  2025.  
  2026. private:
  2027. char krajnaDestinacija[100];
  2028. Patnik *p;
  2029. int brElemeni;
  2030. int brVelosipedi;
  2031. public:
  2032. Voz(char *kD="",int brV=0,Patnik *niza=0,int brEl=0 )//DIREKTNA INICIJALIZACIJA FALESHE + dopuna
  2033. {
  2034. strcpy(krajnaDestinacija,kD);
  2035. brVelosipedi = brV; //vtoriot argument e max broj na velosipedi
  2036. brElemeni = brEl;
  2037. p = new Patnik[brElemeni];
  2038. for (int i = 0; i<brElemeni; i++)
  2039. p[i] = niza[i];
  2040. }
  2041.  
  2042. Voz(const Voz &v)
  2043. {
  2044. strcpy(krajnaDestinacija,v.krajnaDestinacija);
  2045. this->brElemeni=v.brElemeni;
  2046. this->brVelosipedi=v.brVelosipedi;
  2047. this->p = new Patnik [brElemeni];
  2048. for (int i = 0; i<brElemeni; i++)
  2049. p[i] =v.p[i];
  2050. }
  2051.  
  2052. Voz &operator =(const Voz &v)
  2053. {
  2054. if(this!=&v)
  2055. {
  2056. delete [] p;
  2057. brElemeni = v.brElemeni;
  2058. for(int i=0; i < brElemeni; i++)
  2059. {
  2060. p[i]=v.p[i];
  2061. }
  2062. p= new Patnik[brElemeni];
  2063. strcpy(krajnaDestinacija,v.krajnaDestinacija);
  2064. brVelosipedi = v.brVelosipedi;
  2065. }
  2066. return *this;
  2067. }
  2068.  
  2069. Voz &operator += (Patnik x) // se dodava objekt Patnik vo objekt Voz
  2070. {
  2071. Patnik * pomNiza = new Patnik [brElemeni + 1 ];
  2072. if(brElemeni == 0){ // ova e za ПРВИОТ objekt Patnik
  2073. //za da raboti dodeluvanjeto mora da se optovari = kaj patnik!
  2074. pomNiza[brElemeni++] = x;
  2075. delete[]p;
  2076. p=pomNiza;
  2077. return * this;
  2078.  
  2079. }
  2080. else { // ОВА Е ЗА СИТЕ НАРЕДНИ
  2081. for (int i = 0; i<brElemeni; i++)
  2082. //za da raboti dodeluvanjeto mora da se optovari = kaj patnik!
  2083. pomNiza[i] = p[i];
  2084. pomNiza[brElemeni++] = x;
  2085. delete[]p;
  2086. p=pomNiza;
  2087. return * this ;
  2088. }
  2089. }
  2090.  
  2091. friend ostream &operator <<(ostream &o, const Voz &v)// ФАЛЕШЕ const
  2092. {
  2093. o << v.krajnaDestinacija<<endl;
  2094. for(int i = 0; i < v.brElemeni; i++)
  2095. {
  2096. o << v.p[i];
  2097. }
  2098. return o;
  2099. }
  2100.  
  2101. void patniciNemaMesto() // samo pechatime , pa taka VOID vrshi rabota
  2102. {
  2103. int brPrva=0; //pomoshna brojach za prvaKlasa patnici
  2104. int brVtora=0; //pomoshna brojach za vtoraKlasa patnici
  2105. int kvota=0; //koga kje se napolni 10 pochnuvaat brojachite da brojat
  2106.  
  2107. /*koja e idejata, znachi od MAINOT gledate deka vkupno mesta za velosipedi se 10,
  2108. e sega, prvo smeat da vlezat velosipedisti od prva klasa, tie se so redni broevi:
  2109. ime, 1, 1. takvi gi ima 11 na broj, znachi eden ostanuva, mestata se napolneti i
  2110. site velosipedisto od vtora klasa : ime, 2, 1 . isto se nadvor a takvi se Mimi i Kiki
  2111. ajde sega i kodot*/
  2112.  
  2113. for(int i=0 ; i< brElemeni;i++){
  2114. if(p[i].klasa==1&&p[i].velosiped){
  2115. kvota++;
  2116. }
  2117. }
  2118. if(kvota>=10){
  2119. brPrva=kvota-10;
  2120. kvota=10; //da se dobie vishok na patnici od vtora klasa
  2121. }
  2122.  
  2123. //istoto i za vtoa klasa:
  2124. for(int i =0; i< brElemeni;i++){
  2125. if(p[i].klasa==2 && p[i].velosiped){
  2126. kvota++;
  2127. }
  2128. }
  2129. if(kvota>=10)
  2130. brVtora=kvota-10;
  2131.  
  2132. cout << "Brojot na patnici od 1-va klasa koi ostanale bez mesto e: "<<brPrva<<endl;
  2133. cout << "Brojot na patnici od 2-va klasa koi ostanale bez mesto e: "<<brVtora;
  2134. }
  2135.  
  2136.  
  2137. ~Voz()
  2138. {
  2139. delete [] p;
  2140. }
  2141. };
  2142.  
  2143.  
  2144.  
  2145. int main()
  2146. {
  2147. Patnik p;
  2148. char ime[100], destinacija[100];
  2149. int n;
  2150. bool velosiped;
  2151. int klasa;
  2152. int maxv;
  2153. cin >> destinacija >> maxv;
  2154. cin >> n;
  2155. Voz v(destinacija, maxv);
  2156. //cout<<v<<endl;
  2157. for (int i = 0; i < n; i++){
  2158. cin >> ime >> klasa >> velosiped;
  2159. Patnik p(ime, klasa, velosiped);
  2160. //cout<<p<<endl;
  2161. v += p;
  2162. }
  2163. cout << v<<endl;;
  2164. v.patniciNemaMesto();
  2165.  
  2166. return 0;
  2167. }
  2168. 10.RABOTNI CASOVI
  2169. #include <stdio.h>
  2170. #include <string.h>
  2171. #define NEDELI 4
  2172. #define DENOVI 5
  2173.  
  2174. // ovde strukturata RabotnaNedela
  2175. struct RabotnaNedela{
  2176. int broj;
  2177. int rabotniCasovi[5];
  2178.  
  2179. };
  2180.  
  2181. typedef struct RabotnaNedela RN;
  2182.  
  2183. // ovde strukturata Rabotnik
  2184. struct Rabotnik{
  2185. char ime[50];
  2186. RN nedeli[4];
  2187. };
  2188.  
  2189. typedef struct Rabotnik R;
  2190. int maxNedela(R *r)
  2191. {
  2192. int maxCasovi=0;
  2193. int maxNedela=0;
  2194. int i;
  2195. for(i=0;i<4;i++)
  2196. {
  2197. int casoviNedela=0;
  2198. int j=0;
  2199. for(j=0;j<5;j++)
  2200. {
  2201. casoviNedela+=r->nedeli[i].rabotniCasovi[j];
  2202. }
  2203. if (casoviNedela>maxCasovi)
  2204. {
  2205. maxCasovi=casoviNedela;
  2206. maxNedela=i;
  2207. }
  2208. }
  2209. return maxNedela+1;
  2210. }
  2211. void table(R *r, int n)
  2212. {
  2213. printf("Rab\t1\t2\t3\t4\tVkupno\n");
  2214. int i,j;
  2215. for(i=0;i<n;i++)
  2216. {
  2217.  
  2218. int vkupno=0;
  2219. printf("%s\t",r[i].ime);
  2220. for(j=0;j<4;j++)
  2221. {
  2222. int vkupnoCasovi=0;
  2223. int z=0;
  2224. for(z=0;z<5;z++)
  2225. {
  2226. vkupnoCasovi+=r[i].nedeli[j].rabotniCasovi[z];
  2227. }
  2228. printf("%d\t",vkupnoCasovi);
  2229. vkupno+=vkupnoCasovi;
  2230. }
  2231. printf("%d\n",vkupno);
  2232. }
  2233. }
  2234.  
  2235. // ovde funkciite
  2236.  
  2237.  
  2238. int main() {
  2239. int n;
  2240. scanf("%d", &n);
  2241. R rabotnici[n];
  2242. int i;
  2243. for (i = 0; i < n; ++i) {
  2244. scanf("%s", rabotnici[i].ime);
  2245. int j;
  2246. for (j = 0; j < NEDELI; ++j) {
  2247. int k;
  2248. for (k = 0; k < DENOVI; ++k) {
  2249. scanf("%d", &rabotnici[i].nedeli[j].rabotniCasovi[k]);
  2250. }
  2251.  
  2252. }
  2253. }
  2254. printf("TABLE\n");
  2255. table(rabotnici, n);
  2256. printf("MAX NEDELA NA RABOTNIK: %s\n", rabotnici[n / 2].ime);
  2257. printf("%d\n", maxNedela(&rabotnici[n/2]));
  2258. return 0;
  2259. }
  2260. 11.TANCERI
  2261. #include<iostream>
  2262. #include<cstring>
  2263. using namespace std;
  2264. struct Tanc {
  2265. char ime[15];
  2266. char zemja[15];
  2267.  
  2268.  
  2269.  
  2270.  
  2271. };
  2272. struct Tancer {
  2273. char ime[20];
  2274. char prezime[20];
  2275. Tanc niza[5];
  2276.  
  2277.  
  2278.  
  2279. };
  2280.  
  2281. void tancuvanje(Tancer *t, int n, char *zemja)
  2282. {
  2283. for(int i=0;i<n;i++)
  2284. {
  2285.  
  2286. for(int j=0;j<n;j++)
  2287. { if(strcmp(t[i].niza[j].zemja,zemja)==0)
  2288. {cout<<t[i].ime<<" "<<t[i].prezime<<", "<<t[i].niza[j].ime<<endl;
  2289. break;}
  2290.  
  2291. }
  2292.  
  2293. }
  2294.  
  2295.  
  2296.  
  2297. }
  2298.  
  2299. int main() {
  2300. int i, j, n;
  2301. char zemja[15];
  2302. Tancer tanceri[5];
  2303. cin >> n;
  2304. for(i = 0; i < n; i++) {
  2305. cin >> tanceri[i].ime;
  2306. cin >> tanceri[i].prezime;
  2307. for(j = 0; j < 3; j++) {
  2308. cin >> tanceri[i].niza[j].ime;
  2309. cin >> tanceri[i].niza[j].zemja;
  2310. }
  2311. }
  2312. cin >> zemja;
  2313. tancuvanje(tanceri, n, zemja);
  2314. return 0;
  2315. }
  2316. 12.RABOTNI CASOVI (40 POENA)
  2317. #include <stdio.h>
  2318. #include <string.h>
  2319. #define NEDELI 4
  2320. #define DENOVI 5
  2321.  
  2322. // ovde strukturata RabotnaNedela
  2323. struct RabotnaNedela{
  2324. int broj;
  2325. int rabotniCasovi[5];
  2326.  
  2327. };
  2328.  
  2329. typedef struct RabotnaNedela RN;
  2330.  
  2331. // ovde strukturata Rabotnik
  2332. struct Rabotnik{
  2333. char ime[50];
  2334. RN nedeli[4];
  2335. };
  2336.  
  2337. typedef struct Rabotnik R;
  2338. int maxNedela(R *r)
  2339. {
  2340. int maxCasovi=0;
  2341. int maxNedela=0;
  2342. int i;
  2343. for(i=0;i<4;i++)
  2344. {
  2345. int casoviNedela=0;
  2346. int j=0;
  2347. for(j=0;j<5;j++)
  2348. {
  2349. casoviNedela+=r->nedeli[i].rabotniCasovi[j];
  2350. }
  2351. if (casoviNedela>maxCasovi)
  2352. {
  2353. maxCasovi=casoviNedela;
  2354. maxNedela=i;
  2355. }
  2356. }
  2357. return maxNedela+1;
  2358. }
  2359. void table(R *r, int n)
  2360. {
  2361. printf("Rab\t1\t2\t3\t4\tVkupno\n");
  2362. int i,j;
  2363. for(i=0;i<n;i++)
  2364. {
  2365.  
  2366. int vkupno=0;
  2367. printf("%s\t",r[i].ime);
  2368. for(j=0;j<4;j++)
  2369. {
  2370. int vkupnoCasovi=0;
  2371. int z=0;
  2372. for(z=0;z<5;z++)
  2373. {
  2374. vkupnoCasovi+=r[i].nedeli[j].rabotniCasovi[z];
  2375. }
  2376. printf("%d\t",vkupnoCasovi);
  2377. vkupno+=vkupnoCasovi;
  2378. }
  2379. printf("%d\n",vkupno);
  2380. }
  2381. }
  2382.  
  2383. // ovde funkciite
  2384.  
  2385.  
  2386. int main() {
  2387. int n;
  2388. scanf("%d", &n);
  2389. R rabotnici[n];
  2390. int i;
  2391. for (i = 0; i < n; ++i) {
  2392. scanf("%s", rabotnici[i].ime);
  2393. int j;
  2394. for (j = 0; j < NEDELI; ++j) {
  2395. int k;
  2396. for (k = 0; k < DENOVI; ++k) {
  2397. scanf("%d", &rabotnici[i].nedeli[j].rabotniCasovi[k]);
  2398. }
  2399.  
  2400. }
  2401. }
  2402. printf("TABLE\n");
  2403. table(rabotnici, n);
  2404. printf("MAX NEDELA NA RABOTNIK: %s\n", rabotnici[n / 2].ime);
  2405. printf("%d\n", maxNedela(&rabotnici[n/2]));
  2406. return 0;
  2407. }
  2408. 5.LIST CONTAINER
  2409. 14.STRUKTURA VO C
  2410. 15.AKCII
  2411. 16.ZABAVEN PARK
  2412. 17.GITARI
  2413. #include <iostream>
  2414. #include <cstring>
  2415. using namespace std;
  2416. class Gitara{
  2417. char seriski[25];
  2418. double nabavna;
  2419. int godinaProizvodstvo;
  2420. char tip[40];
  2421. public:
  2422. Gitara(const char *tip=" ", const char * seriski =" ",int godinaProizvodstvo=0,double nabavna =0)
  2423. {
  2424. strcpy(this->tip,tip);
  2425. strcpy(this->seriski,seriski);
  2426. this->godinaProizvodstvo=godinaProizvodstvo;
  2427. this->nabavna=nabavna;
  2428.  
  2429.  
  2430.  
  2431. }
  2432. Gitara (const Gitara &g)
  2433. {
  2434.  
  2435.  
  2436. strcpy(this->tip,g.tip);
  2437. strcpy(this->seriski,g.seriski);
  2438. this->godinaProizvodstvo=g.godinaProizvodstvo;
  2439. this->nabavna=g.nabavna;
  2440.  
  2441.  
  2442. }
  2443.  
  2444. Gitara &operator= (const Gitara &g)
  2445. {
  2446.  
  2447.  
  2448.  
  2449. strcpy(this->tip,g.tip); strcpy(this->seriski,g.seriski);
  2450. this->godinaProizvodstvo=g.godinaProizvodstvo;
  2451. this->nabavna=g.nabavna;
  2452. return *this;
  2453.  
  2454. }
  2455.  
  2456. bool daliisti(Gitara g)
  2457. {
  2458. if(strcmp(seriski,g.seriski)==0)
  2459. return true;
  2460. else
  2461. return false;
  2462.  
  2463.  
  2464. }
  2465.  
  2466. void pecati()
  2467. {
  2468. cout<<seriski<<" "<<tip<<" "<<nabavna<<endl;
  2469.  
  2470. }
  2471. friend class Magacin;
  2472.  
  2473.  
  2474. double getNabavna()
  2475. {
  2476. return nabavna;
  2477. }
  2478. char * getTip()
  2479. {
  2480. return tip;
  2481. }
  2482. char * getSeriski()
  2483. {
  2484. return seriski;
  2485. }
  2486. int getGodina()
  2487. {
  2488. return godinaProizvodstvo;
  2489. }
  2490.  
  2491. };
  2492.  
  2493. class Magacin{
  2494. char ime_mag[30];
  2495. char lokacija[60];
  2496. Gitara *git;
  2497. int brg;
  2498. int otvaranje;
  2499. public:
  2500.  
  2501. Magacin(const char *ime_mag=" ", const char *lokacija=" ", int otvaranje=0)
  2502. {
  2503. strcpy(this->ime_mag,ime_mag);
  2504. strcpy(this->lokacija,lokacija);
  2505. this->brg=0;
  2506. this->otvaranje=otvaranje;
  2507. this->git= new Gitara [brg];
  2508.  
  2509.  
  2510. }
  2511.  
  2512. Magacin(const Magacin &m)
  2513. {
  2514.  
  2515. strcpy(this->ime_mag,m.ime_mag);
  2516. strcpy(this->lokacija,m.lokacija);
  2517. this->brg=m.brg;
  2518. this->otvaranje=m.otvaranje;
  2519. this->git= new Gitara [brg];
  2520. for(int i=0;i<brg;i++)
  2521. {
  2522.  
  2523. this->git[i]=m.git[i];
  2524.  
  2525.  
  2526. }
  2527.  
  2528.  
  2529.  
  2530. }
  2531.  
  2532. Magacin &operator=(const Magacin &m)
  2533. {
  2534. if(this!=&m){
  2535. strcpy(this->ime_mag,m.ime_mag);
  2536. strcpy(this->lokacija,m.lokacija);
  2537. this->brg=m.brg;
  2538. this->otvaranje=m.otvaranje;
  2539. delete [] git;
  2540. this->git= new Gitara [brg];
  2541. for(int i=0;i<brg;i++)
  2542. {
  2543.  
  2544. this->git[i]=m.git[i];
  2545.  
  2546.  
  2547. }}
  2548. return *this;
  2549.  
  2550.  
  2551.  
  2552. }
  2553. double vrednost ()
  2554. {
  2555. double suma=0;
  2556. for(int i=0;i<brg;i++)
  2557. {
  2558. suma+=git[i].nabavna;
  2559.  
  2560.  
  2561. }
  2562.  
  2563. return suma;
  2564. }
  2565.  
  2566.  
  2567.  
  2568.  
  2569.  
  2570. void dodadi(const Gitara &d)
  2571. {
  2572. Gitara *tmp= new Gitara [brg+1];
  2573. for(int i=0;i<brg;i++){
  2574. tmp[i]=git[i];
  2575.  
  2576.  
  2577. }
  2578. tmp[brg++]=d;
  2579. delete [] git;
  2580. git=tmp;
  2581.  
  2582. }
  2583.  
  2584. void prodadi(const Gitara &p)
  2585. {
  2586.  
  2587. int count =0;
  2588. for(int i=0;i<brg;i++)
  2589. {
  2590. if(git[i].daliisti(p)==false)
  2591. {
  2592.  
  2593. count++;
  2594.  
  2595. }
  2596.  
  2597. }
  2598. Gitara *tmp= new Gitara [count];
  2599. int newcount=0;
  2600. for(int i=0;i<brg;i++)
  2601. {
  2602. if(git[i].daliisti(p)==false)
  2603. {
  2604.  
  2605. tmp[newcount]=git[i];
  2606. newcount++;
  2607. }
  2608.  
  2609. }
  2610. delete [] git;
  2611. git=tmp;
  2612. brg=count;
  2613.  
  2614. }
  2615. void pecati(bool daliNovi){
  2616.  
  2617. cout<<ime_mag<<" "<<lokacija<<endl;
  2618. for(int i=0;i<brg;i++)
  2619.  
  2620. if(daliNovi==true&&git[i].godinaProizvodstvo>otvaranje)
  2621. {
  2622. git[i].pecati();
  2623. }
  2624. else if(daliNovi==false){
  2625. git[i].pecati();
  2626. }
  2627.  
  2628. }
  2629. };
  2630.  
  2631. /*
  2632.  
  2633. class Gitara{
  2634. private:
  2635. char seriski[25];
  2636. double nabavna;
  2637. int godinaProizvodstvo;
  2638. char tip[40];
  2639. public:
  2640. Gitara(char *tip="",char * seriski ="",int godinaProizvodstvo=0,double nabavna =0)
  2641. {
  2642. strcpy(this->tip,tip);
  2643. strcpy(this->seriski,seriski);
  2644. this->godinaProizvodstvo = godinaProizvodstvo;
  2645. this->nabavna = nabavna;
  2646. }
  2647. Gitara(const Gitara &g)
  2648. {
  2649. strcpy(this->tip,g.tip);
  2650. strcpy(this->seriski,g.seriski);
  2651. this->godinaProizvodstvo = g.godinaProizvodstvo;
  2652. this->nabavna = g.nabavna;
  2653. }
  2654. Gitara & operator=(const Gitara &g)
  2655. {
  2656. strcpy(this->tip,g.tip);
  2657. strcpy(this->seriski,g.seriski);
  2658. this->godinaProizvodstvo = g.godinaProizvodstvo;
  2659. this->nabavna = g.nabavna;
  2660. return *this;
  2661. }
  2662. ~Gitara()
  2663. {
  2664. }
  2665. bool daliIsti(Gitara &g)
  2666. {
  2667. return strcmp(this->seriski,g.seriski)==0;
  2668. }
  2669. void pecati()
  2670. {
  2671. cout<<seriski<<" "<<tip<<" "<<nabavna<<endl;
  2672. }
  2673. double getNabavna()
  2674. {
  2675. return nabavna;
  2676. }
  2677. char * getTip()
  2678. {
  2679. return tip;
  2680. }
  2681. char * getSeriski()
  2682. {
  2683. return seriski;
  2684. }
  2685. int getGodina()
  2686. {
  2687. return godinaProizvodstvo;
  2688. }
  2689. };
  2690.  
  2691. class Magacin{
  2692. private:
  2693. char lokacija[60];
  2694. char ime[50];
  2695. int godinaOtvaranje;
  2696. Gitara * niza;
  2697. int brGitari;
  2698. public:
  2699. Magacin(char * ime="",char * lokacija="",int godinaOtvaranje=0)
  2700. {
  2701. strcpy(this->lokacija,lokacija);
  2702. strcpy(this->ime,ime);
  2703. this->godinaOtvaranje = godinaOtvaranje;
  2704. niza = NULL;
  2705. brGitari = 0;
  2706. }
  2707. Magacin(const Magacin & m)
  2708. {
  2709. strcpy(this->lokacija,m.lokacija);
  2710. strcpy(this->ime,m.ime);
  2711. this->godinaOtvaranje = m.godinaOtvaranje;
  2712. niza = new Gitara[m.brGitari];
  2713. for(int i =0;i<m.brGitari;i++)
  2714. niza[i] = m.niza[i];
  2715. brGitari = m.brGitari;
  2716. }
  2717.  
  2718. Magacin & operator=(const Magacin & m)
  2719. {
  2720. delete [] niza;
  2721. strcpy(this->lokacija,m.lokacija);
  2722. strcpy(this->ime,m.ime);
  2723. this->godinaOtvaranje = m.godinaOtvaranje;
  2724. niza = new Gitara[m.brGitari];
  2725. for(int i =0;i<m.brGitari;i++)
  2726. niza[i] = m.niza[i];
  2727. brGitari = m.brGitari;
  2728. return *this;
  2729. }
  2730. ~Magacin(){delete [] niza;}
  2731. double vrednost()
  2732. {
  2733. double sum=0;
  2734. for(int i=0;i<brGitari;i++)
  2735. sum+=niza[i].getNabavna();
  2736. return sum;
  2737.  
  2738. }
  2739. void dodadi(Gitara & g)
  2740. {
  2741. Gitara * tmp = new Gitara[brGitari +1];
  2742. for(int i=0;i<brGitari;i++)
  2743. tmp[i] = niza[i];
  2744. tmp[brGitari++]=g;
  2745. delete [] niza;
  2746. niza=tmp;
  2747.  
  2748. }
  2749. void prodadi(Gitara & g)
  2750. {
  2751. int newBr = 0;
  2752. for(int i=0;i<brGitari;i++)
  2753. {
  2754. if(niza[i].daliIsti(g)==false)
  2755. {
  2756. newBr++;
  2757. }
  2758. }
  2759. Gitara * tmp = new Gitara[newBr];
  2760. int j=0;
  2761. for(int i=0;i<brGitari;i++)
  2762. {
  2763. if(niza[i].daliIsti(g)==false)
  2764. {
  2765. tmp[j] = niza[i];
  2766. j++;
  2767. }
  2768. }
  2769. delete [] niza;
  2770. niza = tmp;
  2771. brGitari = newBr;
  2772. }
  2773. void pecati(bool daliNovi)
  2774. {
  2775. cout<<ime<<" "<< lokacija<<endl;
  2776. for(int i=0;i<brGitari;i++)
  2777. {
  2778. if(daliNovi==true&&niza[i].getGodina()>godinaOtvaranje)
  2779. {
  2780. niza[i].pecati();
  2781. }
  2782. else if(daliNovi==false){
  2783. niza[i].pecati();
  2784. }
  2785. }
  2786. }
  2787. };*/
  2788. int main() {
  2789. // se testira zadacata modularno
  2790. int testCase;
  2791. cin >> testCase;
  2792.  
  2793. int n, godina;
  2794. float cena;
  2795. char seriski[50],tip[50];
  2796.  
  2797. if(testCase == 1) {
  2798. cout << "===== Testiranje na klasata Gitara ======" << endl;
  2799. cin>>tip;
  2800. cin>>seriski;
  2801. cin >> godina;
  2802. cin >> cena;
  2803. Gitara g(tip,seriski, godina,cena);
  2804. cout<<g.getTip()<<endl;
  2805. cout<<g.getSeriski()<<endl;
  2806. cout<<g.getGodina()<<endl;
  2807. cout<<g.getNabavna()<<endl;
  2808. } else if(testCase == 2){
  2809. cout << "===== Testiranje na klasata Magacin so metodot print() ======" << endl;
  2810. Magacin kb("Magacin1","Lokacija1");
  2811. kb.pecati(false);
  2812. }
  2813. else if(testCase == 3) {
  2814. cout << "===== Testiranje na klasata Magacin so metodot dodadi() ======" << endl;
  2815. Magacin kb("Magacin1","Lokacija1",2005);
  2816. cin>>n;
  2817. for (int i=0;i<n;i++){
  2818. cin>>tip;
  2819. cin>>seriski;
  2820. cin >> godina;
  2821. cin >> cena;
  2822. Gitara g(tip,seriski, godina,cena);
  2823. cout<<"gitara dodadi"<<endl;
  2824. kb.dodadi(g);
  2825. }
  2826. kb.pecati(true);
  2827. }
  2828.  
  2829. else if(testCase == 4) {
  2830. cout << "===== Testiranje na klasata Magacin so metodot prodadi() ======" << endl;
  2831. Magacin kb("Magacin1","Lokacija1",2012);
  2832. cin>>n;
  2833. Gitara brisi;
  2834. for (int i=0;i<n;i++){
  2835. cin>>tip;
  2836. cin>>seriski;
  2837. cin >> godina;
  2838. cin >> cena;
  2839.  
  2840. Gitara g(tip,seriski, godina,cena);
  2841. if(i==2)
  2842. brisi=g;
  2843. cout<<"gitara dodadi"<<endl;
  2844. kb.dodadi(g);
  2845. }
  2846. kb.pecati(false);
  2847. kb.prodadi(brisi);
  2848. kb.pecati(false);
  2849. }
  2850. else if(testCase == 5) {
  2851. cout << "===== Testiranje na klasata Magacin so metodot prodadi() i pecati(true) ======" << endl;
  2852. Magacin kb("Magacin1","Lokacija1",2011);
  2853. cin>>n;
  2854. Gitara brisi;
  2855. for (int i=0;i<n;i++){
  2856. cin>>tip;
  2857. cin>>seriski;
  2858. cin >> godina;
  2859. cin >> cena;
  2860.  
  2861. Gitara g(tip,seriski, godina,cena);
  2862. if(i==2)
  2863. brisi=g;
  2864. cout<<"gitara dodadi"<<endl;
  2865. kb.dodadi(g);
  2866. }
  2867. kb.pecati(true);
  2868. kb.prodadi(brisi);
  2869. cout<<"Po brisenje:"<<endl;
  2870. Magacin kb3;
  2871. kb3=kb;
  2872. kb3.pecati(true);
  2873. }
  2874. else if(testCase ==6)
  2875. {
  2876. cout << "===== Testiranje na klasata Magacin so metodot vrednost()======" << endl;
  2877. Magacin kb("Magacin1","Lokacija1",2011);
  2878. cin>>n;
  2879. Gitara brisi;
  2880. for (int i=0;i<n;i++){
  2881. cin>>tip;
  2882. cin>>seriski;
  2883. cin >> godina;
  2884. cin >> cena;
  2885.  
  2886. Gitara g(tip,seriski, godina,cena);
  2887. if(i==2)
  2888. brisi=g;
  2889. kb.dodadi(g);
  2890. }
  2891. cout<<kb.vrednost()<<endl;
  2892. kb.prodadi(brisi);
  2893. cout<<"Po brisenje:"<<endl;
  2894. cout<<kb.vrednost();
  2895. Magacin kb3;
  2896. kb3=kb;
  2897. }
  2898. return 0;
  2899. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement