Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <fstream>
- using namespace std;
- const int n = 10;
- struct FIO
- {
- char name[30];
- char surname[30];
- char otchestvo[30];
- };
- struct adress
- {
- char city[30];
- char street[30];
- int house;
- int apartment;
- };
- struct date
- {
- int day;
- int month;
- int year;
- };
- struct base
- {
- FIO fio;
- date DateOfBirth;
- char education;
- char MaritalSatus;
- int children;
- char profession;
- char phone[9];
- adress adress;
- };
- void createBinBase(ifstream &f, ofstream &g)
- {
- base a;
- char str[9];
- while (f.peek() != EOF)
- {
- f >> a.fio.surname >> a.fio.name >> a.fio.otchestvo;
- f >> str;
- int num = 0;
- num = (str[0] - '0') * 10 + str[1] - '0';
- a.DateOfBirth.day = num;
- num = 0;
- num = (str[2] - '0') * 10 + str[3] - '0';
- a.DateOfBirth.month = num;
- num = 0;
- num = (str[4] - '0') * 1000 + (str[5] - '0') * 100 + (str[6] - '0') * 10 + (str[7] - '0');
- a.DateOfBirth.year = num;
- f>> a.education >> a.MaritalSatus >> a.children >> a.profession >> a.adress.city >> a.adress.street >> a.adress.house >> a.adress.apartment>>a.phone;
- g.write((char *)&a, sizeof base);
- }
- }
- double Age(int n,int y,int x,int n1,int y1,int x1)
- {
- int day1=n1,month1=y1,year1=x1;
- int year=x,month=y,day=n;
- int count = 0;
- count = year1 - year;
- if (month1 > month)
- count--;
- if (month == month1 && day1 > day) //якобы высчитываю возраст
- count--;
- return count;
- }
- void WorkBin(ifstream &f, ofstream &g)
- {
- base a;
- int k = 0;
- int sum = 0;
- int day1, month1, year1;
- cout << "date today";
- cin >> day1 >> month1 >> year1;
- double srAge[n] = {0};
- int count[n] = {0};
- for (int j = 0; j < 10; j++)
- {
- sum = 0;
- while (!f.eof())
- {
- f.read((char*)&a, sizeof base);
- if (a.children == j)
- {
- sum +=Age(a.DateOfBirth.day, a.DateOfBirth.month, a.DateOfBirth.year, day1, month1, year1);
- count[j]++;
- cout << sum<<endl;
- }
- }
- //srAge[j] = (sum / count[j]);
- }
- /*for (int i = 0; i < 10; i++)
- {
- while (!f.eof())
- {
- f.read((char*)&a, sizeof base);
- if ((Age(a.DateOfBirth.day, a.DateOfBirth.month, a.DateOfBirth.year, day1, month1, year1) > srAge[i]) && (a.adress.house % 2 == 0) && (a.children == i))
- {
- g.write((char*)&a, sizeof base);
- cout << a.children;
- }
- }
- f.clear();
- f.seekg(0, ios_base::beg);
- }*/
- }
- void showResult(ifstream &f)
- {
- base a;
- int year1 = 2018;
- int month1 = 4;
- int day1 = 6;
- char temp[15] = " "; // вывожу для каждого города
- while (!f.eof())
- {
- f.read((char *)&a, sizeof base);
- if (strcmp(a.adress.city, temp) == 0)
- {
- 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;
- }
- else
- {
- cout << endl;
- cout << a.adress.city << endl;
- 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;
- strcpy_s(temp, a.adress.city);
- }
- }
- }
- int main()
- {
- setlocale(LC_ALL, "RUS");
- ifstream finTXTbase("base.txt");
- ofstream foutBINbase("base.bin", ios::binary);
- createBinBase(finTXTbase, foutBINbase);
- foutBINbase.close();
- finTXTbase.close();
- ifstream finBINbase("base.bin", ios::binary);
- ofstream foutBinResult("result.bin", ios::binary);
- WorkBin(finBINbase,foutBinResult);
- finBINbase.close();
- foutBinResult.close();
- ifstream finBINResult("result.bin", ios::binary);
- showResult(finBINResult);
- finBINResult.close();
- system("pause");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement