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()
- {
- const int N = 3;
- dane*tab = new dane[N];
- int x = 0;
- int i = 0;
- int y = 0;
- int q = 0;
- int dlugosc = 0;
- int licznik = 0;
- ifstream infile;
- infile.open("infile.txt");
- ofstream outfile;
- outfile.open("outfile.txt");
- if (!infile.is_open())
- {
- return 0;
- }
- else
- {
- string nazwa_urz;
- string numer_urz;
- string pomiar;
- nast:
- while (!infile.eof())
- {
- getline(infile, nazwa_urz);
- getline(infile, numer_urz);
- getline(infile, pomiar);
- for (int z = 0; z < N; z++)
- {
- if (tab[z].nazwa == nazwa_urz)
- {
- tab[z].nazwa = nazwa_urz;
- tab[z].numer = numer_urz;
- while(pomiar[q]!='\n')
- {
- if(pomiar[i] != ' ')
- {
- dlugosc++;
- i++;
- }
- else
- {
- tab[z].ilosc++;
- tab[z].suma += stof(pomiar.substr(i, dlugosc));
- dlugosc = 0;
- q++;
- }
- }
- }
- goto nast;
- }
- }
- if (tab[x].nazwa.empty())
- {
- tab[x].nazwa = nazwa_urz;
- tab[x].numer = numer_urz;
- {
- while (pomiar[y] != ' ')
- {
- licznik++;
- dlugosc++;
- y++;
- }
- tab[x].ilosc++;
- tab[x].suma += stof(pomiar.substr(licznik - dlugosc, dlugosc));
- }
- x++;
- }
- }
- for (int j = 0; j < 2; j++)
- {
- outfile << tab[j].nazwa << endl;
- outfile << tab[j].numer << endl;
- float srednia = tab[j].suma / tab[j].ilosc;
- outfile << srednia << endl;
- }
- infile.close();
- outfile.close();
- cout << "udalo sie" << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement