Advertisement
Guest User

Untitled

a guest
Feb 10th, 2016
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.34 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. #include <fstream>
  4. using namespace std;
  5.  
  6.  
  7. struct pracownik
  8. {
  9.     int id;
  10.     int kwota;
  11. };
  12. void wyplaty(string PlikWejsciowy, string Plikwyjsciowy)
  13. {
  14.     const int N = 6;
  15.     pracownik tab[N];
  16.     int x, y;
  17.     ifstream txt("PlikWejsciowy.txt", ios::in);
  18.     if (txt.is_open())
  19.     {
  20.         for (int i = 0; !txt.eof(); i++)
  21.         {
  22.             if (i == 0)
  23.  
  24.             {
  25.                 txt>>tab[i].id;
  26.                 txt >> tab[i].kwota;
  27.             }
  28.             else
  29.             {
  30.                 txt >> x;
  31.                 for (int j = 0; j < i; j++)
  32.                 {
  33.                     if (tab[i].id == x)
  34.                     {
  35.                         txt >> y;
  36.                         tab[i].kwota = tab[i].kwota + y;
  37.                     }  
  38.                 }
  39.                 //txt >> y;
  40.                 tab[i].id = x;
  41.                 tab[i].kwota = y;
  42.                    
  43.             }
  44.         }
  45.     }
  46.     else
  47.     {
  48.         cout << "blad" << endl;
  49.     }
  50.     txt.close();
  51.     for (int i = 0; i < N; i++)
  52.     {
  53.         for (int j = 0; j+1 < N; j++)
  54.         {
  55.             pracownik schowek;
  56.             if (tab[j].id > tab[j + 1].id)
  57.             {
  58.                 schowek = tab[j];
  59.                 tab[j] = tab[j + 1];
  60.                 tab[j + 1] = schowek;
  61.             }
  62.         }
  63.     }
  64.     ofstream bin("PlikWyjsciowy.txt", ios::out | ios::binary);
  65.     if (bin.is_open())
  66.     {
  67.         for (int i = 0; i < N; i++)
  68.         {
  69.             bin << tab[i].id << " ";
  70.             bin << tab[i].kwota << " ";
  71.         }
  72.     }
  73.     else
  74.     {
  75.         cout << "blad" << endl;
  76.     }
  77.     bin.close();
  78. }
  79.  
  80. int main()
  81. {
  82.     int x, y;
  83.     string PlikWejsciowy;
  84.     string PlikWyjsciowy;
  85.     wyplaty(PlikWejsciowy, PlikWyjsciowy);
  86.     cin.get();
  87.     return 0;
  88. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement