Aleksandr_Grigoryev

СУКАААААААААААААААА

Apr 5th, 2018
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.35 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3. using namespace std;
  4. struct FIO
  5. {
  6.     char name[15];
  7.     char surname[15];
  8.     char otchestvo[15];
  9. };
  10. struct adress
  11. {
  12.     char city[15];
  13.     char street[15];
  14.     int house;
  15.     int apartment;
  16. };
  17. struct date
  18. {
  19.     int day;
  20.     int month;
  21.     int year;
  22. };
  23. struct base
  24. {
  25.     FIO fio;
  26.     date DateOfBirth;
  27.     char education;
  28.     char MaritalSatus;
  29.     int children;
  30.     char profession;
  31.     int phone;
  32.     adress adress;
  33. };
  34. void createBinBase(ifstream &f, ofstream &g)
  35. {
  36.     base a;
  37.     while (!f.eof())
  38.     {
  39.         f >> a.fio.surname >> a.fio.name >> a.fio.otchestvo;
  40.         char str[9];
  41.         f >> str;
  42.         int num = 0;
  43.         num = (str[0] - '0') * 10 + str[1] - '0';
  44.         a.DateOfBirth.day = num;
  45.         num = 0;
  46.         num = (str[2] - '0') * 10 + str[3] - '0';
  47.         a.DateOfBirth.month = num;
  48.         num = 0;
  49.         num = (str[4] - '0') * 1000 + (str[5] - '0') * 100 + (str[6] - '0') * 10 + str[7] - '0';
  50.         a.DateOfBirth.year = num;
  51.         f>> a.education >> a.MaritalSatus >> a.children >> a.profession >> a.adress.city >> a.adress.street >> a.adress.house >> a.adress.apartment;
  52.         g.write((char *)&a, sizeof base);
  53.         cout << a.DateOfBirth.year;
  54.     }
  55. }
  56. int Age(int n,int y,int x)
  57. {
  58.     int day1,month1,year1;
  59.     int year=x,month=y,day=n;
  60.     int count=0;
  61.     cout << "enter date";
  62.     cin >> day1>>month1>>year1;
  63.     cout << day << ' ' << month <<' '<< year<<endl;
  64.     if (year!=year1)
  65.     count = year1 - year;
  66.     else
  67.     {
  68.         if (month1 < month)
  69.         {  
  70.             count = year1 - year;
  71.             count++;
  72.         }
  73.         else if (month == month1)
  74.         {
  75.             if (day1 <= day)
  76.             {
  77.                 count = year1 - year;
  78.                 count++;
  79.             }
  80.         }
  81.     }
  82.     return  count;
  83. }
  84. void WorkBin(ifstream &f, ofstream &g)
  85. {
  86.     base a;
  87.     int k = 0;
  88.     int age = 0;
  89.     int sum=0;
  90.     double srAge;
  91.     f.read((char*)&a, sizeof base);
  92.     while (f.peek() != EOF)
  93.     {
  94.         age = Age(a.DateOfBirth.day, a.DateOfBirth.month, a.DateOfBirth.year);
  95.         while (!f.eof())
  96.             k++;
  97.         sum += age;
  98.         f.read((char*)&a, sizeof base);
  99.     }
  100.     srAge = sum / k;
  101.     f.seekg(0);
  102.  
  103.     f.read((char*)&a, sizeof base);
  104.         while (f.peek() != EOF)
  105.     {
  106.             for (int i = 0; i <= 9; i++)
  107.             {
  108.                 if (a.children == i)
  109.                 {
  110.                     if (Age(a.DateOfBirth.day, a.DateOfBirth.month, a.DateOfBirth.year) > srAge && a.adress.house % 2 == 0)
  111.                         g.write((char*)&a, sizeof base);
  112.                     else
  113.                     f.read((char*)&a, sizeof base);
  114.                 }
  115.                 else
  116.                 f.read((char*)&a, sizeof base);
  117.             }
  118.     }
  119. }
  120. void showResult(ifstream &f)
  121. {
  122.     base a;
  123.     char temp[15] = " ";
  124.         while (!f.eof())
  125.         {
  126.             f.read((char *)&a, sizeof base);
  127.             if (strcmp(a.adress.city, temp) == 0)
  128.             {
  129.                 cout << a.fio.surname << ' ' << a.fio.name << ' ' << a.fio.otchestvo << ' ' << Age << a.education<<endl;
  130.             }
  131.             else
  132.             {
  133.                 cout << endl;
  134.                 cout << a.fio.surname << ' ' << a.fio.name << ' ' << a.fio.otchestvo << ' ' << Age << a.education << endl;
  135.                 cout << a.adress.city << endl;
  136.                 strcpy_s(temp, a.adress.city);
  137.             }
  138.         }
  139. }
  140. int main()
  141. {
  142.     setlocale(LC_ALL, "RUS");
  143.     ifstream finTXTbase("base.txt");
  144.     ofstream foutBINbase("base.bin", ios::binary);
  145.     createBinBase(finTXTbase, foutBINbase);
  146.     foutBINbase.close();
  147.     finTXTbase.close();
  148.     /*ifstream finBINbase("base.bin", ios::binary);
  149.     ofstream foutBinResult("result.bin", ios::binary);
  150.     WorkBin(finBINbase,foutBinResult);
  151.     finBINbase.close();
  152.     foutBinResult.close();
  153.     ifstream finBINResult("result.bin", ios::binary);
  154.     showResult(finBINResult);
  155.     finBINResult.close();*/
  156.     system("pause");
  157.     return 0;
  158. }
Advertisement
Add Comment
Please, Sign In to add comment