Advertisement
Guest User

Вежби за прв колоквиум C++

a guest
Mar 20th, 2018
786
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 44.73 KB | None | 0 0
  1. 1. Скијачки центар
  2.  
  3. #include<stdio.h>
  4. #include<string.h>
  5.  
  6. typedef struct SkiLift{
  7. char ime[20];
  8. int max_skijaci;
  9. int voUpotreba;
  10. }skiLift;
  11.  
  12. typedef struct SkiCenter {
  13. char ime[20];
  14. char drzava[20];
  15. skiLift niza[20];
  16. int br_lifts;
  17. }skiCenter;
  18.  
  19. int kapacitet(skiCenter sc)
  20. {
  21. int i;
  22. int tmp = 0;
  23. for (i = 0; i < sc.br_lifts; i++)
  24. {
  25. if (sc.niza[i].voUpotreba == 1)
  26. {
  27. tmp += sc.niza[i].max_skijaci;
  28. }
  29. }
  30. return tmp;
  31.  
  32. }
  33. void najgolemKapacitet(skiCenter *sc, int n)
  34. {
  35. int tmp, i, j, max, max_ind;
  36. max = 0;
  37. max_ind = 0;
  38. for (i = 0; i < n; i++)
  39. {
  40. tmp = kapacitet(sc[i]);
  41. if ((tmp > max) || (tmp == max&&sc[i].br_lifts > sc[max_ind].br_lifts)) { max = tmp; max_ind = i; }
  42. }
  43. printf("%s\n%s\n%d\n", sc[max_ind].ime, sc[max_ind].drzava, max);
  44. }
  45.  
  46. int main()
  47. {
  48. int i, j, n, broj;
  49. skiCenter sc[20];
  50. scanf("%d", &n);
  51. for (i = 0; i < n; i++){
  52. //printf("Ime:");
  53. scanf("%s", sc[i].ime);
  54. //printf("\nDrzava:");
  55. scanf("%s", sc[i].drzava);
  56. scanf("%d", &sc[i].br_lifts);
  57.  
  58. for (j = 0; j < sc[i].br_lifts; j++){
  59. scanf("%s", sc[i].niza[j].ime);
  60. scanf("%d", &sc[i].niza[j].max_skijaci);
  61. scanf("%d", &sc[i].niza[j].voUpotreba);
  62. }
  63. }
  64. najgolemKapacitet(sc, n);
  65.  
  66. return 0;
  67. }
  68.  
  69.  
  70.  
  71.  
  72. 1. Компјутерска игра
  73.  
  74. #include<iostream>
  75. #include <cstring>
  76. #include <string>
  77. using namespace std;
  78. struct Igrac{
  79. string Ime;
  80. int nivo;
  81. int poeni;
  82. };
  83. struct KompjuterskaIgra{
  84. string ImeIgra;
  85. Igrac igraci[30];
  86. int brigraci;
  87. }igri[100];
  88. void najdobarIgrac(KompjuterskaIgra *lista, int n){
  89. int i,j,maxpoena=0,maxnivo=0;
  90. string ndigra;
  91. string ndigrach;
  92. for (i=0;i<n;i++){
  93. for (j=0;j<lista[i].brigraci;j++){
  94. if(lista[i].igraci[j].poeni==maxpoena){
  95. if (lista[i].igraci[j].nivo>maxnivo) {
  96. maxpoena=lista[i].igraci[j].poeni;
  97. maxnivo=lista[i].igraci[j].nivo;
  98. ndigra=lista[i].ImeIgra;
  99. // ndigrach=new char[strlen(lista[i].igraci[j].Ime)+1];
  100. // strcpy(ndigrach,lista[i].igraci[j].Ime);
  101. ndigrach=lista[i].igraci[j].Ime;
  102. }} else
  103. if(lista[i].igraci[j].poeni>maxpoena){
  104. maxpoena=lista[i].igraci[j].poeni;
  105. maxnivo=lista[i].igraci[j].nivo;
  106. ndigra=lista[i].ImeIgra;
  107. ndigrach=lista[i].igraci[j].Ime;
  108. }
  109. };
  110. };
  111. //cout<<"zdr"<<endl;
  112. cout<<"Najdobar igrac e igracot so korisnicko ime "<<ndigrach<<" koj ja igra igrata "<<ndigra<<endl;
  113. //sostojki=new char [strlen(p.sostojki)+1];
  114. //strcpy(sostojki,p.sostojki);
  115. }
  116. int main(){
  117.  
  118. int n;
  119. cin>>n; //se cita brojot na igri
  120. //cout<<n<<endl;
  121. KompjuterskaIgra igri[100];
  122. for (int i=0;i<n;i++){
  123. cin>>igri[i].ImeIgra;
  124. //cout<<igri[i].ImeIgra<<endl;
  125. cin>>igri[i].brigraci;
  126. //cout<<igri[i].brigraci<<endl;
  127. for (int j=0;j<igri[i].brigraci;j++){
  128. //cout<<j<<"eve go"<<endl;
  129. //strcpy(cin,lista[j].igraci[i].Ime);
  130. //lista[j].igraci[i].Ime=new char [strlen()]
  131. //getline(cin,igri[i].igraci[j].Ime);
  132. cin>>igri[i].igraci[j].Ime;
  133. //cout<<igri[i].igraci[j].Ime<<endl;
  134. cin>>igri[i].igraci[j].nivo;
  135. cin>>igri[i].igraci[j].poeni;
  136. };
  137. };
  138.  
  139. najdobarIgrac(igri,n);
  140. return 0;
  141. }
  142.  
  143.  
  144. 2. Железничка станица
  145.  
  146. #include<iostream>
  147. #include <cstring>
  148. using namespace std;
  149.  
  150. struct Voz{
  151. char relacija[50];
  152. float km;
  153. int brojPatnici;
  154. };
  155.  
  156. struct ZeleznickaStanica{
  157. char grad[20];
  158. Voz vozovi[30];
  159. int brojVozovi;
  160. };
  161.  
  162. void najkratkaRelacija(ZeleznickaStanica* zs, int n, char* grad){
  163. Voz minRelacija;
  164. minRelacija.km=10000000;
  165. for (int i=0;i<n;i++){
  166. if(strcmp(zs[i].grad,grad)==0){
  167. for(int j=0;j<zs[i].brojVozovi;++j){
  168. if(zs[i].vozovi[j].km<=minRelacija.km){
  169. minRelacija=zs[i].vozovi[j];
  170. }
  171. }
  172. }
  173. }
  174. cout<<"Najkratka relacija: "<<minRelacija.relacija<<" ("<<minRelacija.km<<" km)";
  175. }
  176.  
  177.  
  178.  
  179. int main(){
  180.  
  181. int n;
  182. cin>>n; //se cita brojot na zelezlnichki stanici
  183.  
  184. ZeleznickaStanica zStanica[100];
  185. for (int i=0;i<n;i++){
  186. //se citaat infomracii za n zelezlnichkite stanici i se zacuvuvaat vo poleto zStanica
  187. cin>>zStanica[i].grad>>zStanica[i].brojVozovi;
  188. for(int j=0;j<zStanica[i].brojVozovi;j++){
  189. cin>>zStanica[i].vozovi[j].relacija>>zStanica[i].vozovi[j].km>>zStanica[i].vozovi[j].brojPatnici;
  190. }
  191. }
  192.  
  193. char grad[25];
  194. cin>>grad;
  195.  
  196. najkratkaRelacija(zStanica,n,grad);
  197. return 0;
  198. }
  199.  
  200.  
  201. 2. CD
  202.  
  203. #include <iostream>
  204. #include <cstring>
  205. using namespace std;
  206. enum tip {pop,rap,rok };
  207. class Pesna {
  208. private:
  209. char *ime;
  210. int minuti;
  211. tip muzika;
  212. public:
  213. Pesna () {}
  214. Pesna (char *i,int m,tip muz) {
  215. ime=new char [strlen(i)+1];
  216. strcpy(ime,i);
  217. minuti=m;
  218. muzika=muz;
  219. }
  220. void pecati() {
  221. cout<<"\""<<ime<<"\""<<"-"<<minuti<<"min"<<endl;
  222. }
  223. int getmin ()
  224. {
  225. return minuti;
  226. }
  227. tip getTip()
  228. {
  229. return muzika;
  230. }
  231. };
  232. class CD {
  233. private:
  234. Pesna pesni[10];
  235. int n;
  236. int max;
  237. public:
  238. CD () { }
  239. CD (int max) {
  240. this->max=max;
  241. n=0;
  242. }
  243. CD & dodadiPesna (Pesna p)
  244. {
  245. ++n;
  246. int temp=0;
  247. for(int i=0; i<n-1; i++)
  248. {
  249. temp+=pesni[i].getmin();
  250. }
  251. if(n>10 || max<(temp+p.getmin()))
  252. {
  253. --n;
  254. return *this;
  255. }
  256. pesni[n-1]=p;
  257. return *this;
  258. }
  259. Pesna & getPesna (int k)
  260. {
  261. return pesni[k];
  262. }
  263. int getBroj ()
  264. {
  265. return n;
  266. }
  267. void pecatiPesniPoTip(tip t)
  268. {
  269. for(int i=0; i<n; i++)
  270. {
  271. if(pesni[i].getTip()==t)
  272. pesni[i].pecati();
  273. }
  274.  
  275. }
  276. };
  277. int main() {
  278. // se testira zadacata modularno
  279. int testCase;
  280. cin >> testCase;
  281.  
  282. int n, minuti, kojtip;
  283. char ime[50];
  284.  
  285. if(testCase == 1) {
  286. cout << "===== Testiranje na klasata Pesna ======" << endl;
  287. cin >> ime;
  288. cin >> minuti;
  289. cin >> kojtip; //se vnesuva 0 za POP,1 za RAP i 2 za ROK
  290. Pesna p(ime,minuti,(tip)kojtip);
  291. p.pecati();
  292. } else if(testCase == 2) {
  293. cout << "===== Testiranje na 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. for (int i=0; i<n; i++)
  304. (omileno.getPesna(i)).pecati();
  305. } else if(testCase == 3) {
  306. cout << "===== Testiranje na metodot dodadiPesna() od klasata CD ======" << endl;
  307. CD omileno(20);
  308. cin>>n;
  309. for (int i=0; i<n; i++) {
  310. cin >> ime;
  311. cin >> minuti;
  312. cin >> kojtip; //se vnesuva 0 za POP,1 za RAP i 2 za ROK
  313. Pesna p(ime,minuti,(tip)kojtip);
  314. omileno.dodadiPesna(p);
  315. }
  316. for (int i=0; i<omileno.getBroj(); i++)
  317. (omileno.getPesna(i)).pecati();
  318. } else if(testCase == 4) {
  319. cout << "===== Testiranje na metodot pecatiPesniPoTip() od klasata CD ======" << endl;
  320. CD omileno(20);
  321. cin>>n;
  322. for (int i=0; i<n; i++) {
  323. cin >> ime;
  324. cin >> minuti;
  325. cin >> kojtip; //se vnesuva 0 za POP,1 za RAP i 2 za ROK
  326. Pesna p(ime,minuti,(tip)kojtip);
  327. omileno.dodadiPesna(p);
  328. }
  329. cin>>kojtip;
  330. omileno.pecatiPesniPoTip((tip)kojtip);
  331.  
  332. } else if(testCase == 5) {
  333. cout << "===== Testiranje na metodot pecatiPesniPoTip() od klasata CD ======" << endl;
  334. CD omileno(20);
  335. cin>>n;
  336. for (int i=0; i<n; i++) {
  337. cin >> ime;
  338. cin >> minuti;
  339. cin >> kojtip; //se vnesuva 0 za POP,1 za RAP i 2 za ROK
  340. Pesna p(ime,minuti,(tip)kojtip);
  341. omileno.dodadiPesna(p);
  342. }
  343. cin>>kojtip;
  344. omileno.pecatiPesniPoTip((tip)kojtip);
  345.  
  346. }
  347.  
  348. return 0;
  349. }
  350.  
  351.  
  352. 3. Пицерија
  353.  
  354. #include <iostream>
  355. #include <cstring>
  356.  
  357. using namespace std;
  358.  
  359. //Vasiot kod tuka
  360.  
  361. class Pica{
  362. private:
  363.  
  364. char ime[15];
  365. int cena;
  366. char *sostojki;
  367. int namaluvanje=0;
  368.  
  369. public:
  370.  
  371. Pica(char* ime="",int cena=0,char* sostojki="",int namaluvanje=0){
  372. strncpy(this->ime,ime,15);
  373. this->cena=cena;
  374. this->namaluvanje=namaluvanje;
  375. this->sostojki=new char [strlen(sostojki)+1];
  376. strcpy(this->sostojki,sostojki);
  377. }
  378.  
  379. Pica(const Pica &p){
  380. strncpy(this->ime,p.ime,15);
  381. this->cena=p.cena;
  382. this->namaluvanje=p.namaluvanje;
  383. this->sostojki=new char [strlen(p.sostojki)+1];
  384. strcpy(this->sostojki,p.sostojki);
  385. }
  386.  
  387. Pica& operator=(const Pica& p){
  388. if(this!=&p){
  389. strncpy(this->ime,p.ime,15);
  390. this->cena=p.cena;
  391. this->namaluvanje=p.namaluvanje;
  392. this->sostojki=new char [strlen(p.sostojki)+1];
  393. strcpy(this->sostojki,p.sostojki);
  394. }
  395. return *this;
  396. }
  397.  
  398. ~Pica(){
  399. delete [] sostojki;
  400. }
  401.  
  402. void pecati(){
  403. cout<<ime<<" - "<<sostojki<<", "<<cena<<" ";
  404. if(namaluvanje>0&&namaluvanje<=100){
  405. cout<<cena-cena*namaluvanje/100<<endl;
  406. }
  407. }
  408.  
  409. bool istiSe(Pica &p){
  410. if(strcmp(this->sostojki,p.sostojki)==0) return true;
  411. else return false;
  412. }
  413.  
  414. char* getSostojki(){
  415. return sostojki;
  416. }
  417.  
  418. int getNamaluvanje(){
  419. return namaluvanje;
  420. }
  421.  
  422. };
  423.  
  424. class Picerija{
  425. private:
  426. char ime[15];
  427. Pica *pici;
  428. int brojPici;
  429. public:
  430. Picerija(){}
  431.  
  432. Picerija(char *ime){
  433. strncpy(this->ime,ime,15);
  434. pici=new Pica [0];
  435. brojPici=0;
  436. }
  437.  
  438. Picerija(const Picerija& p){
  439. strncpy(this->ime,p.ime,15);
  440. this->brojPici=p.brojPici;
  441. this->pici=new Pica [brojPici];
  442. for(int i=0;i<brojPici;i++){
  443. this->pici[i]=p.pici[i];
  444. }
  445. }
  446.  
  447. ~Picerija(){
  448. delete [] pici;
  449. }
  450.  
  451. void dodadi(Pica &p){
  452. int flag=0;
  453. for(int i=0;i<brojPici;i++){
  454. if(strcmp(this->pici[i].getSostojki(),p.getSostojki())==0){
  455. flag=1;
  456. }
  457. }
  458. if(flag==0){
  459. Pica *tmp=new Pica[brojPici];
  460. for(int i=0;i<brojPici;i++){
  461. tmp[i]=this->pici[i];
  462. }
  463. delete [] this->pici;
  464. this->pici=new Pica[brojPici+1];
  465. for(int i=0;i<brojPici;i++){
  466. this->pici[i]=tmp[i];
  467. }
  468. this->pici[brojPici]=p;
  469. delete [] tmp;
  470. brojPici++;
  471. }
  472. }
  473.  
  474. char* getIme(){
  475. return this->ime;
  476. }
  477.  
  478. void piciNaPromocija(){
  479. for(int i=0;i<brojPici;i++){
  480. if((this->pici[i].getNamaluvanje())!=0){
  481. this->pici[i].pecati();
  482. }
  483. }
  484. }
  485.  
  486. void setIme(char* ime){
  487. strncpy(this->ime,ime,15);
  488. }
  489.  
  490.  
  491. };
  492.  
  493. int main () {
  494.  
  495. int n;
  496. char ime[15];
  497. cin >> ime;
  498. cin >> n;
  499.  
  500. Picerija p1(ime);
  501. for(int i = 0; i < n; i++){
  502. char imp[100];
  503. cin.get();
  504. cin.getline(imp,100);
  505. int cena;
  506. cin >> cena;
  507. char sostojki[100];
  508. cin.get();
  509. cin.getline(sostojki,100);
  510. int popust;
  511. cin >> popust;
  512. Pica p(imp,cena,sostojki,popust);
  513. p1.dodadi(p);
  514. }
  515.  
  516. Picerija p2 = p1;
  517. cin >> ime;
  518. p2.setIme(ime);
  519. char imp[100];
  520. cin.get();
  521. cin.getline(imp,100);
  522. int cena;
  523. cin >> cena;
  524. char sostojki[100];
  525. cin.get();
  526. cin.getline(sostojki,100);
  527. int popust;
  528. cin >> popust;
  529. Pica p(imp,cena,sostojki,popust);
  530. p2.dodadi(p);
  531.  
  532. cout<<p1.getIme()<<endl;
  533. cout<<"Pici na promocija:"<<endl;
  534. p1.piciNaPromocija();
  535.  
  536. cout<<p2.getIme()<<endl;
  537. cout<<"Pici na promocija:"<<endl;
  538. p2.piciNaPromocija();
  539.  
  540. return 0;
  541.  
  542. }
  543.  
  544.  
  545. 4. Маратон
  546.  
  547.  
  548. #include <iostream>
  549. #include <cstring>
  550. using namespace std;
  551.  
  552. class Ucesnik{
  553.  
  554. private:
  555. char *ime;
  556. bool pol;
  557. int vozrast;
  558.  
  559. public:
  560.  
  561. Ucesnik(char *ime="",bool pol=0,int vozrast=0){
  562. this->ime=new char [strlen(ime)+1];
  563. strcpy(this->ime,ime);
  564. this->pol=pol;
  565. this->vozrast=vozrast;
  566. }
  567.  
  568. ~Ucesnik(){
  569. delete [] ime;
  570. }
  571.  
  572. Ucesnik& operator=(const Ucesnik& u){
  573. if(this!=&u){
  574. delete [] this->ime;
  575. this->ime=new char [strlen(u.ime)+1];
  576. strcpy(this->ime,u.ime);
  577. this->pol=u.pol;
  578. this->vozrast=u.vozrast;
  579. }
  580. return *this;
  581. }
  582.  
  583. bool operator>(Ucesnik &u){
  584. return this->vozrast>u.vozrast;
  585. }
  586.  
  587. friend ostream& operator<<(ostream& out,Ucesnik& u){
  588. out<<u.ime<<endl;
  589. if(u.pol==0) {
  590. out<<"zhenski"<<endl;
  591. } else {
  592. out<<"mashki"<<endl;
  593. }
  594. out<<u.vozrast<<endl;
  595. return out;
  596. }
  597.  
  598. int getVozrast(){
  599. return this->vozrast;
  600. }
  601.  
  602. };
  603.  
  604. class Maraton{
  605.  
  606. private:
  607.  
  608. char lokacija[100];
  609. Ucesnik *ucesnici;
  610. int brojUcesnici;
  611.  
  612. public:
  613.  
  614. Maraton(){}
  615.  
  616. Maraton(char* lokacija){
  617. strncpy(this->lokacija,lokacija,strlen(lokacija)+1);
  618. ucesnici=new Ucesnik[0];
  619. brojUcesnici=0;
  620. }
  621.  
  622. ~Maraton(){
  623. delete [] ucesnici;
  624. }
  625.  
  626. Maraton& operator+=(Ucesnik &u){
  627. Ucesnik *tmp=new Ucesnik [this->brojUcesnici];
  628. for(int i=0;i<this->brojUcesnici;i++){
  629. tmp[i]=this->ucesnici[i];
  630. }
  631. delete [] ucesnici;
  632. ucesnici=new Ucesnik [brojUcesnici+1];
  633. for(int i=0;i<this->brojUcesnici;i++){
  634. this->ucesnici[i]=tmp[i];
  635. }
  636. this->ucesnici[brojUcesnici]=u;
  637. delete [] tmp;
  638. brojUcesnici++;
  639. return *this;
  640.  
  641. }
  642.  
  643. float prosecnoVozrast(){
  644. int sum=0;
  645. for(int i=0;i<brojUcesnici;i++){
  646. sum+=this->ucesnici[i].getVozrast();
  647. }
  648.  
  649. return (float)sum/brojUcesnici;
  650. }
  651.  
  652. void pecatiPomladi(Ucesnik &u){
  653. for(int i=0;i<brojUcesnici;i++){
  654. if(this->ucesnici[i].getVozrast()<u.getVozrast()){
  655. cout<<this->ucesnici[i];
  656. }
  657. }
  658. }
  659.  
  660.  
  661.  
  662.  
  663. };
  664.  
  665.  
  666.  
  667.  
  668. int main() {
  669. char ime[100];
  670. bool maski;
  671. int vozrast, n;
  672. cin >> n;
  673. char lokacija[100];
  674. cin >> lokacija;
  675. Maraton m(lokacija);
  676. Ucesnik **u = new Ucesnik*[n];
  677. for(int i = 0; i < n; ++i) {
  678. cin >> ime >> maski >> vozrast;
  679. u[i] = new Ucesnik(ime, maski, vozrast);
  680. m += *u[i];
  681. }
  682. m.pecatiPomladi(*u[n - 1]);
  683. cout << m.prosecnoVozrast() << endl;
  684. for(int i = 0; i < n; ++i) {
  685. delete u[i];
  686. }
  687. delete [] u;
  688. return 0;
  689.  
  690. }
  691.  
  692.  
  693. 5. Сладолед
  694.  
  695. #include <iostream>
  696. #include <cstring>
  697. using namespace std;
  698.  
  699. class IceCream {
  700. private:
  701. char *name;
  702. char ingredients[100];
  703. float price;
  704. int discount;
  705. void copy(const IceCream &ic) {
  706. name = new char[strlen(ic.name) + 1];
  707. strcpy(name, ic.name);
  708. strncpy(ingredients, ic.ingredients, 99);
  709. ingredients[99] = '\0';
  710. price = ic.price;
  711. discount = ic.discount;
  712. }
  713. public:
  714. IceCream(const char *nm = "", const char *ingr = "", float p = 0) {
  715. name = new char[strlen(nm) + 1];
  716. strcpy(name, nm);
  717. strncpy(ingredients, ingr, 99);
  718. ingredients[99] = '\0';
  719. price = p;
  720. discount = 0;
  721. }
  722.  
  723. IceCream(const IceCream &ic) {
  724. copy(ic);
  725. }
  726.  
  727. IceCream& operator=(const IceCream &ic) {
  728. if (this == &ic) return *this;
  729. delete [] name;
  730. copy(ic);
  731. return *this;
  732. }
  733.  
  734. friend ostream& operator<<(ostream &out, const IceCream &ic) {
  735. out << ic.name << ": ";
  736. out << ic.ingredients << " ";
  737. out << ic.price << " ";
  738. if (ic.discount > 0) {
  739. out << "(" << ic.price * (100 - ic.discount) / 100 << ")";
  740. }
  741. return out;
  742. }
  743. void setName(char *n) {
  744. delete [] name;
  745. name = new char[strlen(n) + 1];
  746. strcpy(name, n);
  747. }
  748.  
  749. IceCream& operator++() {
  750. discount += 5;
  751. return *this;
  752. }
  753.  
  754. IceCream operator+(const char* extra) {
  755.  
  756. char* newName = new char[strlen(name) + strlen(extra) + 4];
  757. strcat(newName, name);
  758. strcat(newName, " + ");
  759. strcat(newName, extra);
  760.  
  761. IceCream res(newName, ingredients, price + 10);
  762. res.setDiscount(discount);
  763. return res;
  764. }
  765.  
  766. void setName(const char* n) {
  767. delete [] name;
  768. name = new char[strlen(n) + 1];
  769. strcpy(name, n);
  770. }
  771.  
  772. void setDiscount(int d) {
  773.  
  774. if(d>=0&&d<=100)
  775. discount = d;
  776. }
  777.  
  778. ~IceCream() {
  779. delete [] name;
  780. }
  781. };
  782.  
  783. class IceCreamShop {
  784. private:
  785. char name[50];
  786. IceCream *icecreams;
  787. int n;
  788. void copy(const IceCreamShop &ics) {
  789. strcpy(name, ics.name);
  790. n = ics.n;
  791. icecreams = new IceCream[n];
  792. for (int i = 0; i < n; ++i) {
  793. icecreams[i] = ics.icecreams[i];
  794. }
  795. }
  796. public:
  797. IceCreamShop(char* nm) {
  798. strcpy(name, nm);
  799. icecreams = NULL;
  800. n = 0;
  801. }
  802. IceCreamShop(const IceCreamShop &ics) {
  803. copy(ics);
  804. }
  805. IceCreamShop& operator=(const IceCreamShop &ics) {
  806. if (this == &ics) return *this;
  807. delete [] icecreams;
  808. copy(ics);
  809. return *this;
  810. }
  811. ~IceCreamShop() {
  812. delete [] icecreams;
  813. }
  814.  
  815. IceCreamShop& operator+= (IceCream &ic) {
  816. IceCream *tmp = icecreams;
  817. icecreams = new IceCream[n + 1];
  818. for (int i = 0; i < n; ++i) {
  819. icecreams[i] = tmp[i];
  820. }
  821. icecreams[n] = ic;
  822. ++n;
  823. delete [] tmp;
  824. return *this;
  825. }
  826.  
  827. friend ostream& operator<<(ostream &out, const IceCreamShop &ics) {
  828. cout << ics.name << endl;
  829. for (int i = 0; i < ics.n; ++i) {
  830. out << ics.icecreams[i] << endl;
  831. }
  832. return out;
  833. }
  834.  
  835. };
  836.  
  837. int main() {
  838. char name[100];
  839. char ingr[100];
  840. float price;
  841. int discount;
  842.  
  843. int testCase;
  844.  
  845. cin >> testCase;
  846. cin.get();
  847. if(testCase == 1) {
  848. cout << "====== TESTING IceCream CLASS ======" << endl;
  849. cin.getline(name,100);
  850. cin.getline(ingr,100);
  851. cin >> price;
  852. cin >> discount;
  853. cout << "CONSTRUCTOR" << endl;
  854. IceCream ic1(name, ingr, price);
  855. ic1.setDiscount(discount);
  856. cin.get();
  857. cin.getline(name,100);
  858. cin.getline(ingr,100);
  859. cin >> price;
  860. cin >> discount;
  861. IceCream ic2(name, ingr, price);
  862. ic2.setDiscount(discount);
  863. cout << "OPERATOR <<" << endl;
  864. cout << ic1 << endl;
  865. cout << ic2 << endl;
  866. cout << "OPERATOR ++" << endl;
  867. ++ic1;
  868. cout << ic1 << endl;
  869. cout << "OPERATOR +" << endl;
  870. IceCream ic3 = ic2 + "chocolate";
  871. cout << ic3 << endl;
  872. } else if(testCase == 2) {
  873. cout << "====== TESTING IceCream CONSTRUCTORS ======" << endl;
  874. cin.getline(name,100);
  875. cin.getline(ingr,100);
  876. cin >> price;
  877. //cin >> discount;
  878. cout << "CONSTRUCTOR" << endl;
  879. IceCream ic1(name, ingr, price);
  880. cout << ic1 << endl;
  881. cout << "COPY CONSTRUCTOR" << endl;
  882. IceCream ic2(ic1);
  883. cin.get();
  884. cin.getline(name,100);
  885. ic2.setName(name);
  886. cout << ic1 << endl;
  887. cout << ic2 << endl;
  888. cout << "OPERATOR =" << endl;
  889. ic1 = ic2;
  890. cin.getline(name,100);
  891. ic2.setName(name);
  892. cout << ic1 << endl;
  893. cout << ic2 << endl;
  894.  
  895. cin >> discount;
  896. ic1.setDiscount(discount);
  897.  
  898.  
  899. } else if(testCase == 3) {
  900. cout << "====== TESTING IceCreamShop ======" << endl;
  901. char icsName[50];
  902. cin.getline(icsName,100);
  903. cout << "CONSTRUCTOR" << endl;
  904. IceCreamShop ics(icsName);
  905. int n;
  906. cin >> n;
  907. cout << "OPERATOR +=" << endl;
  908. for(int i = 0; i < n; ++i) {
  909. cin.get();
  910. cin.getline(name,100);
  911. cin.getline(ingr,100);
  912. cin >> price;
  913. IceCream ic(name, ingr, price);
  914. ics += ic;
  915. }
  916. cout << ics;
  917. } else if(testCase == 4) {
  918. cout << "====== TESTING IceCreamShop CONSTRUCTORS ======" << endl;
  919. char icsName[50];
  920. cin.getline(icsName,100);
  921. IceCreamShop ics(icsName);
  922. int n;
  923. cin >> n;
  924. for(int i = 0; i < n; ++i) {
  925. cin.get();
  926. cin.getline(name,100);
  927. cin.getline(ingr,100);
  928. cin >> price;
  929. IceCream ic(name, ingr, price);
  930. ics += ic;
  931. }
  932. IceCream x("FINKI fruits", "strawberry ice cream, raspberry ice cream, blueberry ice cream", 60);
  933. IceCreamShop icp = ics;
  934. ics+=x;
  935. cout << ics << endl;
  936. cout << icp << endl;
  937. }
  938.  
  939.  
  940. return 0;
  941. }
  942.  
  943.  
  944. 6. Планинарски дом
  945.  
  946. #include<iostream>
  947. #include<string.h>
  948. using namespace std;
  949.  
  950. class Zichara {
  951. private:
  952. char *place;
  953. int dayPrice;
  954. public:
  955. Zichara() {
  956. place = new char[0];
  957. }
  958. Zichara(char *place, int price) {
  959. this->place = new char[strlen(place)+1];
  960. strcpy(this->place,place);
  961. dayPrice = price;
  962. }
  963. ~Zichara() {
  964. delete [] place;
  965. }
  966. Zichara(const Zichara &z) {
  967. place = new char[strlen(z.place)+1];
  968. strcpy(place,z.place);
  969. dayPrice = z.dayPrice;
  970. }
  971. Zichara& operator=(const Zichara &z) {
  972. if(this != &z){
  973. delete [] place;
  974. place = new char[strlen(z.place)+1];
  975. dayPrice = z.dayPrice;
  976. }
  977. return *this;
  978. }
  979. int getPrice () {
  980. return dayPrice;
  981. }
  982. };
  983.  
  984. class PlaninarskiDom {
  985. private:
  986. char name[15];
  987. int prices [2];
  988. char clas;
  989. bool itHas;
  990. Zichara zichara;
  991. public:
  992. PlaninarskiDom() {
  993. itHas = false;
  994. }
  995. PlaninarskiDom (char *name, int *prices, char clas) {
  996. strcpy(this->name,name);
  997. for(int i=0; i<2; i++)
  998. this->prices[i] = prices[i];
  999. this->clas = clas;
  1000. }
  1001. ~PlaninarskiDom() {}
  1002. PlaninarskiDom& operator=(const PlaninarskiDom &p) {
  1003. if(this != &p){
  1004. strcpy(name,p.name);
  1005. for(int i=0; i<2; i++)
  1006. prices[i] = p.prices[i];
  1007. clas = p.clas;
  1008. itHas = p.itHas;
  1009. zichara = p.zichara;
  1010. }
  1011. return *this;
  1012. }
  1013. PlaninarskiDom& operator--() {
  1014. if(clas != 'F') {
  1015. ++clas;
  1016. }
  1017. return *this;
  1018. }
  1019. friend ostream& operator<< (ostream &out, PlaninarskiDom &p) {
  1020. out << p.name << " klasa:" << p.clas;
  1021. if(p.itHas)
  1022. out << " so Zichara" << endl;
  1023. else
  1024. out << endl;
  1025. return out;
  1026. }
  1027. bool operator <= (char znak) {
  1028. return clas > znak;
  1029. }
  1030. void setZichara (Zichara z) {
  1031. zichara = z;
  1032. itHas = true;
  1033. }
  1034. void presmetajDnevenPrestoj(int den, int mesec, int &cena) {
  1035. if(den < 1 || den > 31 || mesec < 1 || mesec > 12) {
  1036. throw 5;
  1037. }
  1038. if (itHas)
  1039. cena += zichara.getPrice();
  1040. if ((den >= 1&&mesec >= 4&&mesec < 9) || (mesec == 9&&den == 1)) {
  1041. cena += prices[0];
  1042. }
  1043. else {
  1044. cena += prices[1];
  1045. }
  1046. }
  1047. };
  1048.  
  1049. int main(){
  1050.  
  1051. PlaninarskiDom p; //креирање на нов објект од класата планинарски дом
  1052. //во следниот дел се вчитуваат информации за планинарскиот дом
  1053. char imePlaninarskiDom[15],mestoZichara[30],klasa;
  1054. int ceni[12];
  1055. int dnevnakartaZichara;
  1056. bool daliZichara;
  1057. cin>>imePlaninarskiDom;
  1058. for (int i=0;i<2;i++) cin>>ceni[i];
  1059. cin>>klasa;
  1060. cin>>daliZichara;
  1061.  
  1062. //во следниот дел се внесуваат информации и за жичарата ако постои
  1063. if (daliZichara) {
  1064. cin>>mestoZichara>>dnevnakartaZichara;
  1065. PlaninarskiDom pom(imePlaninarskiDom,ceni,klasa);
  1066. Zichara r(mestoZichara,dnevnakartaZichara);
  1067. pom.setZichara(r);
  1068. p=pom;
  1069. }
  1070. else{
  1071. PlaninarskiDom *pok=new PlaninarskiDom(imePlaninarskiDom,ceni,klasa);
  1072. p=*pok;
  1073. }
  1074.  
  1075. //се намалува класата на планинарскиот дом за 2
  1076. --p;
  1077. --p;
  1078.  
  1079. int cena;
  1080. int den,mesec;
  1081. cin>>den>>mesec;
  1082. try{
  1083. p.presmetajDnevenPrestoj(den,mesec,cena); //тука се користи функцијата presmetajDnevenPrestoj
  1084. cout<<"Informacii za PlaninarskiDomot:"<<endl;
  1085. cout<<p;
  1086. if (p<='D')
  1087. cout<<"Planinarskiot dom za koj se vneseni informaciite ima klasa poniska ili ista so D\n";
  1088.  
  1089. cout<<"Cenata za "<<den<<"."<<mesec<<" e "<<cena; //се печати цената за дадениот ден и месец
  1090. }
  1091. catch (int){
  1092. cout<<"Mesecot ili denot e greshno vnesen!";
  1093. }
  1094. }
  1095.  
  1096.  
  1097. 7. Фактура
  1098.  
  1099. #include <stdio.h>
  1100. #include <string.h>
  1101.  
  1102. typedef struct Proizvod
  1103. {
  1104. char productCode[20];
  1105. int price;
  1106. int productsInStore;
  1107. } Proizvod;
  1108.  
  1109. typedef struct Narachka
  1110. {
  1111. char name[15];
  1112. Proizvod p[10];
  1113. int productsOrdered[10];
  1114. int noProductsOrdered;
  1115. } Narachka;
  1116.  
  1117. void pecatiFaktura(Narachka n)
  1118. {
  1119. printf("Faktura za %s\n", n.name);
  1120. int i, j, total=0, flag, temp[10];
  1121. Proizvod tmp[20];
  1122. for(i=0; i<n.noProductsOrdered-1; i++)
  1123. {
  1124. for(j=i+1; j<n.noProductsOrdered; j++)
  1125. {
  1126. if(strcmp(n.p[i].productCode, n.p[j].productCode)>0)
  1127. {
  1128. tmp[i]=n.p[j];
  1129. n.p[j]=n.p[i];
  1130. n.p[i]=tmp[i];
  1131. }
  1132. }
  1133. }
  1134. for(i=0; i<n.noProductsOrdered; i++)
  1135. {
  1136. if(n.p[i].productsInStore>n.productsOrdered[i])
  1137. {
  1138. n.p[i].productsInStore=n.productsOrdered[i];
  1139. }
  1140. else
  1141. {
  1142. flag=0;
  1143. break;
  1144. }
  1145. }
  1146. if(flag)
  1147. {
  1148. for(i=0; i<n.noProductsOrdered; i++)
  1149. {
  1150. printf("%s %d %d %d\n", n.p[i].productCode, n.p[i].price, n.p[i].productsInStore, n.p[i].price*n.p[i].productsInStore);
  1151. total+=n.p[i].price*n.p[i].productsInStore;
  1152. }
  1153. printf("Vkupnata suma na fakturata e %d\n", total);
  1154.  
  1155. }
  1156. else
  1157. {
  1158. printf("Fakturata ne moze da se izgotvi\n");
  1159. }
  1160. }
  1161.  
  1162. int main() {
  1163.  
  1164. Narachka narachka;
  1165. scanf("%s", &narachka.name);
  1166. scanf("%d", &narachka.noProductsOrdered);
  1167. int i;
  1168. for (i=0; i<narachka.noProductsOrdered; ++i)
  1169. {
  1170. scanf("%s", &narachka.p[i].productCode);
  1171. scanf("%d", &narachka.p[i].price);
  1172. scanf("%d", &narachka.p[i].productsInStore);
  1173. }
  1174. int j;
  1175. for (j=0; j<narachka.noProductsOrdered; ++j)
  1176. {
  1177. scanf("%d", &narachka.productsOrdered[j]);
  1178. }
  1179. pecatiFaktura(narachka);
  1180. return 0;
  1181. }
  1182.  
  1183.  
  1184. 8. Воз
  1185.  
  1186. #include<iostream>
  1187. #include<cstring>
  1188. using namespace std;
  1189.  
  1190. class Patnik
  1191. {
  1192. private:
  1193. char name[100];
  1194. int classType;
  1195. bool bicycle;
  1196. public:
  1197. Patnik() {}
  1198. Patnik(const char *name, const int classType, const bool bicycle)
  1199. {
  1200. strcpy(this->name, name);
  1201. this->classType=classType;
  1202. this->bicycle=bicycle;
  1203. }
  1204. Patnik(const Patnik &r)
  1205. {
  1206. strcpy(name, r.name);
  1207. classType=r.classType;
  1208. bicycle=r.bicycle;
  1209. }
  1210. Patnik &operator=(const Patnik &r)
  1211. {
  1212. if(this!=&r)
  1213. {
  1214. strcpy(name, r.name);
  1215. classType=r.classType;
  1216. bicycle=r.bicycle;
  1217. }
  1218. return *this;
  1219. }
  1220. ~Patnik() {}
  1221. friend ostream &operator<<(ostream &out, const Patnik &o)
  1222. {
  1223. out<<o.name<<endl;
  1224. out<<o.classType<<endl;
  1225. out<<o.bicycle<<endl;
  1226. return out;
  1227. }
  1228. const int getClass() { return classType; }
  1229. const bool getBike() const { return bicycle; }
  1230. };
  1231.  
  1232. class Voz
  1233. {
  1234. private:
  1235. char destination[100];
  1236. Patnik *p;
  1237. int noPassengers, bicAllowed;
  1238. public:
  1239. Voz(const char *destination, const int bicAllowed)
  1240. {
  1241. strcpy(this->destination, destination);
  1242. this->bicAllowed=bicAllowed;
  1243. noPassengers=0;
  1244. p=NULL;
  1245. }
  1246. ~Voz() { delete [] p; }
  1247. Voz &operator+=(const Patnik &n)
  1248. {
  1249. Patnik *tmp=new Patnik[noPassengers+1];
  1250. for(int i=0; i<noPassengers; i++)
  1251. {
  1252. tmp[i]=p[i];
  1253. }
  1254. if(bicAllowed!=0&&n.getBike()==1)
  1255. {
  1256. tmp[noPassengers]=n;
  1257. noPassengers++;
  1258. }
  1259. else if(n.getBike()==0)
  1260. {
  1261. tmp[noPassengers]=n;
  1262. noPassengers++;
  1263. }
  1264. delete [] p;
  1265. p=tmp;
  1266. return *this;
  1267. }
  1268. friend ostream &operator<<(ostream &out, const Voz &o)
  1269. {
  1270. out<<o.destination<<endl;
  1271. for(int i=0; i<o.noPassengers; i++)
  1272. {
  1273. out<<o.p[i]<<endl;
  1274. }
  1275. return out;
  1276. }
  1277. void patniciNemaMesto()
  1278. {
  1279. int count1=0, count2=0;
  1280. for(int i=0; i<noPassengers; i++)
  1281. {
  1282. if(p[i].getClass()==1)
  1283. {
  1284. if(p[i].getBike())
  1285. {
  1286. count1++;
  1287. }
  1288. }
  1289. else
  1290. {
  1291. if(p[i].getBike())
  1292. {
  1293. count2++;
  1294. }
  1295. }
  1296. }
  1297. if(count1+count2<=bicAllowed)
  1298. {
  1299. count1=count2=0;
  1300. }
  1301. else if(count1>bicAllowed)
  1302. {
  1303. count1-=bicAllowed;
  1304. }
  1305. else if(count1<bicAllowed)
  1306. {
  1307. count1=bicAllowed-count1;
  1308. count2-=count1;
  1309. count1=0;
  1310. }
  1311. cout<<"Brojot na patnici od 1-va klasa koi ostanale bez mesto e: "<<count1<<endl;
  1312. cout<<"Brojot na patnici od 2-ra klasa koi ostanale bez mesto e: "<<count2<<endl;
  1313. }
  1314. };
  1315.  
  1316. int main()
  1317. {
  1318. Patnik p;
  1319. char ime[100], destinacija[100];
  1320. int n;
  1321. bool velosiped;
  1322. int klasa;
  1323. int maxv;
  1324. cin >> destinacija >> maxv;
  1325. cin >> n;
  1326. Voz v(destinacija, maxv);
  1327. //cout<<v<<endl;
  1328. for (int i = 0; i < n; i++){
  1329. cin >> ime >> klasa >> velosiped;
  1330. Patnik p(ime, klasa, velosiped);
  1331. //cout<<p<<endl;
  1332. v += p;
  1333. }
  1334. cout << v;
  1335. v.patniciNemaMesto();
  1336. return 0;
  1337. }
  1338.  
  1339.  
  1340. 9. Кабелски телевизии
  1341.  
  1342. #include <iostream>
  1343. #include <cstring>
  1344. using namespace std;
  1345.  
  1346. class TV
  1347. {
  1348. private:
  1349. char name[100];
  1350. bool type;
  1351. int category;
  1352. float rating;
  1353. public:
  1354. TV(const char *name="", const bool type=0, const int category=0, const float rating=0)
  1355. {
  1356. strcpy(this->name, name);
  1357. this->type=type;
  1358. this->category=category;
  1359. this->rating=rating;
  1360. }
  1361. TV(const TV &r)
  1362. {
  1363. strcpy(name, r.name);
  1364. type=r.type;
  1365. category=r.category;
  1366. rating=r.rating;
  1367. }
  1368. TV &operator=(const TV &r)
  1369. {
  1370. if(this!=&r)
  1371. {
  1372. strcpy(name, r.name);
  1373. type=r.type;
  1374. category=r.category;
  1375. rating=r.rating;
  1376. }
  1377. return *this;
  1378. }
  1379. ~TV() {}
  1380. friend ostream &operator<<(ostream &out, const TV &o)
  1381. {
  1382. out<<o.name<<endl;
  1383. if(o.type)
  1384. {
  1385. out<<"D"<<endl;
  1386. }
  1387. else
  1388. {
  1389. out<<"A"<<endl;
  1390. }
  1391. out<<o.category<<endl;
  1392. out<<o.rating<<endl;
  1393. return out;
  1394. }
  1395. bool operator==(const TV &r)
  1396. {
  1397. return (strcmp(name, r.name)==0&&type==r.type);
  1398. }
  1399. TV &operator++()
  1400. {
  1401. rating+=0.5;
  1402. return *this;
  1403. }
  1404. float getRating() const { return rating; }
  1405. };
  1406.  
  1407. class KabelskiOperator
  1408. {
  1409. private:
  1410. char name[100];
  1411. TV *p;
  1412. int noChannels;
  1413. public:
  1414. KabelskiOperator(const char *name)
  1415. {
  1416. strcpy(this->name, name);
  1417. p=NULL;
  1418. noChannels=0;
  1419. }
  1420. ~KabelskiOperator() { delete [] p; }
  1421. KabelskiOperator &operator+=(const TV &n)
  1422. {
  1423. if(n.getRating()>5)
  1424. {
  1425. TV *tmp=new TV[noChannels+1];
  1426. for(int i=0; i<noChannels; i++)
  1427. {
  1428. tmp[i]=p[i];
  1429. }
  1430. tmp[noChannels]=n;
  1431. delete [] p;
  1432. p=tmp;
  1433. noChannels++;
  1434. }
  1435. return *this;
  1436. }
  1437. friend ostream &operator<<(ostream &out, const KabelskiOperator &o)
  1438. {
  1439. out<<o.name<<endl;
  1440. for(int i=0; i<o.noChannels; i++)
  1441. {
  1442. out<<o.p[i]<<endl;
  1443. }
  1444. return out;
  1445. }
  1446. void zgolemi(const TV &tv)
  1447. {
  1448. for(int i=0; i<noChannels; i++)
  1449. {
  1450. if(p[i]==tv)
  1451. {
  1452. ++p[i];
  1453. break;
  1454. }
  1455. }
  1456. }
  1457. };
  1458.  
  1459. int main() {
  1460. int n, x;
  1461. cin >> n >> x;
  1462. char name[100];
  1463. cin >> name;
  1464. KabelskiOperator ko(name);
  1465. TV t;
  1466. for(int i = 0; i < n; ++i) {
  1467. char name[100];
  1468. bool digital;
  1469. int category;
  1470. float rating;
  1471. cin >> name >> digital >> category >> rating;
  1472. TV tv(name, digital, category, rating);
  1473. ko += tv;
  1474. if(i == x) {
  1475. t = tv;
  1476. }
  1477. }
  1478. cout << ko;
  1479. cout << "=== ZGOLEMI ===" << endl;
  1480. cout << t;
  1481. ko.zgolemi(t);
  1482. cout << ko;
  1483. return 0;
  1484. }
  1485.  
  1486.  
  1487. 10. Работни часови
  1488.  
  1489. #include <stdio.h>
  1490. #include <string.h>
  1491. #define NEDELI 4
  1492. #define DENOVI 5
  1493.  
  1494. typedef struct RabotnaNedela
  1495. {
  1496. int casovi[DENOVI];
  1497. int weekNo;
  1498. }RN;
  1499.  
  1500. typedef struct Rabotnik
  1501. {
  1502. char ime[50];
  1503. RN nedeli[NEDELI];
  1504. }R;
  1505.  
  1506. int maxNedela(R *s)
  1507. {
  1508. int i, j, max=0, index, hoursWorked=0;
  1509. for(i=0; i<NEDELI; i++)
  1510. {
  1511. for(j=0; j<DENOVI; j++)
  1512. {
  1513. hoursWorked+=s->nedeli[i].casovi[j];
  1514. }
  1515. if(hoursWorked>max)
  1516. {
  1517. max=hoursWorked;
  1518. index=i;
  1519. }
  1520. hoursWorked=0;
  1521. }
  1522. return index+1;
  1523. }
  1524.  
  1525. void table(R *s, int n)
  1526. {
  1527. int i, j, k;
  1528. printf("Rab\t%d\t%d\t%d\t%d\tVkupno\n", 1, 2, 3, 4);
  1529. for(i=0; i<n; i++)
  1530. {
  1531. int addDays[NEDELI]={0};
  1532. for(j=0; j<NEDELI; j++)
  1533. {
  1534. for(k=0; k<DENOVI; k++)
  1535. {
  1536. addDays[j]+=s[i].nedeli[j].casovi[k];
  1537. }
  1538. }
  1539. int total=addDays[0]+addDays[1]+addDays[2]+addDays[3];
  1540. printf("%s\t%d\t%d\t%d\t%d\t%d\n", s[i].ime, addDays[0], addDays[1], addDays[2], addDays[3], total);
  1541.  
  1542. }
  1543. }
  1544.  
  1545. int main() {
  1546. int n;
  1547. scanf("%d", &n);
  1548. R rabotnici[n];
  1549. int i;
  1550. for (i = 0; i < n; ++i) {
  1551. scanf("%s", rabotnici[i].ime);
  1552. int j;
  1553. for (j = 0; j < NEDELI; ++j) {
  1554. int k;
  1555. for (k = 0; k < DENOVI; ++k) {
  1556. scanf("%d", &rabotnici[i].nedeli[j].casovi[k]);
  1557. }
  1558.  
  1559. }
  1560. }
  1561. printf("TABLE\n");
  1562. table(rabotnici, n);
  1563. printf("MAX NEDELA NA RABOTNIK: %s\n", rabotnici[n / 2].ime);
  1564. printf("%d\n", maxNedela(&rabotnici[n / 2]));
  1565. return 0;
  1566. }
  1567.  
  1568.  
  1569. 11. Танчери
  1570.  
  1571. #include <iostream>
  1572. #include <cstring>
  1573. using namespace std;
  1574. struct Tanc{
  1575. char ime[15], zemja[15];
  1576. };
  1577.  
  1578. struct Tancer{
  1579. char ime[20], prezime[20];
  1580. Tanc niza[5];
  1581. };
  1582.  
  1583. void tancuvanje(Tancer *t, int n, char *zemja)
  1584. {
  1585. int i, j, indexI, indexJ;
  1586. int count[n];
  1587. for(i=0;i<n;i++)
  1588. {
  1589. count[i]=0;
  1590. for(j=0; j<3; j++)
  1591. {
  1592. if(strcmp(zemja, t[i].niza[j].zemja)==0)
  1593. count[i]++;
  1594. }
  1595. }
  1596. for(i=0; i<n; i++)
  1597. {
  1598. for(j=0; j<3; j++)
  1599. {
  1600. if(count[i]==1)
  1601. {
  1602. if(strcmp(zemja, t[i].niza[j].zemja)==0)
  1603. {
  1604. cout<<t[i].ime<<" "<<t[i].prezime<<", "<<t[i].niza[j].ime<<endl;
  1605. indexI=i;
  1606. indexJ=j;
  1607. }
  1608. }
  1609. if(count[i]==2)
  1610. {
  1611. if(strcmp(zemja, t[i].niza[j].zemja)==0)
  1612. if(strcmp(t[i].niza[j].ime, t[indexI].niza[indexJ].ime)==0)
  1613. cout<<t[i].ime<<" "<<t[i].prezime<<", "<<t[i].niza[j].ime<<endl;
  1614. }
  1615. }
  1616. }
  1617. }
  1618. int main()
  1619. {
  1620. int n,i,j;
  1621. Tancer t[10];
  1622. cin>>n;
  1623. for(i=0;i<n;i++){
  1624. cin>>t[i].ime;
  1625. cin>>t[i].prezime;
  1626. for(j=0;j<3;j++){
  1627. cin>>t[i].niza[j].ime;
  1628. cin>>t[i].niza[j].zemja;
  1629. }
  1630. }
  1631. char zemja[15];
  1632. cin>>zemja;
  1633. tancuvanje(t,n,zemja);
  1634. return 0;
  1635. }
  1636.  
  1637.  
  1638. 13. Работни часови (40 поени)
  1639.  
  1640. #include <stdio.h>
  1641. #include <string.h>
  1642. #define NEDELI 4
  1643. #define DENOVI 5
  1644.  
  1645. typedef struct RabotnaNedela
  1646. {
  1647. int casovi[DENOVI];
  1648. int weekNo;
  1649. }RN;
  1650.  
  1651. typedef struct Rabotnik
  1652. {
  1653. char ime[50];
  1654. RN nedeli[NEDELI];
  1655. }R;
  1656.  
  1657. int maxNedela(R *s)
  1658. {
  1659. int i, j, max=0, index, hoursWorked=0;
  1660. for(i=0; i<NEDELI; i++)
  1661. {
  1662. for(j=0; j<DENOVI; j++)
  1663. {
  1664. hoursWorked+=s->nedeli[i].casovi[j];
  1665. }
  1666. if(hoursWorked>max)
  1667. {
  1668. max=hoursWorked;
  1669. index=i;
  1670. }
  1671. hoursWorked=0;
  1672. }
  1673. return index+1;
  1674. }
  1675.  
  1676. void table(R *s, int n)
  1677. {
  1678. int i, j, k;
  1679. printf("Rab\t%d\t%d\t%d\t%d\tVkupno\n", 1, 2, 3, 4);
  1680. for(i=0; i<n; i++)
  1681. {
  1682. int addDays[NEDELI]={0};
  1683. for(j=0; j<NEDELI; j++)
  1684. {
  1685. for(k=0; k<DENOVI; k++)
  1686. {
  1687. addDays[j]+=s[i].nedeli[j].casovi[k];
  1688. }
  1689. }
  1690. int total=addDays[0]+addDays[1]+addDays[2]+addDays[3];
  1691. printf("%s\t%d\t%d\t%d\t%d\t%d\n", s[i].ime, addDays[0], addDays[1], addDays[2], addDays[3], total);
  1692.  
  1693. }
  1694. }
  1695.  
  1696. int main() {
  1697. int n;
  1698. scanf("%d", &n);
  1699. R rabotnici[n];
  1700. int i;
  1701. for (i = 0; i < n; ++i) {
  1702. scanf("%s", rabotnici[i].ime);
  1703. int j;
  1704. for (j = 0; j < NEDELI; ++j) {
  1705. int k;
  1706. for (k = 0; k < DENOVI; ++k) {
  1707. scanf("%d", &rabotnici[i].nedeli[j].casovi[k]);
  1708. }
  1709.  
  1710. }
  1711. }
  1712. printf("TABLE\n");
  1713. table(rabotnici, n);
  1714. printf("MAX NEDELA NA RABOTNIK: %s\n", rabotnici[n / 2].ime);
  1715. printf("%d\n", maxNedela(&rabotnici[n / 2]));
  1716. return 0;
  1717. }
  1718.  
  1719.  
  1720.  
  1721. 14. Структура во C
  1722.  
  1723. #include<stdio.h>
  1724. typedef struct Pacient{
  1725. char ime[100];
  1726. int zdravstveno,pregledi;
  1727. }Pacient;
  1728.  
  1729. typedef struct MaticenDoktor{
  1730. char ime[100];
  1731. int br_pac,brpregledi;
  1732. Pacient niza[200];
  1733. float cena,zarabotka;
  1734. }doktor;
  1735.  
  1736. void najuspesen_doktor(doktor a[],int n){
  1737. int i,j;
  1738.  
  1739. for(i=0;i<n;i++){
  1740. for(j=0;j<a[i].br_pac;j++){
  1741. if(a[i].niza[j].zdravstveno==0){
  1742. a[i].zarabotka+=a[i].cena*a[i].niza[j].pregledi;
  1743. }
  1744. a[i].brpregledi+=a[i].niza[j].pregledi;
  1745. }
  1746. }
  1747. doktor najdobar=a[0];
  1748. for(i=0;i<n;i++){
  1749. if(a[i].zarabotka==najdobar.zarabotka){
  1750. if(a[i].brpregledi>najdobar.brpregledi)
  1751. najdobar=a[i];
  1752. }
  1753. }
  1754. printf("%s %.2f %d",najdobar.ime,najdobar.zarabotka,najdobar.brpregledi);
  1755. }
  1756.  
  1757. int main()
  1758. {
  1759. int i, j, n, broj;
  1760. doktor md[200];
  1761. scanf("%d", &n);
  1762. for (i = 0; i < n; i++){
  1763. //ime na doktor
  1764. scanf("%s", md[i].ime);
  1765. //broj na pacienti
  1766. scanf("%d", &md[i].br_pac);
  1767. //cena na pregled
  1768. scanf("%f", &md[i].cena);
  1769.  
  1770. md[i].zarabotka=0,md[i].brpregledi=0;
  1771.  
  1772. for (j = 0; j < md[i].br_pac; j++){
  1773. scanf("%s", md[i].niza[j].ime);
  1774. scanf("%d", &md[i].niza[j].zdravstveno);
  1775. scanf("%d", &md[i].niza[j].pregledi);
  1776. }
  1777. }
  1778. najuspesen_doktor(md, n);
  1779.  
  1780. return 0;
  1781. }
  1782.  
  1783.  
  1784. 15. Акции
  1785.  
  1786. #include<iostream>
  1787. #include<cstring>
  1788.  
  1789. using namespace std;
  1790.  
  1791. // vasiot kod za klasite ovde
  1792. class StockRecord{
  1793. private:
  1794. char ID[12];
  1795. char kompanija[50];
  1796. float cena_spored_koja;
  1797. float momentalna_cena;
  1798. int br_akcii;
  1799. public:
  1800. StockRecord(char *ID="", char *kompanija="", float cena_spored_koja=0.0, int br_akcii=0){
  1801. strcpy(this->ID, ID);
  1802. strcpy(this->kompanija, kompanija);
  1803. this->cena_spored_koja=cena_spored_koja;
  1804. this->br_akcii=br_akcii;
  1805. this->momentalna_cena=0;
  1806. }
  1807. void setNewPrice(double c){
  1808. this->momentalna_cena=c;
  1809. }
  1810. double value(){
  1811. double res=0.0;
  1812. res=br_akcii*momentalna_cena;
  1813. return res;
  1814. }
  1815. double profit(){
  1816. double res=0.0;
  1817. res=br_akcii*(momentalna_cena-cena_spored_koja);
  1818. return res;
  1819. }
  1820. friend ostream& operator<<(ostream& out, StockRecord &sr){
  1821. return out<<sr.kompanija<<" "<<sr.br_akcii<<" "<<sr.cena_spored_koja<<" "<<sr.momentalna_cena<<" "<<sr.profit()<<endl;
  1822. }
  1823. };
  1824.  
  1825. class Client{
  1826. private:
  1827. char clientName[60];
  1828. int clientID;
  1829. StockRecord *kompanii;
  1830. int n;
  1831. public:
  1832. Client (char *clientName="", int clientID=0){
  1833. strcpy(this->clientName, clientName);
  1834. this->clientID=clientID;
  1835. this->kompanii=new StockRecord[50];
  1836. this->n=0;
  1837. }
  1838. double totalValue(){
  1839. double sum=0.0;
  1840. for(int i=0;i<n;++i){
  1841. sum+=kompanii[i].value();
  1842. }
  1843. return sum;
  1844. }
  1845. Client& operator+= (StockRecord &sr){
  1846. kompanii[n]=sr;
  1847. ++n;
  1848. return *this;
  1849. }
  1850. friend ostream& operator<< (ostream& out, Client &c){
  1851. out<<c.clientID<<" "<<c.totalValue()<<endl;
  1852. for(int i=0;i<c.n;++i){
  1853. out<<c.kompanii[i];
  1854. }
  1855. return out;
  1856. }
  1857. };
  1858.  
  1859. // ne menuvaj vo main-ot
  1860.  
  1861. int main(){
  1862.  
  1863. int test;
  1864. cin >> test;
  1865.  
  1866. if(test == 1){
  1867. double price;
  1868. cout << "=====TEST NA KLASATA StockRecord=====" << endl;
  1869. StockRecord sr("1", "Microsoft", 60.0, 100);
  1870. cout << "Konstruktor OK" << endl;
  1871. cin >> price;
  1872. sr.setNewPrice(price);
  1873. cout << "SET metoda OK" << endl;
  1874. }
  1875. else if(test == 2){
  1876. cout << "=====TEST NA METODITE I OPERATOR << OD KLASATA StockRecord=====" << endl;
  1877. char id[12], company[50];
  1878. double price, newPrice;
  1879. int n, shares;
  1880. cin >> n;
  1881. for(int i = 0; i < n; ++i){
  1882. cin >> id;
  1883. cin >> company;
  1884. cin >> price;
  1885. cin >> newPrice;
  1886. cin >> shares;
  1887. StockRecord sr(id, company, price, shares);
  1888. sr.setNewPrice(newPrice);
  1889. cout << sr.value() << endl;
  1890. cout << sr;
  1891. }
  1892. }
  1893. else if(test == 3){
  1894. cout << "=====TEST NA KLASATA Client=====" << endl;
  1895. char companyID[12], companyName[50], clientName[50];
  1896. int clientID, n, shares;
  1897. double oldPrice, newPrice;
  1898. bool flag = true;
  1899. cin >> clientName;
  1900. cin >> clientID;
  1901. cin >> n;
  1902. Client c(clientName, clientID);
  1903. cout << "Konstruktor OK" << endl;
  1904. for(int i = 0; i < n; ++i){
  1905. cin >> companyID;
  1906. cin >> companyName;
  1907. cin >> oldPrice;
  1908. cin >> newPrice;
  1909. cin >> shares;
  1910. StockRecord sr(companyID, companyName, oldPrice, shares);
  1911. sr.setNewPrice(newPrice);
  1912. c += sr;
  1913. if(flag){
  1914. cout << "Operator += OK" << endl;
  1915. flag = false;
  1916. }
  1917. }
  1918. cout << c;
  1919. cout << "Operator << OK" << endl;
  1920. }
  1921. return 0;
  1922.  
  1923. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement