Advertisement
Guest User

Untitled

a guest
Oct 31st, 2014
129
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.66 KB | None | 0 0
  1. #include<iostream>
  2. #include<iomanip>
  3. using namespace std;
  4.  
  5. const int MAX_R = 15;
  6. const int MAX_A = 10;
  7. const int MAX_N = 5;
  8. const int MAX_N_T = MAX_N +1;
  9. const int MAX_K = 6;
  10.  
  11.  
  12. struct kontener{
  13. char wlasciciel[MAX_N_T];
  14. int waga;
  15.  
  16. };
  17.  
  18. struct stos_kontenerow{
  19. int ile;
  20. kontener stos[MAX_K];
  21. };
  22.  
  23. struct trojka_indeksow{
  24. int rzad;
  25. int aleja;
  26. int wys;
  27. };
  28.  
  29.  
  30. int gen_plac( stos_kontenerow plac[][MAX_A], int r, int a )
  31. {
  32. int ile_kont = 0;
  33.  
  34. for( int rzad = 0; rzad < r; rzad++ )
  35. for( int aleja = 0; aleja < a; aleja++ )
  36. {
  37. plac[rzad][aleja].ile = rand() % (MAX_K + 1);
  38. ile_kont += plac[rzad][aleja].ile;
  39. for (int k = 0; k < plac[rzad][aleja].ile; k++)
  40. {
  41. plac[rzad][aleja].stos[k].waga = rand() % 100 + 1;
  42. plac[rzad][aleja].stos[k].wlasciciel[0]
  43. = static_cast<char>(rand() % (90 - 65 + 1) + 65);
  44. plac[rzad][aleja].stos[k].wlasciciel[1] = '\0';
  45. }
  46. }
  47. return ile_kont;
  48. }
  49.  
  50.  
  51. void pisz_plac( stos_kontenerow plac[][MAX_A], int r, int a )
  52. {
  53. for( int rzad = 0; rzad < r; rzad++ )
  54. for( int aleja = 0; aleja < a; aleja++ )
  55. {
  56. cout << setw(10) << rzad+1 << setw(3) << aleja+1 << endl;
  57. for (int k = 0; k < plac[rzad][aleja].ile; k++)
  58. cout << setw(3) << k + 1
  59. << setw(3) << plac[rzad][aleja].stos[k].waga
  60. << setw(2) << plac[rzad][aleja].stos[k].wlasciciel
  61. << endl;
  62. }
  63. }
  64.  
  65.  
  66.  
  67. void szukaj(stos_kontenerow plac[][MAX_A], int r, int a, char nazwa[], trojka_indeksow ind[], int &n)
  68. {
  69. n = 0;
  70. for( int rzad = 0; rzad < r; rzad++ )
  71. for( int aleja = 0; aleja < a; aleja++ )
  72. {
  73. for (int k = 0; k < plac[rzad][aleja].ile; k++)
  74. if( !strcmp(plac[rzad][aleja].stos[k].wlasciciel, nazwa) )
  75. {
  76. ind[n].rzad = rzad;
  77. ind[n].aleja = aleja;
  78. ind[n].wys = k;
  79. n++;
  80. }
  81. }
  82. }
  83.  
  84.  
  85.  
  86. void pisz_ind( trojka_indeksow ind[], int n )
  87. {
  88. for( int i = 0; i < n; i++ )
  89. cout << setw(3) << ind[i].rzad + 1
  90. << setw(3) << ind[i].aleja + 1
  91. << setw(3) << ind[i].wys + 1
  92. << endl;
  93. }
  94.  
  95.  
  96.  
  97. void rysuj_plac( stos_kontenerow plac[][MAX_A], int r, int a )
  98. {
  99. for( int rzad = 0; rzad < r; rzad++ ) {
  100. for( int aleja = 0; aleja < a; aleja++ )
  101. cout << setw(3) << plac[rzad][aleja].ile;
  102. cout << endl;
  103. }
  104. }
  105.  
  106. int main()
  107. {
  108. stos_kontenerow plac[MAX_R][MAX_A];
  109. int r, a;
  110. cout << "Podaj rozmiary placu:" << endl;
  111. cout << "rzedy: ";
  112. cin >> r;
  113. cout << "aleje: ";
  114. cin >> a;
  115.  
  116. int ile_kont = gen_plac( plac, r, a );
  117. cout << "Wygenerowano " << ile_kont << " kontenerow" << endl;
  118.  
  119. rysuj_plac( plac, r, a );
  120. pisz_plac ( plac, r, a );
  121.  
  122. trojka_indeksow ind[MAX_R*MAX_A*MAX_K];
  123. char nazwa[MAX_N_T];
  124. int n;
  125.  
  126.  
  127.  
  128. cout << "Podaj nazwe klienta ktorego kontenerow poszukujesz: ";
  129. cin >> nazwa;
  130. szukaj( plac, r, a, nazwa, ind, n );
  131. cout << "Kontenery klienta znajduja sie w nastepujacych miejscach" << endl;
  132. pisz_ind( ind, n );
  133.  
  134. system("pause");
  135. return 0;
  136. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement