Advertisement
Guest User

Untitled

a guest
Oct 21st, 2019
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.83 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <time.h>
  4. #include <iostream>
  5. using namespace std;
  6.  
  7. struct Struktura
  8. {
  9.     int i;
  10.     char c;
  11.     float f;
  12. };
  13.  
  14. Struktura** losowanie(int N){
  15.     // dynamiczna tablica N wskaznikow na struktury
  16.     Struktura** tab = new Struktura*[N];
  17.     for (int i = 0; i < N; i++) {
  18.         // alokacja pamięci na pojedynczą strukture
  19.         tab[i] = new Struktura;
  20.        
  21.         tab[i]->i = rand() % 10000 - 1000;
  22.         if (i > 0) {
  23.             int j = 0;
  24.             while (j < i) {
  25.                 if (tab[i]->i == tab[j]->i) {
  26.                     tab[i]->i = rand() % 10000 - 1000;
  27.                 }
  28.                 else {
  29.                     j++;
  30.                 }
  31.             }
  32.         }
  33.         tab[i]->c = 98 + rand() % 19;
  34.         tab[i]->f = 1000 + N;
  35.     }
  36.  
  37.     return tab;
  38. }
  39.  
  40. int main() {
  41.     srand(time(NULL));
  42.     int count = 2;
  43.     Struktura** stk = new Struktura*[count];
  44.     stk = losowanie(count);
  45.  
  46.     cout << *stk;
  47.    
  48.  
  49.     return(0);
  50.  
  51. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement