Posted By


FilipJ on 11/22/10

Tagged


Statistics


Viewed 422 times
Favorited by 0 user(s)

zadatak_3_strukture_podataka


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



Copy this code and paste it in your HTML
  1. #############################################################################
  2. #################################red_polje.h#################################
  3. #############################################################################
  4.  
  5.  
  6. #include<iostream>
  7. using namespace std;
  8.  
  9. struct zapis{
  10. char prezime[20];
  11. char ime[20];
  12. int god;
  13. float stanje;
  14. char vrsta_transakcije;
  15. };
  16.  
  17. struct qu{
  18. zapis elements[10000];
  19. int front,rear;
  20. };
  21.  
  22. typedef qu red;
  23.  
  24. int AddOne(int n){
  25. return((n+1)%10000);
  26. }//fjas
  27.  
  28. zapis FrontQ(red *Q){
  29. if(AddOne((*Q).rear)==(*Q).front){
  30. cout << "Red je pun" << endl;
  31. }
  32. return (*Q).elements[(*Q).front];
  33. }//fja
  34.  
  35. void EnQueueQ(zapis x, red *Q){
  36. (*Q).rear=AddOne((*Q).rear);
  37. (*Q).elements[(*Q).rear] = x;
  38. }//fja
  39.  
  40. void DeQueueQ(red *Q){
  41. if(AddOne((*Q).rear)==(*Q).front){
  42. cout << "Red je pun" << endl;
  43. }
  44. (*Q).front=AddOne((*Q).front);
  45. }//fja
  46.  
  47. void InitQ(red *Q){
  48. (*Q).rear=9999;
  49. (*Q).front=0;
  50. }//fja
  51.  
  52. bool IsEmptyQ(red *Q){
  53. if(AddOne((*Q).rear)==(*Q).front){
  54. return true;
  55. }
  56. else {
  57. return false;
  58. }
  59. }//fja
  60.  
  61. #############################################################################
  62. ################################zadatak3.cpp#################################
  63. #############################################################################
  64.  
  65. #include<iostream>
  66. #include "red_polje.h"
  67. using namespace std;
  68. zapis klijent;
  69. int br=0;
  70. void dodavanje_zapisa(qu *Q){
  71. cout << "Unesite ime: ";
  72. cin >> klijent.ime;
  73. cout << endl << "Unesite prezime: ";
  74. cin >> klijent.prezime;
  75. cout << endl << "Godina rodjenja: ";
  76. cin >> klijent.god;
  77. cout << endl << "Stanje na bankovnom racunu (kn): ";
  78. cin >> klijent.stanje;
  79. cout << endl << "Vrsta transakcije (u/i,p,k): ";
  80. cin >> klijent.vrsta_transakcije;
  81. cout << endl;
  82. EnQueueQ(klijent, Q);
  83. br++;
  84. }
  85. void ispis(qu *Q, qu *trenutni){
  86. zapis klijent;
  87. while(!IsEmptyQ(Q)){
  88. klijent=FrontQ(Q);
  89. DeQueueQ(Q);
  90. cout << "Ime: " << klijent.ime << endl;
  91. cout << "Prezime: " << klijent.prezime << endl;
  92. cout << "Godiste: " << klijent.god << endl;
  93. cout << "Stanje na racunu: " << klijent.stanje << endl;
  94. cout << "Vrsta transakcije: " << klijent.vrsta_transakcije << endl;
  95. cout << "----------------------------" << endl;
  96. ///////
  97. EnQueueQ(klijent, trenutni);
  98. }//while
  99. while(!IsEmptyQ(trenutni)){
  100. klijent=FrontQ(trenutni);
  101. DeQueueQ(trenutni);
  102. EnQueueQ(klijent, Q);
  103. }//while
  104. }//fja
  105.  
  106. void provjera(qu *Q, qu *trenutni){
  107. zapis pom;
  108. int jos=br;
  109. while(jos){
  110. pom=FrontQ(Q);
  111. DeQueueQ(Q);
  112. if(pom.god < 1945) {
  113. EnQueueQ(pom, Q);
  114. }//if
  115. else {
  116. EnQueueQ(pom, trenutni);
  117. }//else
  118. jos--;
  119. }//while
  120. while(!IsEmptyQ(trenutni)){
  121. pom=FrontQ(trenutni);
  122. DeQueueQ(trenutni);
  123. EnQueueQ(pom, Q);
  124. }//while
  125. ispis(Q,trenutni);
  126. }//fja
  127.  
  128. void brisanje(qu *Q, qu *trenutni){
  129. zapis klijent;
  130. int jos=br;
  131. while(jos){
  132. klijent=FrontQ(Q);
  133. DeQueueQ(Q);
  134. if(klijent.stanje > 100 || klijent.vrsta_transakcije=='u' || klijent.vrsta_transakcije=='p'){
  135. EnQueueQ(klijent, trenutni);
  136. }//if
  137. jos--;
  138. }//while
  139. while(!IsEmptyQ(trenutni)){
  140. klijent=FrontQ(trenutni);
  141. DeQueueQ(trenutni);
  142. EnQueueQ(klijent, Q);
  143. }//while
  144. ispis(Q,trenutni);
  145. }//fja
  146.  
  147. void otvaranje_zatvaranje(qu *Q){
  148. zapis klijent;
  149. klijent=FrontQ(Q);
  150. DeQueueQ(Q);
  151. if(!IsEmptyQ(Q)){
  152. otvaranje_zatvaranje(Q); }//if
  153. EnQueueQ(klijent, Q);
  154. }//fja
  155.  
  156. int main(){
  157. int izbor;
  158. qu q;
  159. InitQ(&q);
  160. qu trenutni;
  161. InitQ(&trenutni);
  162.  
  163. cout << endl;
  164. do{
  165. cout << "---------------IZBORNIK--------------" << endl;
  166. cout << "1. Dodavanje zapisa o klinetima u red" << endl;
  167. cout << "2. Ispis starijih od 65 na pocetak reda" << endl;
  168. cout << "3. Izbacivanje klijenata (stanje < 100kn)" << endl;
  169. cout << "4. Simulacija saltera u banci" << endl;
  170. cout << "9. Izlaz iz programa" << endl;
  171. cout << "--------------------------------------" << endl;
  172. cout << "Unesite vas izbor: ";
  173. cin >> izbor;
  174. cout << endl;
  175. switch(izbor){
  176. case 1:
  177. dodavanje_zapisa(&q);
  178. break;
  179. case 2: provjera(&q,&trenutni);
  180. break;
  181. case 3: brisanje(&q,&trenutni);
  182. break;
  183. case 4: otvaranje_zatvaranje(&q);
  184. ispis(&q,&trenutni);
  185. break;
  186.  
  187. }//switch
  188. }while(izbor!=9);
  189. system("PAUSE");
  190. return 0;
  191. }

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.