Advertisement
masx1996

Untitled

Feb 11th, 2016
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.68 KB | None | 0 0
  1. #include<iostream>
  2. #include<string>
  3. #include<fstream>
  4. using namespace std;
  5. struct dane
  6. {
  7.     string nazwa;
  8.     string numer;
  9.     int ilosc;
  10.     float suma;
  11. };
  12.  
  13. int main()
  14. {
  15.     const int N = 3;
  16.     dane*tab = new dane[N];
  17.     int x = 0;
  18.     int i = 0;
  19.     int y = 0;
  20.     int q = 0;
  21.     int dlugosc = 0;
  22.     int licznik = 0;
  23.     ifstream infile;
  24.     infile.open("infile.txt");
  25.     ofstream outfile;
  26.     outfile.open("outfile.txt");
  27.     if (!infile.is_open())
  28.     {
  29.         return 0;
  30.     }
  31.     else
  32.     {
  33.         string nazwa_urz;
  34.         string numer_urz;
  35.         string pomiar;
  36.         nast:
  37.         while (!infile.eof())
  38.         {
  39.  
  40.             getline(infile, nazwa_urz);
  41.             getline(infile, numer_urz);
  42.             getline(infile, pomiar);
  43.             for (int z = 0; z < N; z++)
  44.             {
  45.                 if (tab[z].nazwa == nazwa_urz)
  46.                 {
  47.                     tab[z].nazwa = nazwa_urz;
  48.                     tab[z].numer = numer_urz;
  49.                     while(pomiar[q]!='\n')
  50.                     {
  51.                         if(pomiar[i] != ' ')
  52.                         {
  53.                             dlugosc++;
  54.                             i++;
  55.                         }
  56.                         else
  57.                         {
  58.                             tab[z].ilosc++;
  59.                             tab[z].suma += stof(pomiar.substr(i, dlugosc));
  60.                             dlugosc = 0;
  61.                             q++;
  62.                         }
  63.                 }
  64.             }
  65.                     goto nast;
  66.                 }
  67.             }
  68.  
  69.             if (tab[x].nazwa.empty())
  70.             {
  71.                 tab[x].nazwa = nazwa_urz;
  72.                 tab[x].numer = numer_urz;
  73.                 {
  74.                     while (pomiar[y] != ' ')
  75.                     {
  76.                         licznik++;
  77.                         dlugosc++;
  78.                         y++;
  79.                     }
  80.                     tab[x].ilosc++;
  81.                     tab[x].suma += stof(pomiar.substr(licznik - dlugosc, dlugosc));
  82.                 }
  83.                 x++;
  84.             }
  85.        
  86.         }
  87.         for (int j = 0; j < 2; j++)
  88.         {
  89.             outfile << tab[j].nazwa << endl;
  90.             outfile << tab[j].numer << endl;
  91.             float srednia = tab[j].suma / tab[j].ilosc;
  92.             outfile << srednia << endl;
  93.         }
  94.         infile.close();
  95.         outfile.close();
  96.         cout << "udalo sie" << endl;
  97.  
  98.         return 0;
  99.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement