结构podataka-Zadataku 1-Glavniu计划

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了结构podataka-Zadataku 1-Glavniu计划相关的知识,希望对你有一定的参考价值。

Glavni dio programa"Životinjska_farma"

Ovaj program se ističe od sličnih riješenja više s svojim vizualnim izričajem no samim načinom riješavanja zadatka.
Razlog tome je prije svega Å¡to je velik broj studenata dobio isti zadatak.
  1. #include <iostream>
  2. #include <cstring>
  3. #include <windows.h>
  4. #include "l_polj.h"
  5. //#include "l_pok.h"
  6. using namespace std;
  7. //_______________________________________________________________________________________________
  8. void last_to_st() {
  9. HANDLE hConsole;
  10. hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
  11. elem a;
  12. int k=0;
  13. int p = PreviousL(EndL(list),list);
  14. while(k<br_elem){
  15. a=RetrieveL(p,list);
  16. SetConsoleTextAttribute(hConsole, 12);
  17. cout<<" ________________________________________________________________________________ ";
  18. SetConsoleTextAttribute(hConsole, 15);
  19. cout<<" Sifra:"<<a.sifra<<endl;
  20. cout<<" Vrsta:"<<a.vrsta<<endl;
  21. cout<<" Naziv:"<<a.naziv<<endl;
  22. cout<<" Cijena:"<<a.cijena<<endl;
  23. cout<<" Datum:"<<a.date.d<<".";
  24. cout<<a.date.m<<"."<<a.date.y<<". ";
  25. SetConsoleTextAttribute(hConsole, 12);
  26. cout<<" ________________________________________________________________________________ ";
  27. SetConsoleTextAttribute(hConsole, 15);
  28. p = PreviousL(p,list);
  29. k++;
  30. }
  31. }
  32.  
  33. //_______________________________________________________________________________________________
  34. void after_date() {
  35. HANDLE hConsole;
  36. hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
  37. int numero=0;
  38. elem a;
  39. int p = FirstL(list);
  40. while(p!=EndL(list)) {
  41. a = RetrieveL(p,list);
  42. if(a.date.y>=2012)
  43. if((!strcmp(a.date.m,"rujan")&&a.date.d>23)||!strcmp(a.date.m,"listopad")||
  44. !strcmp(a.date.m,"studeni")||!strcmp(a.date.m,"prosinac")) {
  45. numero++;
  46. SetConsoleTextAttribute(hConsole, 12);
  47. cout<<" ________________________________________________________________________________ ";
  48. SetConsoleTextAttribute(hConsole, 15);
  49. cout<<" Sifra:"<<a.sifra<<endl;
  50. cout<<" Vrsta:"<<a.vrsta<<endl;
  51. cout<<" Naziv:"<<a.naziv<<endl;
  52. cout<<" Cijena:"<<a.cijena<<endl;
  53. cout<<" Datum:"<<a.date.d<<"."<<a.date.m<<"."<<a.date.y<<". ";
  54. SetConsoleTextAttribute(hConsole, 12);
  55. cout<<" ________________________________________________________________________________ ";
  56. SetConsoleTextAttribute(hConsole, 15);
  57. }
  58. p = NextL(p,list);
  59. }
  60. SetConsoleTextAttribute(hConsole, 10);
  61. cout<<" Broj pronadenih zivotinja:"<<numero<<" ";
  62. SetConsoleTextAttribute(hConsole, 15);
  63. }
  64.  
  65.  
  66. //_______________________________________________________________________________________________
  67. int spawn_new_creature() {
  68. HANDLE hConsole;
  69. hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
  70. elem novi;
  71. novi.sifra=sifra++;
  72. SetConsoleTextAttribute(hConsole, 12);
  73. cout<<" ________________________________________________________________________________ ";
  74. SetConsoleTextAttribute(hConsole, 15);
  75. cout<<" Vrsta:";
  76. cin.ignore();
  77. cin.getline(novi.vrsta,50);
  78. cout<<" Naziv:";
  79. cin.getline(novi.naziv,50);
  80. cout<<" Cijena:";cin>>novi.cijena;
  81. if(novi.cijena<=0) {sifra--;return 0;}
  82. cout<<" Unesite datum dostave: ";
  83. cout<<" Dan:";cin>>novi.date.d;
  84. if(novi.date.d<=0||novi.date.d>31) {sifra--;return 0;}
  85. cout<<" Mjesec:";
  86. cin.ignore();
  87. cin.getline(novi.date.m,10);
  88. if(novi.date.d>29&&!strcmp(novi.date.m,"veljaca")) {sifra--;return 0;}
  89. cout<<" Godina:";cin>>novi.date.y;
  90. if(novi.date.y<1523||novi.date.y>2023) {sifra--;return 0;}
  91. InsertL(novi,br_elem,list);
  92. br_elem++;
  93. SetConsoleTextAttribute(hConsole, 12);
  94. cout<<" ________________________________________________________________________________ ";
  95. SetConsoleTextAttribute(hConsole, 15);
  96. return 1;
  97. }
  98.  
  99. //_______________________________________________________________________________________________
  100. int del_name() {
  101. HANDLE hConsole;
  102. hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
  103. char naziv[50];
  104. SetConsoleTextAttribute(hConsole, 12);
  105. cout<<" ________________________________________________________________________________ ";
  106. SetConsoleTextAttribute(hConsole, 15);
  107. cout<<" Unesite naziv zivotinje:";
  108. cin.ignore();
  109. cin.getline(naziv,50);
  110. SetConsoleTextAttribute(hConsole, 12);
  111. cout<<" ________________________________________________________________________________ ";
  112. SetConsoleTextAttribute(hConsole, 15);
  113. int stuff = LocateL(naziv,list);
  114. if(stuff==EndL(list)) return 0;
  115. else {
  116. DeleteL(stuff,list);
  117. br_elem--;
  118. return 1;
  119. }
  120. }
  121.  
  122. //_______________________________________________________________________________________________
  123. int del_spi() {
  124. HANDLE hConsole;
  125. hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
  126. char vrsta[50];
  127. int stuff;
  128. bool obrisan=0;
  129. v=1;
  130. SetConsoleTextAttribute(hConsole, 12);
  131. cout<<" ________________________________________________________________________________ ";
  132. SetConsoleTextAttribute(hConsole, 15);
  133. cout<<" Unesite vrstu zivotinje:";
  134. cin.ignore();
  135. cin.getline(vrsta,35);
  136. SetConsoleTextAttribute(hConsole, 12);
  137. cout<<" ________________________________________________________________________________ ";
  138. SetConsoleTextAttribute(hConsole, 15);
  139. while (LocateL(vrsta,list)!=EndL(list)) {
  140. stuff = LocateL(vrsta,list);
  141. DeleteL(stuff,list);
  142. br_elem--;
  143. obrisan=1;
  144. }
  145. v=0;
  146. if(!obrisan) return 0;
  147. else return 1;
  148. }
  149.  
  150. //_______________________________________________________________________________________________
  151. void output() {
  152. HANDLE hConsole;
  153. hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
  154. elem a;
  155. int p=FirstL(list);
  156. while (p!=EndL(list)){
  157. a=RetrieveL(p,list);
  158. SetConsoleTextAttribute(hConsole, 12);
  159. cout<<" ________________________________________________________________________________ ";
  160. SetConsoleTextAttribute(hConsole, 15);
  161. cout<<" Sifra: "<<a.sifra<<endl;
  162. cout<<" Vrsta: "<<a.vrsta<<endl;
  163. cout<<" Naziv: "<<a.naziv<<endl;
  164. cout<<" Cijena: "<<a.cijena<<endl;
  165. cout<<" Datum: "<<a.date.d<<".";
  166. cout<<a.date.m<<"."<<a.date.y<<". ";
  167. SetConsoleTextAttribute(hConsole, 12);
  168. cout<<" ________________________________________________________________________________ ";
  169. SetConsoleTextAttribute(hConsole, 15);
  170. p = NextL(p,list);
  171. }
  172. }
  173.  
  174. //_______________________________________________________________________________________________
  175. void spoji(int truble, int wub_wub, int buble) {
  176. int I=truble, J=buble+1, K=0;
  177. elem *b = new elem [buble-truble+1];
  178. elem prvi,drugi;
  179.  
  180. while(I<=wub_wub && J<=buble){
  181.  
  182. prvi=RetrieveL(I,list);
  183. drugi=RetrieveL(J,list);
  184.  
  185. if(prvi.cijena > drugi.cijena) {
  186. b[K++]=prvi;
  187. I++;
  188. }
  189.  
  190. else if(prvi.cijena < drugi.cijena){
  191. b[K++]=drugi;
  192. J++;
  193. }
  194. else if(strcmp(prvi.naziv,drugi.naziv)==-1) {
  195. b[K++]=drugi;
  196. J++;
  197. }
  198. else {
  199. b[K++]=prvi;
  200. I++;
  201. }
  202. }
  203.  
  204. if(I>wub_wub) while(J<=buble) {
  205. drugi=RetrieveL(J,list);
  206. b[K++] = drugi;
  207. J++;
  208. }
  209.  
  210. else while(I<=wub_wub) {
  211. prvi=RetrieveL(I,list);
  212. b[K++] = prvi;
  213. I++;
  214. }
  215.  
  216. for(int I=0;I<=buble-truble;I++)Return(b[I],truble+I,list);
  217.  
  218. delete [] b;
  219. }
  220.  
  221. //_______________________________________________________________________________________________
  222. void msort(int truble, int buble) {
  223. if(truble<buble) {
  224. int wub_wub=(truble+buble)/2;
  225. msort(truble,wub_wub);
  226. msort(wub_wub+1,buble);
  227. spoji(truble,buble,wub_wub);
  228. }
  229. }
  230.  
  231. //_______________________________________________________________________________________________
  232. void msort() {
  233. msort(0,br_elem-1);
  234. }
  235.  
  236. int main() {
  237. HANDLE hConsole;
  238. hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
  239.  
  240. SetConsoleTextAttribute(hConsole, 12);
  241. cout<<" N";
  242. SetConsoleTextAttribute(hConsole, 11);
  243. cout<<"Y";
  244. SetConsoleTextAttribute(hConsole, 10);
  245. cout<<"A";
  246. SetConsoleTextAttribute(hConsole, 15);
  247. cout<<"N ";
  248. SetConsoleTextAttribute(hConsole, 12);
  249. cout<<"C";
  250. SetConsoleTextAttribute(hConsole, 11);
  251. cout<<"O";
  252. SetConsoleTextAttribute(hConsole, 10);
  253. cout<<"R";
  254. SetConsoleTextAttribute(hConsole, 15);
  255. cout<<"P ";
  256. //_____________________________START____________________________________________________________
  257. int choice=9001;
  258. InitL(list);
  259. do {
  260.  
  261.  
  262. HANDLE hConsole;
  263. hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
  264.  
  265.  
  266.  
  267. // cout<<" <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<Izbornik>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>";
  268. SetConsoleTextAttribute(hConsole, 12);
  269. cout<<" _____________________________________Izbornik___________________________________";
  270. SetConsoleTextAttribute(hConsole, 15);
  271. cout<<" | [1] Dodaj zivotinju. |";
  272. cout<<" | [2] Ispis od zadnje dodane zivotinje do prvo dodane. |";
  273. cout<<" | [3] Ispis dodanih zivotinja koje su dostavljene nakon 23.9.2012. |";
  274. cout<<" | [4] Brisanje unesenih zivotinja [naziv]. |";
  275. cout<<" | [5] Brisanje unesenih zivotinja [vrsta]. |";
  276. cout<<" | [6] Silazno sortiranje [naziv/cijena]. |";
  277. cout<<" | [7] Clear screen. (brisanje prethodnog ispisa sa ekrana) |";
  278. cout<<" | [0] Zatvaranje programa. |";
  279. cout<<" |___________________________________________________________________|";
  280. SetConsoleTextAttribute(hConsole, 12);
  281. cout<<" ________________________________________________________________________________ ";
  282. SetConsoleTextAttribute(hConsole, 15);
  283. cout<<" Izbor[0-7]:";
  284. cin>>choice;
  285. cout<<" ";
  286.  
  287. switch(choice) {
  288. //_______________________________________________________________________________________________
  289. case 1:
  290. if(spawn_new_creature())
  291. {
  292. SetConsoleTextAttribute(hConsole, 10);
  293. cout<<" Zapis je uspjesno dodan. ";
  294. SetConsoleTextAttribute(hConsole, 15);
  295. }
  296. else
  297. { SetConsoleTextAttribute(hConsole, 12);
  298. cout<<" <<Error!>> ";
  299. SetConsoleTextAttribute(hConsole, 15);
  300. cout<< "Pogresan unos!";
  301. }
  302. break;
  303. //_______________________________________________________________________________________________
  304. case 2:last_to_st();
  305.  
  306. break;
  307. //_______________________________________________________________________________________________
  308. case 3:after_date();
  309.  
  310. break;
  311. //_______________________________________________________________________________________________
  312. case 4:
  313. if(del_name()) {
  314.  
  315. SetConsoleTextAttribute(hConsole, 10);
  316. cout<<" Trazena zivotinja je obrisana. ";
  317. SetConsoleTextAttribute(hConsole, 15);
  318. output();
  319. }
  320. else
  321. { SetConsoleTextAttribute(hConsole, 12);
  322. cout<<" <<Error!>> ";
  323. SetConsoleTextAttribute(hConsole, 15);
  324. cout<<"Trazena zivotinja nije obrisana. Zivotinja pod tim nazivom ne postoji u zapisu. ";
  325. }
  326. break;
  327. //_______________________________________________________________________________________________
  328. case 5:
  329. if(del_spi()) {
  330.  
  331. SetConsoleTextAttribute(hConsole, 10);
  332. cout<<" Trazena vrsta je obrisana. ";
  333. SetConsoleTextAttribute(hConsole, 15);
  334. output();
  335. }
  336. else
  337. { SetConsoleTextAttribute(hConsole, 12);
  338. cout<<" <<Error!>> ";
  339. SetConsoleTextAttribute(hConsole, 15);
  340. cout<<"Trazena vrsta nije obrisana. Vrsta ne postoji u zapisu.. ";
  341. }
  342. break;
  343.  
  344. //_______________________________________________________________________________________________
  345. case 6:
  346. msort();
  347. output();
  348.  
  349. break;
  350.  
  351. case 7:
  352. system("cls");
  353.  
  354. break;
  355. }
  356. }while(choice!=0);
  357. DeleteAll(list);
  358.  
  359. system("pause");
  360. return 0;
  361. }
  362.  
  363.  
  364. //made by Mugo

以上是关于结构podataka-Zadataku 1-Glavniu计划的主要内容,如果未能解决你的问题,请参考以下文章

什么是网站的扁平结构与树形结构

golang中级进阶(二):结构体

数据结构有哪些分类呢?

哈佛结构是否比冯诺依曼结构要好?

数据结构哪些是四种常见的逻辑结构

数据结构 -- 结构体Struct