Posted By

ldominov on 12/02/11


Tagged

c++


Versions (?)

glavni program


 / Published in: C++
 

asdsadasdasdasdasdasdasdas

  1. #include <iostream>
  2. #include <ctime>
  3. #include "red_pokazivac.h"
  4. using namespace std;
  5. bool ooooooooooooooooooooooooooooooo = false;
  6. void prvi(int P[], int PR[], int o) {
  7. srand((unsigned)time(0));
  8. for(int i=0; i<o; i++){
  9. P[i]=rand()%9999+1;
  10. P[o+i]=rand()%9999+1;
  11. PR[i]=rand()%4+1;
  12. }
  13. ooooooooooooooooooooooooooooooo = true;
  14. }
  15. void ispis(int P[], int PR[], int o) {
  16. cout<< endl << endl;
  17. cout<<"prvo vrijeme"<<"\t"<<"drugo vrijeme"<<"\t"<<"prioritet"<<endl;
  18. for(int i=0; i<o; i++)
  19. cout<<"\t"<<P[i]<<"\t"<<P[o+i]<<"\t"<<"\t"<<PR[i]<<endl;
  20. cout<<"___________________________________________________\n\n";
  21. }
  22. void drugi(int P[], int o) {
  23. red *RED=InitQ(RED);
  24. int C,V,J,I,POM;
  25. C=V=J=I=POM=0;
  26. pomocna x;
  27. while(J<o){
  28. x.x=P[J];
  29. x.y=P[o+J++];
  30. EnQueueQ(x, RED);
  31. cout<< ++I <<". pacijent:\n";
  32. POM=FrontQ(RED).x;
  33. cout<<"Na celu reda je: "<<POM<<endl <<"Vrijeme dolaska: "<<C<<endl;
  34. V=FrontQ(RED).y;
  35. cout<<"Vrijeme unutra: "<<V<<endl;
  36. C+=V;
  37. cout<<"Vrijeme odlaska: "<<C<<endl<<endl;
  38. C+=POM;
  39. DeQueueQ(RED);
  40. }
  41. cout<<"~~~~~~~~~~~~~~~~~THE END~~~~~~~~~~~~~~~~~~~~~~~\n";
  42. delete [] RED;
  43. }
  44. void treci(int P[], int PR[], int o) {
  45. int *PP = new int[2*o];
  46. int *PRPR = new int[2*o];
  47. int j,C,V,B;
  48. for(int i=0; i<o; i++){
  49. PP[i]=P[i];
  50. PP[o+i]=P[o+i];
  51. PRPR[i]=PRPR[i];
  52. }
  53. for(int i=1;i<o;i++){
  54. C=PRPR[i];
  55. V=PP[i];
  56. B=PP[o+i];
  57. j=i-1;
  58. while(j>=0 && PRPR[j]>C){
  59. PRPR[j+1]=PRPR[j];
  60. PP[j+1]=PP[j];
  61. PP[o+j+1]=PP[o+j--];
  62. }
  63. PRPR[j+1]=C;
  64. PP[j+1]=V;
  65. PP[o+j+1]=B;
  66. }
  67.  
  68. drugi(PP,o);
  69. delete [] PP, PRPR;
  70. }
  71. int main(){
  72. int izbor;
  73. cout << "\n Koliki broj pacijenata zelite u simulaciji? ";
  74. int o; cin >> o;
  75. int *P = new int[2*o];
  76. int *PR = new int[2*o];
  77. do{
  78. system("cls");
  79. cout << "\n~~~~~~~~~~~~~~~~~~~~~~ THE BEGIN~~~~~~~~~~~~~~~~~~~~~"
  80. << "\n1. Generiranje podataka o pacijenatima"
  81. << "\n2. Simulacije cekaonice"
  82. << "\n3. Simulacije cekaonice (modifikacija)"
  83. << "\n9. Izlaz iz programa\n"
  84. << "\nVas izbor: ";
  85. cin >> izbor;
  86. switch(izbor){
  87. case 1:
  88. prvi(P,PR,o);
  89. ispis(P,PR,o);
  90. break;
  91. case 2: if(!ooooooooooooooooooooooooooooooo) break;
  92. drugi(P,o); break;
  93. case 3: if(!ooooooooooooooooooooooooooooooo) break;
  94. treci(P,PR,o); break;
  95. case 9: cout<<"\n~~~~~~~~~~~~~~~~~~~~ THE END~~~~~~~~~~~~~~~~~~~~~\n";
  96. }
  97. system("pause");
  98. }while(izbor!=9);
  99. delete [] P, PR;
  100. return 0;
  101. }

Report this snippet  

You need to login to post a comment.