Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cstring>
- //#include "stog_polje.h"
- #include "stog_pokazivac.h"
- using namespace std;
- stack *kamion = new stack;
- void ukrcaj(stack *S){
- int serial, godiste;
- string proizvodjac,model;
- cout<<"Proizvodjac: ";
- cin.ignore();
- cin.clear();
- getline(cin,proizvodjac, '\n');
- char jos;
- do{
- cout<<"Model: ";
- getline(cin,model, '\n');
- cout<<"Serijski broj auta:";
- cin>>serial;
- do{
- cout<<"Godiste: ";
- cin>>godiste;
- if(godiste<1995||godiste>2010)
- cout<<"Godiste mora biti između 1995-2010\n";
- }while(godiste<1995||godiste>2010);
- PushS(serial,proizvodjac,model,godiste,S);
- cout<<"Zelite li jos unositi modela?\n";
- cin>>jos;
- cin.ignore();
- }while(jos=='d');
- }
- void iskrcaj_2006(stack *S){
- cout<<"Ispis svih automobila novijih od 2006 koji nisu Audi\n";
- cout<<"-----------------------------------------\n";
- stack *pom=new stack;
- InitS(pom);
- int godiste, serial;
- string proizvodjac, model;
- while(!IsEmptyS(S)){
- TopS(*S,&proizvodjac,&model,&serial,&godiste);//pregledaj koje su vrijednosti
- if(godiste>2006&&proizvodjac.compare("Audi")!=0){
- cout<<"\nSerijski broj: "<<serial<<endl;
- cout<<"Proizvodjac: "<<proizvodjac<<endl;
- cout<<"Model: "<<model<<endl;
- cout<<"Godiste: "<<godiste<<endl;
- }//ispis trazenog elementa IF
- PushS(serial,proizvodjac,model,godiste,pom); //snimi u pomocni stog
- PopS(S); //iduci element iz glavnog stoga
- }//while
- //vracanje nazad u stog i ispis njegovog sadrzaja
- stack *pom2=new stack;//koristit ce se da ispise stanje glavnog stoga
- InitS(pom2);
- while(!IsEmptyS(pom)){
- TopS(*pom,&proizvodjac,&model,&serial,&godiste);//pregledaj koje su vrijednosti
- PushS(serial,proizvodjac,model,godiste,S); //vrati u stog prethodno stanje
- PushS(serial,proizvodjac,model,godiste,pom2);//snimi u pomocni stog
- PopS(pom); //iduci element iz glavnog stoga
- }//while
- cout<<"-----------------------------------------\n";
- cout<<"Ispisivanje stanja kamiona (glavnog stoga)\n";
- cout<<"-----------------------------------------\n";
- while(!IsEmptyS(pom2)){
- TopS(*pom2,&proizvodjac,&model,&serial,&godiste);//pregledaj koje su vrijednosti
- cout<<"\nSerijski broj: "<<serial<<endl;
- cout<<"Proizvodjac: "<<proizvodjac<<endl;
- cout<<"Model: "<<model<<endl;
- cout<<"Godiste: "<<godiste<<endl;
- PopS(pom2); //iduci element iz glavnog/pomocnog stoga
- }//while
- delete pom,pom2;
- }
- void rekurzija(stack *S){
- int godiste, serial;
- string proizvodjac, model;
- if(!IsEmptyS(S)){
- TopS(*S,&proizvodjac,&model,&serial,&godiste);
- cout<<"\nSerijski broj: "<<serial<<endl;
- cout<<"Proizvodjac: "<<proizvodjac<<endl;
- cout<<"Model: "<<model<<endl;
- cout<<"Godiste: "<<godiste<<endl;
- PopS(S);
- rekurzija(S);
- PushS(serial,proizvodjac,model,godiste,S);
- }
- }
- void izbornik(){
- cout<<"1. Ukrcaj automobil\n";
- cout<<"2. Iskrcaj sve automobile u prvoj robnoj kuci >2006 godiste-non Audi\n";
- cout<<"3. Iskrcaj sve automobile u drugoj robnoj kuci\n";
- cout<<"9. Izlaz\n";
- }
- int main(){
- InitS(kamion);
- int izbor;
- do{
- izbornik();
- cin>>izbor;
- switch(izbor){
- case 1:{
- ukrcaj(kamion);
- break;}
- case 2:
- iskrcaj_2006(kamion);
- break;
- case 3:
- rekurzija(kamion);
- break;
- }
- }while(izbor!=9);
- system("pause");
- return 0;
- }
Add Comment
Please, Sign In to add comment