结构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.
#include <iostream> #include <cstring> #include <windows.h> #include "l_polj.h" //#include "l_pok.h" using namespace std; //_______________________________________________________________________________________________ void last_to_st() { HANDLE hConsole; hConsole = GetStdHandle(STD_OUTPUT_HANDLE); elem a; int k=0; int p = PreviousL(EndL(list),list); while(k<br_elem){ a=RetrieveL(p,list); SetConsoleTextAttribute(hConsole, 12); cout<<" ________________________________________________________________________________ "; SetConsoleTextAttribute(hConsole, 15); cout<<" Sifra:"<<a.sifra<<endl; cout<<" Vrsta:"<<a.vrsta<<endl; cout<<" Naziv:"<<a.naziv<<endl; cout<<" Cijena:"<<a.cijena<<endl; cout<<" Datum:"<<a.date.d<<"."; cout<<a.date.m<<"."<<a.date.y<<". "; SetConsoleTextAttribute(hConsole, 12); cout<<" ________________________________________________________________________________ "; SetConsoleTextAttribute(hConsole, 15); p = PreviousL(p,list); k++; } } //_______________________________________________________________________________________________ void after_date() { HANDLE hConsole; hConsole = GetStdHandle(STD_OUTPUT_HANDLE); int numero=0; elem a; int p = FirstL(list); while(p!=EndL(list)) { a = RetrieveL(p,list); if(a.date.y>=2012) if((!strcmp(a.date.m,"rujan")&&a.date.d>23)||!strcmp(a.date.m,"listopad")|| !strcmp(a.date.m,"studeni")||!strcmp(a.date.m,"prosinac")) { numero++; SetConsoleTextAttribute(hConsole, 12); cout<<" ________________________________________________________________________________ "; SetConsoleTextAttribute(hConsole, 15); cout<<" Sifra:"<<a.sifra<<endl; cout<<" Vrsta:"<<a.vrsta<<endl; cout<<" Naziv:"<<a.naziv<<endl; cout<<" Cijena:"<<a.cijena<<endl; cout<<" Datum:"<<a.date.d<<"."<<a.date.m<<"."<<a.date.y<<". "; SetConsoleTextAttribute(hConsole, 12); cout<<" ________________________________________________________________________________ "; SetConsoleTextAttribute(hConsole, 15); } p = NextL(p,list); } SetConsoleTextAttribute(hConsole, 10); cout<<" Broj pronadenih zivotinja:"<<numero<<" "; SetConsoleTextAttribute(hConsole, 15); } //_______________________________________________________________________________________________ int spawn_new_creature() { HANDLE hConsole; hConsole = GetStdHandle(STD_OUTPUT_HANDLE); elem novi; novi.sifra=sifra++; SetConsoleTextAttribute(hConsole, 12); cout<<" ________________________________________________________________________________ "; SetConsoleTextAttribute(hConsole, 15); cout<<" Vrsta:"; cin.ignore(); cin.getline(novi.vrsta,50); cout<<" Naziv:"; cin.getline(novi.naziv,50); cout<<" Cijena:";cin>>novi.cijena; if(novi.cijena<=0) {sifra--;return 0;} cout<<" Unesite datum dostave: "; cout<<" Dan:";cin>>novi.date.d; if(novi.date.d<=0||novi.date.d>31) {sifra--;return 0;} cout<<" Mjesec:"; cin.ignore(); cin.getline(novi.date.m,10); if(novi.date.d>29&&!strcmp(novi.date.m,"veljaca")) {sifra--;return 0;} cout<<" Godina:";cin>>novi.date.y; if(novi.date.y<1523||novi.date.y>2023) {sifra--;return 0;} InsertL(novi,br_elem,list); br_elem++; SetConsoleTextAttribute(hConsole, 12); cout<<" ________________________________________________________________________________ "; SetConsoleTextAttribute(hConsole, 15); return 1; } //_______________________________________________________________________________________________ int del_name() { HANDLE hConsole; hConsole = GetStdHandle(STD_OUTPUT_HANDLE); char naziv[50]; SetConsoleTextAttribute(hConsole, 12); cout<<" ________________________________________________________________________________ "; SetConsoleTextAttribute(hConsole, 15); cout<<" Unesite naziv zivotinje:"; cin.ignore(); cin.getline(naziv,50); SetConsoleTextAttribute(hConsole, 12); cout<<" ________________________________________________________________________________ "; SetConsoleTextAttribute(hConsole, 15); int stuff = LocateL(naziv,list); if(stuff==EndL(list)) return 0; else { DeleteL(stuff,list); br_elem--; return 1; } } //_______________________________________________________________________________________________ int del_spi() { HANDLE hConsole; hConsole = GetStdHandle(STD_OUTPUT_HANDLE); char vrsta[50]; int stuff; bool obrisan=0; v=1; SetConsoleTextAttribute(hConsole, 12); cout<<" ________________________________________________________________________________ "; SetConsoleTextAttribute(hConsole, 15); cout<<" Unesite vrstu zivotinje:"; cin.ignore(); cin.getline(vrsta,35); SetConsoleTextAttribute(hConsole, 12); cout<<" ________________________________________________________________________________ "; SetConsoleTextAttribute(hConsole, 15); while (LocateL(vrsta,list)!=EndL(list)) { stuff = LocateL(vrsta,list); DeleteL(stuff,list); br_elem--; obrisan=1; } v=0; if(!obrisan) return 0; else return 1; } //_______________________________________________________________________________________________ void output() { HANDLE hConsole; hConsole = GetStdHandle(STD_OUTPUT_HANDLE); elem a; int p=FirstL(list); while (p!=EndL(list)){ a=RetrieveL(p,list); SetConsoleTextAttribute(hConsole, 12); cout<<" ________________________________________________________________________________ "; SetConsoleTextAttribute(hConsole, 15); cout<<" Sifra: "<<a.sifra<<endl; cout<<" Vrsta: "<<a.vrsta<<endl; cout<<" Naziv: "<<a.naziv<<endl; cout<<" Cijena: "<<a.cijena<<endl; cout<<" Datum: "<<a.date.d<<"."; cout<<a.date.m<<"."<<a.date.y<<". "; SetConsoleTextAttribute(hConsole, 12); cout<<" ________________________________________________________________________________ "; SetConsoleTextAttribute(hConsole, 15); p = NextL(p,list); } } //_______________________________________________________________________________________________ void spoji(int truble, int wub_wub, int buble) { int I=truble, J=buble+1, K=0; elem *b = new elem [buble-truble+1]; elem prvi,drugi; while(I<=wub_wub && J<=buble){ prvi=RetrieveL(I,list); drugi=RetrieveL(J,list); if(prvi.cijena > drugi.cijena) { b[K++]=prvi; I++; } else if(prvi.cijena < drugi.cijena){ b[K++]=drugi; J++; } else if(strcmp(prvi.naziv,drugi.naziv)==-1) { b[K++]=drugi; J++; } else { b[K++]=prvi; I++; } } if(I>wub_wub) while(J<=buble) { drugi=RetrieveL(J,list); b[K++] = drugi; J++; } else while(I<=wub_wub) { prvi=RetrieveL(I,list); b[K++] = prvi; I++; } for(int I=0;I<=buble-truble;I++)Return(b[I],truble+I,list); delete [] b; } //_______________________________________________________________________________________________ void msort(int truble, int buble) { if(truble<buble) { int wub_wub=(truble+buble)/2; msort(truble,wub_wub); msort(wub_wub+1,buble); spoji(truble,buble,wub_wub); } } //_______________________________________________________________________________________________ void msort() { msort(0,br_elem-1); } int main() { HANDLE hConsole; hConsole = GetStdHandle(STD_OUTPUT_HANDLE); SetConsoleTextAttribute(hConsole, 12); cout<<" N"; SetConsoleTextAttribute(hConsole, 11); cout<<"Y"; SetConsoleTextAttribute(hConsole, 10); cout<<"A"; SetConsoleTextAttribute(hConsole, 15); cout<<"N "; SetConsoleTextAttribute(hConsole, 12); cout<<"C"; SetConsoleTextAttribute(hConsole, 11); cout<<"O"; SetConsoleTextAttribute(hConsole, 10); cout<<"R"; SetConsoleTextAttribute(hConsole, 15); cout<<"P "; //_____________________________START____________________________________________________________ int choice=9001; InitL(list); do { HANDLE hConsole; hConsole = GetStdHandle(STD_OUTPUT_HANDLE); // cout<<" <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<Izbornik>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>"; SetConsoleTextAttribute(hConsole, 12); cout<<" _____________________________________Izbornik___________________________________"; SetConsoleTextAttribute(hConsole, 15); cout<<" | [1] Dodaj zivotinju. |"; cout<<" | [2] Ispis od zadnje dodane zivotinje do prvo dodane. |"; cout<<" | [3] Ispis dodanih zivotinja koje su dostavljene nakon 23.9.2012. |"; cout<<" | [4] Brisanje unesenih zivotinja [naziv]. |"; cout<<" | [5] Brisanje unesenih zivotinja [vrsta]. |"; cout<<" | [6] Silazno sortiranje [naziv/cijena]. |"; cout<<" | [7] Clear screen. (brisanje prethodnog ispisa sa ekrana) |"; cout<<" | [0] Zatvaranje programa. |"; cout<<" |___________________________________________________________________|"; SetConsoleTextAttribute(hConsole, 12); cout<<" ________________________________________________________________________________ "; SetConsoleTextAttribute(hConsole, 15); cout<<" Izbor[0-7]:"; cin>>choice; cout<<" "; switch(choice) { //_______________________________________________________________________________________________ case 1: if(spawn_new_creature()) { SetConsoleTextAttribute(hConsole, 10); cout<<" Zapis je uspjesno dodan. "; SetConsoleTextAttribute(hConsole, 15); } else { SetConsoleTextAttribute(hConsole, 12); cout<<" <<Error!>> "; SetConsoleTextAttribute(hConsole, 15); cout<< "Pogresan unos!"; } break; //_______________________________________________________________________________________________ case 2:last_to_st(); break; //_______________________________________________________________________________________________ case 3:after_date(); break; //_______________________________________________________________________________________________ case 4: if(del_name()) { SetConsoleTextAttribute(hConsole, 10); cout<<" Trazena zivotinja je obrisana. "; SetConsoleTextAttribute(hConsole, 15); output(); } else { SetConsoleTextAttribute(hConsole, 12); cout<<" <<Error!>> "; SetConsoleTextAttribute(hConsole, 15); cout<<"Trazena zivotinja nije obrisana. Zivotinja pod tim nazivom ne postoji u zapisu. "; } break; //_______________________________________________________________________________________________ case 5: if(del_spi()) { SetConsoleTextAttribute(hConsole, 10); cout<<" Trazena vrsta je obrisana. "; SetConsoleTextAttribute(hConsole, 15); output(); } else { SetConsoleTextAttribute(hConsole, 12); cout<<" <<Error!>> "; SetConsoleTextAttribute(hConsole, 15); cout<<"Trazena vrsta nije obrisana. Vrsta ne postoji u zapisu.. "; } break; //_______________________________________________________________________________________________ case 6: msort(); output(); break; case 7: system("cls"); break; } }while(choice!=0); DeleteAll(list); system("pause"); return 0; } //made by Mugo
以上是关于结构podataka-Zadataku 1-Glavniu计划的主要内容,如果未能解决你的问题,请参考以下文章