Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- #include <fstream>
- using namespace std;
- struct pracownik
- {
- int id;
- int kwota;
- };
- void wyplaty(string PlikWejsciowy, string Plikwyjsciowy)
- {
- const int N = 6;
- pracownik tab[N];
- int x, y;
- ifstream txt("PlikWejsciowy.txt", ios::in);
- if (txt.is_open())
- {
- for (int i = 0; !txt.eof(); i++)
- {
- if (i == 0)
- {
- txt>>tab[i].id;
- txt >> tab[i].kwota;
- }
- else
- {
- txt >> x;
- for (int j = 0; j < i; j++)
- {
- if (tab[i].id == x)
- {
- txt >> y;
- tab[i].kwota = tab[i].kwota + y;
- }
- }
- //txt >> y;
- tab[i].id = x;
- tab[i].kwota = y;
- }
- }
- }
- else
- {
- cout << "blad" << endl;
- }
- txt.close();
- for (int i = 0; i < N; i++)
- {
- for (int j = 0; j+1 < N; j++)
- {
- pracownik schowek;
- if (tab[j].id > tab[j + 1].id)
- {
- schowek = tab[j];
- tab[j] = tab[j + 1];
- tab[j + 1] = schowek;
- }
- }
- }
- ofstream bin("PlikWyjsciowy.txt", ios::out | ios::binary);
- if (bin.is_open())
- {
- for (int i = 0; i < N; i++)
- {
- bin << tab[i].id << " ";
- bin << tab[i].kwota << " ";
- }
- }
- else
- {
- cout << "blad" << endl;
- }
- bin.close();
- }
- int main()
- {
- int x, y;
- string PlikWejsciowy;
- string PlikWyjsciowy;
- wyplaty(PlikWejsciowy, PlikWyjsciowy);
- cin.get();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement