Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <fstream>
- using namespace std;
- struct Postavka
- {
- int Ndet;
- int post;
- int Kolv;
- int month;
- int year;
- };
- struct Complete
- {
- int nomDet;
- int nomPost;
- int month;
- int year;
- int count;
- };
- void formBinPost(ifstream &f, ofstream &g)
- {
- Postavka a;
- while (f.peek() != EOF)
- {
- f >> a.Ndet >> a.post >> a.Kolv >> a.month >> a.year;
- g.write((char *)&a, sizeof Postavka);
- }
- }
- void formBinComplete(ifstream &f, ofstream &g)
- {
- Complete b;
- while (f.peek() != EOF)
- {
- f >> b.nomDet >> b.nomPost >> b.count >> b.month >> b.year;
- g.write((char *)&b, sizeof Complete);
- }
- }
- void formNewBin(ifstream &f, ifstream &f1, ofstream &g)
- {
- Postavka a;
- Complete b;
- f.read((char *)&a, sizeof Postavka);
- f1.read((char *)&b, sizeof Complete);
- while (!f1.eof())
- {
- if (a.Ndet == b.nomDet && a.post == b.nomPost &&!f1.eof())
- {
- a.Kolv += b.count;
- if (a.year < b.year)
- {
- a.month = b.month;
- a.year = b.year;
- }
- if (a.year == b.year&&a.month < b.month)
- a.month = b.month;
- g.write((char *)&a, sizeof Postavka);
- f1.read((char *)&b, sizeof Complete);
- f.read((char *)&a, sizeof Postavka);
- }
- else if ((a.Ndet != b.nomDet && !f.eof()) || (a.post != b.nomPost && a.Ndet == b.nomDet && !f.eof()))
- {
- if ((a.Ndet < b.nomDet) || (a.Ndet == b.nomDet&&a.post < b.nomPost))
- {
- g.write((char*)&a, sizeof(Postavka));
- f.read((char*)&a, sizeof(Postavka));
- }
- else if ((a.Ndet > b.nomDet) || (a.Ndet == b.nomDet && a.post > b.nomPost))
- {
- g.write((char*)&b, sizeof(Postavka));
- f1.read((char*)&b, sizeof(Complete));
- }
- }
- }
- if (f1.eof() && !f.eof())
- {
- while (!f.eof())
- {
- g.write((char *)&a, sizeof Postavka);
- f.read((char *)&a, sizeof Postavka);
- }
- }
- }
- void showNewBin(ifstream &f)
- {
- Postavka a;
- while (f.peek() != EOF)
- {
- f.read((char *)&a, sizeof Postavka);
- cout << a.Ndet << ' ' << a.post << ' ' << a.Kolv << ' ' << a.month << ' ' << a.year << endl;
- }
- }
- int main()
- {
- setlocale(LC_ALL, "RUS");
- ifstream in("Поставки.txt");
- ofstream outBinPost("Rezult.bin", ios::binary);
- formBinPost(in, outBinPost);
- in.close();
- outBinPost.close();
- ifstream in1("Новые.txt");
- ofstream outBinRazriv("Text1.bin", ios::binary);
- formBinComplete(in1, outBinRazriv);
- in1.close();
- outBinRazriv.close();
- ifstream inBin("Rezult.bin", ios::binary);
- ifstream inBin1("Text1.bin", ios::binary);
- ofstream outBin("rezult1.bin", ios::binary);
- formNewBin(inBin, inBin1, outBin);
- outBin.close();
- inBin.close();
- inBin1.close();
- ifstream outBinin("rezult1.bin", ios::binary);
- showNewBin(outBinin);
- system("pause");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement