Advertisement
Aleksandr_Grigoryev

ЕБУЧАЯ СЕМЕСТРОВАЯ

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