Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- #include<string>
- #include<fstream>
- using namespace std;
- struct dane
- {
- string nazwa;
- string numer;
- int ilosc;
- float suma;
- };
- int main()
- {
- fstream infile;
- ofstream outfile;
- string nazwa;
- string numer;
- string pomiar;
- infile.open("pomiary.txt");
- outfile.open("wynik.txt");
- const int N = 3;
- int x = 0;
- int y = 0;
- int z = 0;
- int ilosc = 0;
- int dlugosc = 0;
- int suma = 0;
- dane tab[N];
- nast:
- while (!infile.eof())
- {
- getline(infile, nazwa);
- getline(infile, numer);
- getline(infile, pomiar);
- while (pomiar[x] != '/n')
- {
- while (pomiar[x] != ' ')
- {
- x++;
- dlugosc++;
- }
- ilosc++;
- suma += stof(pomiar.substr(x - dlugosc, dlugosc));
- dlugosc = 0;
- x++;
- cout << suma << "----" << ilosc << endl;
- }
- for (int i = 0; i < N; i++)
- {
- if (tab[i].nazwa == nazwa)
- {
- tab[i].nazwa = nazwa;
- tab[i].numer = numer;
- tab[i].ilosc += ilosc;
- tab[i].suma += suma;
- ilosc = 0;
- suma = 0;
- goto nast;
- }
- }
- tab[z].nazwa = nazwa;
- tab[z].numer = numer;
- tab[z].ilosc = ilosc;
- tab[z].suma = suma;
- suma = 0;
- ilosc = 0;
- z++;
- }
- for (int i = 0; i < N; i++)
- {
- outfile << tab[i].nazwa << endl;
- outfile << tab[i].numer << endl;
- outfile << tab[i].suma / tab[i].ilosc << endl;
- }
- infile.close();
- outfile.close();
- return 0;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement