Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <fstream>
- using namespace std;
- struct FIO
- {
- char name[15];
- char surname[15];
- char otchestvo[15];
- };
- struct adress
- {
- char city[15];
- char street[15];
- 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;
- int phone;
- adress adress;
- };
- void createBinBase(ifstream &f, ofstream &g)
- {
- base a;
- while (!f.eof())
- {
- f >> a.fio.surname >> a.fio.name >> a.fio.otchestvo;
- char str[9];
- 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;
- g.write((char *)&a, sizeof base);
- cout << a.DateOfBirth.year;
- }
- }
- int Age(int n,int y,int x)
- {
- int day1,month1,year1;
- int year=x,month=y,day=n;
- int count=0;
- cout << "enter date";
- cin >> day1>>month1>>year1;
- cout << day << ' ' << month <<' '<< year<<endl;
- if (year!=year1)
- count = year1 - year;
- else
- {
- if (month1 < month)
- {
- count = year1 - year;
- count++;
- }
- else if (month == month1)
- {
- if (day1 <= day)
- {
- count = year1 - year;
- count++;
- }
- }
- }
- return count;
- }
- void WorkBin(ifstream &f, ofstream &g)
- {
- base a;
- int k = 0;
- int age = 0;
- int sum=0;
- double srAge;
- f.read((char*)&a, sizeof base);
- while (f.peek() != EOF)
- {
- age = Age(a.DateOfBirth.day, a.DateOfBirth.month, a.DateOfBirth.year);
- while (!f.eof())
- k++;
- sum += age;
- f.read((char*)&a, sizeof base);
- }
- srAge = sum / k;
- f.seekg(0);
- f.read((char*)&a, sizeof base);
- while (f.peek() != EOF)
- {
- for (int i = 0; i <= 9; i++)
- {
- if (a.children == i)
- {
- if (Age(a.DateOfBirth.day, a.DateOfBirth.month, a.DateOfBirth.year) > srAge && a.adress.house % 2 == 0)
- g.write((char*)&a, sizeof base);
- else
- f.read((char*)&a, sizeof base);
- }
- else
- f.read((char*)&a, sizeof base);
- }
- }
- }
- void showResult(ifstream &f)
- {
- base a;
- 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.education<<endl;
- }
- else
- {
- cout << endl;
- cout << a.fio.surname << ' ' << a.fio.name << ' ' << a.fio.otchestvo << ' ' << Age << a.education << endl;
- cout << a.adress.city << 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