Guest User

Untitled

a guest
Jun 21st, 2018
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.12 KB | None | 0 0
  1. #include <iostream>
  2. #include <cstring>
  3. //#include "stog_polje.h"
  4. #include "stog_pokazivac.h"
  5. using namespace std;
  6. stack *kamion = new stack;
  7.  
  8.  
  9. void ukrcaj(stack *S){
  10. int serial, godiste;
  11. string proizvodjac,model;
  12. cout<<"Proizvodjac: ";
  13. cin.ignore();
  14. cin.clear();
  15. getline(cin,proizvodjac, '\n');
  16. char jos;
  17. do{
  18. cout<<"Model: ";
  19. getline(cin,model, '\n');
  20. cout<<"Serijski broj auta:";
  21. cin>>serial;
  22. do{
  23. cout<<"Godiste: ";
  24. cin>>godiste;
  25. if(godiste<1995||godiste>2010)
  26. cout<<"Godiste mora biti između 1995-2010\n";
  27. }while(godiste<1995||godiste>2010);
  28. PushS(serial,proizvodjac,model,godiste,S);
  29. cout<<"Zelite li jos unositi modela?\n";
  30. cin>>jos;
  31. cin.ignore();
  32. }while(jos=='d');
  33.  
  34. }
  35.  
  36. void iskrcaj_2006(stack *S){
  37. cout<<"Ispis svih automobila novijih od 2006 koji nisu Audi\n";
  38. cout<<"-----------------------------------------\n";
  39. stack *pom=new stack;
  40. InitS(pom);
  41. int godiste, serial;
  42. string proizvodjac, model;
  43. while(!IsEmptyS(S)){
  44. TopS(*S,&proizvodjac,&model,&serial,&godiste);//pregledaj koje su vrijednosti
  45. if(godiste>2006&&proizvodjac.compare("Audi")!=0){
  46. cout<<"\nSerijski broj: "<<serial<<endl;
  47. cout<<"Proizvodjac: "<<proizvodjac<<endl;
  48. cout<<"Model: "<<model<<endl;
  49. cout<<"Godiste: "<<godiste<<endl;
  50.  
  51. }//ispis trazenog elementa IF
  52. PushS(serial,proizvodjac,model,godiste,pom); //snimi u pomocni stog
  53. PopS(S); //iduci element iz glavnog stoga
  54. }//while
  55. //vracanje nazad u stog i ispis njegovog sadrzaja
  56.  
  57. stack *pom2=new stack;//koristit ce se da ispise stanje glavnog stoga
  58. InitS(pom2);
  59. while(!IsEmptyS(pom)){
  60. TopS(*pom,&proizvodjac,&model,&serial,&godiste);//pregledaj koje su vrijednosti
  61. PushS(serial,proizvodjac,model,godiste,S); //vrati u stog prethodno stanje
  62. PushS(serial,proizvodjac,model,godiste,pom2);//snimi u pomocni stog
  63. PopS(pom); //iduci element iz glavnog stoga
  64. }//while
  65.  
  66. cout<<"-----------------------------------------\n";
  67. cout<<"Ispisivanje stanja kamiona (glavnog stoga)\n";
  68. cout<<"-----------------------------------------\n";
  69. while(!IsEmptyS(pom2)){
  70. TopS(*pom2,&proizvodjac,&model,&serial,&godiste);//pregledaj koje su vrijednosti
  71. cout<<"\nSerijski broj: "<<serial<<endl;
  72. cout<<"Proizvodjac: "<<proizvodjac<<endl;
  73. cout<<"Model: "<<model<<endl;
  74. cout<<"Godiste: "<<godiste<<endl;
  75. PopS(pom2); //iduci element iz glavnog/pomocnog stoga
  76. }//while
  77. delete pom,pom2;
  78. }
  79.  
  80. void rekurzija(stack *S){
  81. int godiste, serial;
  82. string proizvodjac, model;
  83. if(!IsEmptyS(S)){
  84. TopS(*S,&proizvodjac,&model,&serial,&godiste);
  85. cout<<"\nSerijski broj: "<<serial<<endl;
  86. cout<<"Proizvodjac: "<<proizvodjac<<endl;
  87. cout<<"Model: "<<model<<endl;
  88. cout<<"Godiste: "<<godiste<<endl;
  89. PopS(S);
  90. rekurzija(S);
  91. PushS(serial,proizvodjac,model,godiste,S);
  92. }
  93. }
  94.  
  95. void izbornik(){
  96. cout<<"1. Ukrcaj automobil\n";
  97. cout<<"2. Iskrcaj sve automobile u prvoj robnoj kuci >2006 godiste-non Audi\n";
  98. cout<<"3. Iskrcaj sve automobile u drugoj robnoj kuci\n";
  99. cout<<"9. Izlaz\n";
  100.  
  101. }
  102. int main(){
  103. InitS(kamion);
  104. int izbor;
  105. do{
  106. izbornik();
  107. cin>>izbor;
  108. switch(izbor){
  109. case 1:{
  110. ukrcaj(kamion);
  111. break;}
  112. case 2:
  113. iskrcaj_2006(kamion);
  114. break;
  115. case 3:
  116. rekurzija(kamion);
  117. break;
  118. }
  119. }while(izbor!=9);
  120.  
  121. system("pause");
  122. return 0;
  123. }
Add Comment
Please, Sign In to add comment