# Posted By

Mugooooo on 11/12/12

# Statistics

Viewed 278 times
Favorited by 0 user(s)

# Strukture podataka-Zadatak_1-Glavni_Program

/ Published in: C++
Save to your folder(s)

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.

Copy this code and paste it in your HTML
`#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<<"\n________________________________________________________________________________\n";SetConsoleTextAttribute(hConsole, 15);    cout<<"\tSifra:"<<a.sifra<<endl;    cout<<"\tVrsta:"<<a.vrsta<<endl;    cout<<"\tNaziv:"<<a.naziv<<endl;    cout<<"\tCijena:"<<a.cijena<<endl;    cout<<"\tDatum:"<<a.date.d<<".";    cout<<a.date.m<<"."<<a.date.y<<".\n";SetConsoleTextAttribute(hConsole, 12);    cout<<"\n________________________________________________________________________________\n";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<<"\n________________________________________________________________________________\n";SetConsoleTextAttribute(hConsole, 15);    cout<<"\tSifra:"<<a.sifra<<endl;    cout<<"\tVrsta:"<<a.vrsta<<endl;    cout<<"\tNaziv:"<<a.naziv<<endl;    cout<<"\tCijena:"<<a.cijena<<endl;    cout<<"\tDatum:"<<a.date.d<<"."<<a.date.m<<"."<<a.date.y<<".\n";SetConsoleTextAttribute(hConsole, 12);    cout<<"\n________________________________________________________________________________\n";SetConsoleTextAttribute(hConsole, 15);    }    p = NextL(p,list);    }    SetConsoleTextAttribute(hConsole, 10);    cout<<"\tBroj pronadenih zivotinja:"<<numero<<"\n   \n ";    SetConsoleTextAttribute(hConsole, 15);    }  //_______________________________________________________________________________________________  int spawn_new_creature() {        HANDLE hConsole;    hConsole = GetStdHandle(STD_OUTPUT_HANDLE);    elem novi;    novi.sifra=sifra++;SetConsoleTextAttribute(hConsole, 12);    cout<<"\n________________________________________________________________________________\n";SetConsoleTextAttribute(hConsole, 15);    cout<<"\tVrsta:";    cin.ignore();    cin.getline(novi.vrsta,50);    cout<<"\tNaziv:";    cin.getline(novi.naziv,50);    cout<<"\tCijena:";cin>>novi.cijena;    if(novi.cijena<=0) {sifra--;return 0;}    cout<<"\tUnesite datum dostave:\n";    cout<<"\tDan:";cin>>novi.date.d;    if(novi.date.d<=0||novi.date.d>31) {sifra--;return 0;}    cout<<"\tMjesec:";    cin.ignore();    cin.getline(novi.date.m,10);    if(novi.date.d>29&&!strcmp(novi.date.m,"veljaca")) {sifra--;return 0;}    cout<<"\tGodina:";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<<"\n________________________________________________________________________________\n";SetConsoleTextAttribute(hConsole, 15);    return 1;    } //_______________________________________________________________________________________________  int del_name() {        HANDLE hConsole;    hConsole = GetStdHandle(STD_OUTPUT_HANDLE);    char naziv[50];SetConsoleTextAttribute(hConsole, 12);    cout<<"\n________________________________________________________________________________\n";SetConsoleTextAttribute(hConsole, 15);    cout<<"\tUnesite naziv zivotinje:";    cin.ignore();    cin.getline(naziv,50);SetConsoleTextAttribute(hConsole, 12);    cout<<"\n________________________________________________________________________________\n";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<<"\n________________________________________________________________________________\n";SetConsoleTextAttribute(hConsole, 15);    cout<<"\tUnesite vrstu zivotinje:";    cin.ignore();    cin.getline(vrsta,35);SetConsoleTextAttribute(hConsole, 12);    cout<<"\n________________________________________________________________________________\n";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<<"\n________________________________________________________________________________\n";SetConsoleTextAttribute(hConsole, 15);    cout<<"\tSifra: "<<a.sifra<<endl;    cout<<"\tVrsta: "<<a.vrsta<<endl;    cout<<"\tNaziv: "<<a.naziv<<endl;    cout<<"\tCijena: "<<a.cijena<<endl;    cout<<"\tDatum: "<<a.date.d<<".";    cout<<a.date.m<<"."<<a.date.y<<".\n";SetConsoleTextAttribute(hConsole, 12);    cout<<"\n________________________________________________________________________________\n";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\t\t\t\t     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 \n";//_____________________________START____________________________________________________________    int choice=9001;    InitL(list);    do {      HANDLE hConsole;    hConsole = GetStdHandle(STD_OUTPUT_HANDLE);   //    cout<<"\n\n<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<Izbornik>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>";SetConsoleTextAttribute(hConsole, 12);    cout<<"\n\n_____________________________________Izbornik___________________________________";       SetConsoleTextAttribute(hConsole, 15);       cout<<"\n\t | [1] Dodaj zivotinju.                                              |";    cout<<"\n\t | [2] Ispis od zadnje dodane zivotinje do prvo dodane.              |";    cout<<"\n\t | [3] Ispis dodanih zivotinja koje su dostavljene nakon 23.9.2012.  |";    cout<<"\n\t | [4] Brisanje unesenih zivotinja [naziv].                          |";    cout<<"\n\t | [5] Brisanje unesenih zivotinja [vrsta].                          |";    cout<<"\n\t | [6] Silazno sortiranje [naziv/cijena].                            |";    cout<<"\n\t | [7] Clear screen. (brisanje prethodnog ispisa sa ekrana)          |";    cout<<"\n\t | [0] Zatvaranje programa.                                          |";    cout<<"\n\t |___________________________________________________________________|";SetConsoleTextAttribute(hConsole, 12);    cout<<"\n________________________________________________________________________________\n";SetConsoleTextAttribute(hConsole, 15);    cout<<"\n\t  Izbor[0-7]:";    cin>>choice;    cout<<"\n\n";     switch(choice) {//_______________________________________________________________________________________________                       case 1:    if(spawn_new_creature())    {    SetConsoleTextAttribute(hConsole, 10);    cout<<"\tZapis je uspjesno dodan.\n";    SetConsoleTextAttribute(hConsole, 15);}    else {        SetConsoleTextAttribute(hConsole, 12);         cout<<"\t<<Error!>>\n\t";         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<<"\n\tTrazena zivotinja je obrisana.\n\n";    SetConsoleTextAttribute(hConsole, 15);    output();    }    else {      SetConsoleTextAttribute(hConsole, 12);         cout<<"\t<<Error!>>\n\t";         SetConsoleTextAttribute(hConsole, 15);    cout<<"Trazena zivotinja nije obrisana.\n\tZivotinja pod tim nazivom ne postoji u zapisu.\n\n";}    break;//_______________________________________________________________________________________________            case 5:    if(del_spi()) {     SetConsoleTextAttribute(hConsole, 10);    cout<<"\n\tTrazena vrsta je obrisana.\n\n";    SetConsoleTextAttribute(hConsole, 15);    output();    }    else {    SetConsoleTextAttribute(hConsole, 12);    cout<<"\t<<Error!>>\n\t";    SetConsoleTextAttribute(hConsole, 15);    cout<<"Trazena vrsta nije obrisana.\n\tVrsta ne postoji u zapisu..\n\n";}    break; //_______________________________________________________________________________________________        case 6:    msort();    output();     break;     case 7:    system("cls");     break;    }    }while(choice!=0);    DeleteAll(list);     system("pause");    return 0;    }  //made by Mugo`

## Comments

Subscribe to comments

You need to login to post a comment.