Advertisement
masx1996

Untitled

Feb 11th, 2016
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.36 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.     fstream infile;
  16.     ofstream outfile;
  17.     string nazwa;
  18.     string numer;
  19.     string pomiar;
  20.     infile.open("pomiary.txt");
  21.     outfile.open("wynik.txt");
  22.     const int N = 3;
  23.     int x = 0;
  24.     int y = 0;
  25.     int z = 0;
  26.     int ilosc = 0;
  27.     int dlugosc = 0;
  28.     int suma = 0;
  29.     dane tab[N];
  30. nast:
  31.     while (!infile.eof())
  32.     {
  33.         getline(infile, nazwa);
  34.         getline(infile, numer);
  35.         getline(infile, pomiar);
  36.         while (pomiar[x] != '/n')
  37.         {
  38.             while (pomiar[x] != ' ')
  39.             {
  40.                 x++;
  41.                 dlugosc++;
  42.             }
  43.             ilosc++;
  44.             suma += stof(pomiar.substr(x - dlugosc, dlugosc));
  45.             dlugosc = 0;
  46.             x++;
  47.             cout << suma << "----" << ilosc << endl;
  48.         }
  49.  
  50.         for (int i = 0; i < N; i++)
  51.         {
  52.             if (tab[i].nazwa == nazwa)
  53.             {
  54.                 tab[i].nazwa = nazwa;
  55.                 tab[i].numer = numer;
  56.                 tab[i].ilosc += ilosc;
  57.                 tab[i].suma += suma;
  58.                 ilosc = 0;
  59.                 suma = 0;
  60.                 goto nast;
  61.             }
  62.         }
  63.  
  64.         tab[z].nazwa = nazwa;
  65.         tab[z].numer = numer;
  66.         tab[z].ilosc = ilosc;
  67.         tab[z].suma = suma;
  68.         suma = 0;
  69.         ilosc = 0;
  70.         z++;
  71.     }
  72.     for (int i = 0; i < N; i++)
  73.     {
  74.         outfile << tab[i].nazwa << endl;
  75.         outfile << tab[i].numer << endl;
  76.         outfile << tab[i].suma / tab[i].ilosc << endl;
  77.     }
  78.     infile.close();
  79.     outfile.close();
  80.     return 0;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement