Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- #include<iomanip>
- using namespace std;
- const int MAX_R = 15;
- const int MAX_A = 10;
- const int MAX_N = 5;
- const int MAX_N_T = MAX_N +1;
- const int MAX_K = 6;
- struct kontener{
- char wlasciciel[MAX_N_T];
- int waga;
- };
- struct stos_kontenerow{
- int ile;
- kontener stos[MAX_K];
- };
- struct trojka_indeksow{
- int rzad;
- int aleja;
- int wys;
- };
- int gen_plac( stos_kontenerow plac[][MAX_A], int r, int a )
- {
- int ile_kont = 0;
- for( int rzad = 0; rzad < r; rzad++ )
- for( int aleja = 0; aleja < a; aleja++ )
- {
- plac[rzad][aleja].ile = rand() % (MAX_K + 1);
- ile_kont += plac[rzad][aleja].ile;
- for (int k = 0; k < plac[rzad][aleja].ile; k++)
- {
- plac[rzad][aleja].stos[k].waga = rand() % 100 + 1;
- plac[rzad][aleja].stos[k].wlasciciel[0]
- = static_cast<char>(rand() % (90 - 65 + 1) + 65);
- plac[rzad][aleja].stos[k].wlasciciel[1] = '\0';
- }
- }
- return ile_kont;
- }
- void pisz_plac( stos_kontenerow plac[][MAX_A], int r, int a )
- {
- for( int rzad = 0; rzad < r; rzad++ )
- for( int aleja = 0; aleja < a; aleja++ )
- {
- cout << setw(10) << rzad+1 << setw(3) << aleja+1 << endl;
- for (int k = 0; k < plac[rzad][aleja].ile; k++)
- cout << setw(3) << k + 1
- << setw(3) << plac[rzad][aleja].stos[k].waga
- << setw(2) << plac[rzad][aleja].stos[k].wlasciciel
- << endl;
- }
- }
- void szukaj(stos_kontenerow plac[][MAX_A], int r, int a, char nazwa[], trojka_indeksow ind[], int &n)
- {
- n = 0;
- for( int rzad = 0; rzad < r; rzad++ )
- for( int aleja = 0; aleja < a; aleja++ )
- {
- for (int k = 0; k < plac[rzad][aleja].ile; k++)
- if( !strcmp(plac[rzad][aleja].stos[k].wlasciciel, nazwa) )
- {
- ind[n].rzad = rzad;
- ind[n].aleja = aleja;
- ind[n].wys = k;
- n++;
- }
- }
- }
- void pisz_ind( trojka_indeksow ind[], int n )
- {
- for( int i = 0; i < n; i++ )
- cout << setw(3) << ind[i].rzad + 1
- << setw(3) << ind[i].aleja + 1
- << setw(3) << ind[i].wys + 1
- << endl;
- }
- void rysuj_plac( stos_kontenerow plac[][MAX_A], int r, int a )
- {
- for( int rzad = 0; rzad < r; rzad++ ) {
- for( int aleja = 0; aleja < a; aleja++ )
- cout << setw(3) << plac[rzad][aleja].ile;
- cout << endl;
- }
- }
- int main()
- {
- stos_kontenerow plac[MAX_R][MAX_A];
- int r, a;
- cout << "Podaj rozmiary placu:" << endl;
- cout << "rzedy: ";
- cin >> r;
- cout << "aleje: ";
- cin >> a;
- int ile_kont = gen_plac( plac, r, a );
- cout << "Wygenerowano " << ile_kont << " kontenerow" << endl;
- rysuj_plac( plac, r, a );
- pisz_plac ( plac, r, a );
- trojka_indeksow ind[MAX_R*MAX_A*MAX_K];
- char nazwa[MAX_N_T];
- int n;
- cout << "Podaj nazwe klienta ktorego kontenerow poszukujesz: ";
- cin >> nazwa;
- szukaj( plac, r, a, nazwa, ind, n );
- cout << "Kontenery klienta znajduja sie w nastepujacych miejscach" << endl;
- pisz_ind( ind, n );
- system("pause");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement