/ Published in: C++
Expand |
Embed | Plain Text
#include <iostream> #include <conio.h> //#include "rpolj.h" #include "rpok.h" using namespace std; bool dodaj(red *Q){ //dodavanje novih elemenata u red char jos; bool deda = false; do{ klijent x; cout << "Ime: "; cin.ignore(); cin.getline(x.ime,30); cout << "Godina rodjenja: "; cin >> x.god; if (x.god < 1945) deda = true; cout << "Stanje na racunu: "; cin >> x.st; do{ cout << "Vrsta transakcije(1-3)?: "; cin >> x.tip; if (x.tip <1 || x.tip >3) cout << "\n1) Uplata/isplata\n2) Placanje racuna\n3) krediti\nIzbor: "; }while(x.tip <1 || x.tip >3); EnQueueQ(x,Q); cout << "Zelite li upisati jos?(d/n)?"; cin >> jos; }while(jos!='n' && jos !='N'); return deda; // vraca true ako ima starijih od 1945. godista } void stanje(red *Q){ //Ispisuje trenutacno stanje reda pomocu dodatnog reda red *der = InitQ(der);//inicira se pomocni red klijent x; //pomocni char vrsta[3][20] = {"Uplata/Isplata","Placanje racuna","Krediti"}; cout << "\n......................." << "\nTrenutno stanje u redu:" << "\n......................."; while(!IsEmptyQ(Q)){ x = FrontQ(Q); DeQueueQ(Q); EnQueueQ(x,der); cout << "\nIme: " << x.ime << "\nGodiste: " << x.god << "\nStanje: " << x.st << "\nVrsta transakcije: " << vrsta[x.tip-1] << "\n.......................\n"; getch(); } while(!IsEmptyQ(der)){ x = FrontQ(der); DeQueueQ(der); EnQueueQ(x,Q); } } void filtar(red *Q,bool schmool){ // Premjestanje starkelja na početak reda/izbacivanje siromaha (ako je parametar schmool 1 = penzici, ako je 0 = siromahi) red *der = InitQ(der); bool uvjet, zapis; klijent x; int i,b = SizeQ(Q); for (i=0;i<b;i++){ x = FrontQ(Q); DeQueueQ(Q); if (schmool) uvjet = (x.god < 1945); else uvjet = (x.st <100 && x.tip == 3); if(uvjet){ if(schmool) EnQueueQ(x,Q); } else EnQueueQ(x,der); } b = SizeQ(der); for (i=0;i<b;i++){ x = FrontQ(der); DeQueueQ(der); EnQueueQ(x,Q); } } void muvanje(red *Q){ klijent x; if (!IsEmptyQ(Q)){ x = FrontQ(Q); DeQueueQ(Q); muvanje(Q); EnQueueQ(x,Q); } } int main(){ int iz; red *der = InitQ(der); //iniciranje glavnog reda do{ //izbornik cout << endl << "-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+" << endl << "+-+-+-+-+-+-+ Izbornik -+-+-+-+-+-+-" << endl << "-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+" << endl << "+- 1. Dodavanje klijenata u red +-" << endl << "+- 2. Izbacivanje siromasnih +-" << endl << "-+ 3. Muvanje na novi salter -+" << endl << "+- 0. Izlaz +-" << endl << "+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-" << endl; cin >> iz; switch(iz){ case 1: if (dodaj(der)) filtar(der,1); //Ako ima penzica filtriraj stanje(der); //Ispis stanja break; case 2: filtar(der,0); //izbacivanje siromaha stanje(der); break; case 3: muvanje(der); //premjestanje u novi red stanje(der); break; case 0: break; case 5: //tajna mogucnost za provjeru stanja stanje(der); break; default: cout << "\nOdaberite jednu od ponudjenih mogucnosti! (Ne postoji tajna mogućnost)" << endl; //Tajna mogucnost je 5. break; } }while(iz); cout << "Pristisnite bilo kaj..."; getch(); return 0; }
You need to login to post a comment.
