Advertisement
Guest User

Untitled

a guest
Apr 7th, 2020
180
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.02 KB | None | 0 0
  1. #include <iostream>
  2. #include <cstdlib>
  3. #include <fstream>
  4. #include <ctime>
  5. #include <vector>
  6.  
  7. void generazione_dati (int &a, int &b) {
  8.     std::fstream f;
  9.     f.open ("conf.txt");
  10.     a = rand()% 25 + 1;
  11.     b = rand()% 25 + 1;
  12.     f << a << b << ",";
  13.     f.close();
  14. }
  15.  
  16. void riempimento_dati (int a, int b, std::vector<std::vector<int>> &v) {
  17.     for (int i=0; i<a; ++i) {
  18.         for (int j=0; i<b; ++j)
  19.             v[i].push_back(rand()% 256);
  20.     }
  21. }
  22.  
  23. void caricamento_dati (int a, int b, std::vector<std::vector<int>> &v) {
  24.     std::fstream f;
  25.     f.open ("data.csv");
  26.     for (int i=0; i<a; ++i) {
  27.         for (int j=0; j<b; ++j) {
  28.             if (j = b-1)
  29.                 f << v [i][j];
  30.             else
  31.                 f << v [i][j] << ",";
  32.         }
  33.         f << "\n";
  34.     }
  35.     f.close();
  36. }
  37.  
  38. int main() {
  39.     srand(time(NULL));
  40.     int a, b;
  41.     generazione_dati (a, b);
  42.     std::vector<std::vector<int>> v;
  43.     riempimento_dati (a, b, v);
  44.     caricamento_dati (a, b, v);
  45.     return 0;
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement