Advertisement
Aleksandr_Grigoryev

19 и

May 24th, 2018
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.70 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3. using namespace std;
  4. struct Postavka
  5. {
  6.     int Ndet;
  7.     int post;
  8.     int Kolv;
  9.     int month;
  10.     int year;
  11.  
  12. };
  13. struct Complete
  14. {
  15.     int nomDet;
  16.     int nomPost;
  17.     int month;
  18.     int year;
  19.     int count;
  20. };
  21. void formBinPost(ifstream &f, ofstream &g)
  22. {
  23.     Postavka a;
  24.     while (f.peek() != EOF)
  25.     {
  26.         f >> a.Ndet >> a.post >> a.Kolv >> a.month >> a.year;
  27.         g.write((char *)&a, sizeof Postavka);
  28.     }
  29. }
  30. void formBinComplete(ifstream &f, ofstream &g)
  31. {
  32.     Complete b;
  33.     while (f.peek() != EOF)
  34.     {
  35.         f >> b.nomDet >> b.nomPost >> b.count >> b.month >> b.year;
  36.         g.write((char *)&b, sizeof Complete);
  37.     }
  38. }
  39. void formNewBin(ifstream &f, ifstream &f1, ofstream &g)
  40. {
  41.     Postavka a;
  42.     Complete b;
  43.     f.read((char *)&a, sizeof Postavka);
  44.     f1.read((char *)&b, sizeof Complete);
  45.     while (!f1.eof())
  46.     {
  47.         if (a.Ndet == b.nomDet && a.post == b.nomPost &&!f1.eof())
  48.         {
  49.             a.Kolv += b.count;
  50.             if (a.year < b.year)
  51.             {
  52.                 a.month = b.month;
  53.                 a.year = b.year;
  54.             }
  55.             if (a.year == b.year&&a.month < b.month)
  56.                 a.month = b.month;
  57.             g.write((char *)&a, sizeof Postavka);
  58.             f1.read((char *)&b, sizeof Complete);  
  59.             f.read((char *)&a, sizeof Postavka);
  60.         }
  61.        
  62.             else if ((a.Ndet != b.nomDet  && !f.eof()) || (a.post != b.nomPost && a.Ndet == b.nomDet && !f.eof()))
  63.             {
  64.                 if ((a.Ndet < b.nomDet) || (a.Ndet == b.nomDet&&a.post < b.nomPost))
  65.                 {
  66.                     g.write((char*)&a, sizeof(Postavka));
  67.                     f.read((char*)&a, sizeof(Postavka));
  68.                 }
  69.                 else if ((a.Ndet > b.nomDet) || (a.Ndet == b.nomDet && a.post > b.nomPost))
  70.                 {
  71.                     g.write((char*)&b, sizeof(Postavka));
  72.                     f1.read((char*)&b, sizeof(Complete));
  73.                 }
  74.             }
  75.     }
  76.  
  77.     if (f1.eof() && !f.eof())
  78.     {
  79.         while (!f.eof())
  80.         {
  81.             g.write((char *)&a, sizeof Postavka);
  82.             f.read((char *)&a, sizeof Postavka);
  83.         }
  84.     }
  85. }
  86. void showNewBin(ifstream &f)
  87. {
  88.     Postavka a;
  89.     while (f.peek() != EOF)
  90.     {
  91.         f.read((char *)&a, sizeof Postavka);
  92.         cout << a.Ndet << ' ' << a.post << ' ' << a.Kolv << ' ' << a.month << ' ' << a.year << endl;
  93.     }
  94. }
  95. int main()
  96. {
  97.     setlocale(LC_ALL, "RUS");
  98.     ifstream in("Поставки.txt");
  99.     ofstream outBinPost("Rezult.bin", ios::binary);
  100.     formBinPost(in, outBinPost);
  101.     in.close();
  102.     outBinPost.close();
  103.     ifstream in1("Новые.txt");
  104.     ofstream outBinRazriv("Text1.bin", ios::binary);
  105.     formBinComplete(in1, outBinRazriv);
  106.     in1.close();
  107.     outBinRazriv.close();
  108.     ifstream inBin("Rezult.bin", ios::binary);
  109.     ifstream inBin1("Text1.bin", ios::binary);
  110.     ofstream outBin("rezult1.bin", ios::binary);
  111.     formNewBin(inBin, inBin1, outBin);
  112.     outBin.close();
  113.     inBin.close();
  114.     inBin1.close();
  115.     ifstream outBinin("rezult1.bin", ios::binary);
  116.     showNewBin(outBinin);
  117.     system("pause");
  118.     return 0;
  119. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement