/ Published in: C++
Drugi zadatak
Expand |
Embed | Plain Text
//stog pokaziva�� struct odora { int code; char ime[40], vrsta[40], datum[20], rok_up[20]; }; struct st { odora vrijednost; st *next; }; st *stog=new st, *stog1=new st; void InitS (st *stog) { stog->next=NULL; } odora TopS (st *stog) { return (stog->next)->vrijednost; } void PushS (odora x, st *stog) { st *novi=new st; novi->vrijednost=x; novi->next=stog->next; stog->next=novi; } void PopS (st *stog) { st *prvi=stog->next; stog->next=prvi->next; delete prvi; } bool IsEmptyS (st *stog) { if (stog->next==NULL) return true; else return false; } //stog polje struct odora { int code; char ime[45], vrsta[45], datum[25], rok_up[25]; }; struct st { odora elem[1000]; int kursor; }; st stog, stog1; void InitS (st &stog) { stog.kursor=999; } odora TopS (st stog) { return stog.elem[stog.kursor+1]; } void PushS (odora x, st &stog) { stog.elem[stog.kursor]=x; stog.kursor--; } void PopS (st &stog) { stog.kursor++; } bool IsEmptyS (st stog) { if (stog.kursor==999) return true; return false; } //main #include <iostream> #include <cmath> //#include "stog_polje.h" #include "stog_pokazivac.h" using namespace std; bool check_date(char p[], bool w=true) { int days=10*(p[0]-48)+(p[1]-48); if (days<1 || days>31) return 0; int mjes=10*(p[3]-48)+(p[4]-48); if (mjes<1 || mjes>12) return 0; if (w) { int god=1000*(p[6]-48)+100*(p[7]-48)+10*(p[8]-48)+(p[9]-48); if (god<2010 || god>2011) return 0; } return 1; } bool datum (char p[]) { int god=1000*(p[6]-48)+100*(p[7]-48)+10*(p[8]-48)+(p[9]-48); if (god>2010) return false; int mje=10*(p[3]-48)+(p[4]-48); if (mje<9) return true; if (mje>9) return false; int dan=10*(p[0]-48)+(p[1]-48); if (dan<23) return true; return false; } void ispis_1 () { odora a; InitS(stog1); system ("cls"); cout << "Ispis robe koja je proizvedena prije 23.09.2010.: "<<endl; while (!IsEmptyS(stog)) { a=TopS(stog); if (datum(a.datum)) { cout << "\nSifra robe: " << a.code; cout << "\nNaziv robe: " << a.ime; cout << "\nVrsta robe: " << a.vrsta; cout << "\nDatum proizvodnje: " << a.datum; cout << "\nRok uporabe: " << a.rok_up; cout << "\n======================="<<endl; } else PushS(a, stog1); PopS(stog); } system ("pause"); cout << "\nStanje stoga:\n"; while (!IsEmptyS(stog1)) { a=TopS(stog1); cout << "\nSifra robe: " << a.code; cout << "\nNaziv robe: " << a.ime; cout << "\nVrsta robe: " << a.vrsta; cout << "\nDatum proizvodnje: " << a.datum; cout << "\nRok uporabe: " << a.rok_up; cout << "\n======================"<<endl; PopS(stog1); PushS(a, stog); } system ("pause"); } void f1 (){// utovar robe :D system ("cls"); odora a; cout << "Sifra robe: "; cin >> a.code; cin.ignore(); cout << "Naziv robe: "; cin.getline(a.ime, 45); cout << "Vrsta robe: "; cin.getline(a.vrsta, 45); bool w; do { cout << "Datum proizvodnje (01.01.2010.-31.12.2011.): "; cin.getline(a.datum, 25); w=check_date(a.datum); if (!w) cout << "Krivi datum!\n"; } while (!w); do { cout << "Rok uporabe: "; cin.getline(a.rok_up, 25); w=check_date(a.rok_up, false); if (!w) cout << "Krivi datum!\n"; } while (!w); PushS(a, stog); cout << "\nDodali ste robu u stog.\n"; system ("pause"); } bool razlika (char p[], char b[]) { int proiz=1000*(p[6]-48)+100*(p[7]-48)+10*(p[8]-48)+(p[9]-48); int rok=1000*(b[6]-48)+100*(b[7]-48)+10*(b[8]-48)+(b[9]-48); if (proiz+1<rok) return false; if (proiz<rok) { proiz=10*(p[3]-48)+(p[4]-48); if (proiz<12) return false; rok=10*(b[3]-48)+(b[4]-48); if (rok>1) return false; proiz=10*(p[0]-48)+(p[1]-48); rok=10*(b[0]-48)+(b[1]-48); if ((rok+30-proiz)>14) return false; return true; } proiz=10*(p[3]-48)+(p[4]-48); rok=10*(b[3]-48)+(b[4]-48); if (proiz+1<rok) return false; if (proiz<rok) { proiz=10*(p[0]-48)+(p[1]-48); rok=10*(b[0]-48)+(b[1]-48); if ((rok+30-proiz)>14) return false; return true; } proiz=10*(p[0]-48)+(p[1]-48); rok=10*(b[0]-48)+(b[1]-48); if ((proiz-rok)>14) return false; return true; } void ispis_2 () { static bool t=true; if (IsEmptyS(stog)) { t=true; return; } odora a=TopS(stog); bool w=razlika(a.datum, a.rok_up); if (w) { cout << "\nSifra robe: " << a.code; cout << "\nNaziv robe: " << a.ime; cout << "\nVrsta robe: " << a.vrsta; cout << "\nDatum proizvodnje: " << a.datum; cout << "\nRok uporabe: " << a.rok_up; cout << "\n====================="<<endl; } PopS(stog); ispis_2(); if (t) { system ("pause"); cout << "\nStanje stoga:"<<endl; t=false; } if (!w) { PushS(a, stog); cout << "\nSifra robe: " << a.code; cout << "\nNaziv robe: " << a.ime; cout << "\nVrsta robe: " << a.vrsta; cout << "\nDatum proizvodnje: " << a.datum; cout << "\nRok uporabe: " << a.rok_up; cout << "\n==================="<<endl; } return; } int main () { int a; InitS(stog); do { system ("cls"); cout<<"----------------------------------------------------"<<endl; cout << "1. Utovar robe u skladiste"<<endl; cout << "2. Istovar robe u prvoj trgovini"<<endl; cout << "3. Istovar robe u drugoj trgovini"<<endl; cout << "9. Prekid programa"<<endl; cout<<"----------------------------------------------------"<<endl; cout << "Vas izbor: "; do {cin >> a; } while (a<0 || a>3&&a!=9); switch (a) { case 1: f1(); break; case 2: ispis_1(); break; case 3:{ system ("cls"); cout << "Ispis pokvarljive robe:\n"; ispis_2(); system ("pause"); } } } while (a!=9); return 0; }
You need to login to post a comment.
