#include "stdafx.h"
#define N 5
using namespace std;
struct idk
{
string name;
string fth;
};
struct Person
{
struct idk fio;
int ChildAmount;
string ChildBrth[5];
};
struct Date
{
int year;
int mth;
int day;
};
string creator_date(string str1)
{
Date idk;
int year, mth, day;
year = (rand() % (2013 - 1990 + 1) + 1990);
mth = (1 + rand() % 12);
if ((mth == 2) && (year % 4 == 0))
day = (1 + rand() % 28);
else if ((mth % 2 == 0) && (mth != 2))
day = (1 + rand() % 30);
else
day = (1 + rand() % 31);
str1 = to_string(idk.year = year) + '.';
str1 += to_string(idk.mth = mth) + '.';
str1 += to_string(idk.day = day);
return str1;
};
int calculator(string str1)
{
int i = 0, date[3], cnt = 0;
while ((str1[i] <= '.') && (i < 3))
{
date[i] = atoi(str1.c_str());
i++;
}
if ((date[0] <= 1996) && (date[1] <= 12) && (date[2] <= 12))
cnt++;
return cnt;
};
string re_fth()
{
ifstream Fth("Fth.txt");
int filelen = 0, i = 0;
string buff;
while (!Fth.eof())
{
string temp;
Fth >> temp;
filelen++;
}
int x = 1 + rand() % filelen;
Fth.seekg(0, Fth.beg);
while (i < x)
{
Fth >> buff;
i++;
}
Fth.close();
return buff;
}
void Cpy(int *LenFio)
{
ifstream old("Out1.txt");
ofstream New("Out2.txt");
string temp;
for (int i = 0; i < N; i++)
{
getline(old, temp, '\n');
New << temp + " Длина ФИО = " + to_string(LenFio[i]) + " символов." + '\n';
}
old.close();
New.close();
}
int _tmain()
{
setlocale(LC_ALL, "Rus");
string str, date;
Person a[N];
srand(time(NULL));
int k = 0, LenFio[N];
ifstream FI("Names.txt");
while ((!FI.eof()) && (k < N))
{
getline(FI, a[k].fio.name, '\n');
int strlen = a[k].fio.name.length();
if ((a[k].fio.name[strlen - 1] == 'а') || (a[k].fio.name[strlen - 1] == 'я'))
a[k].fio.fth = re_fth() + "овна";
else
a[k].fio.fth = re_fth() + "ович";
k++;
}
FI.close();
ofstream fout("Out1.txt");
for (int i = 0; i < N; i++)
{
int counter = 0;
int x = (1 + rand() % 5);
a[i].ChildAmount = x;
for (int j = 0; j < x; j++)
{
a[i].ChildBrth[j] += creator_date(date);
counter += calculator(a[i].ChildBrth[j]);
}
cout << "Рабочий " << a[i].fio.name << " " << a[i].fio.fth << "\tполучает " << counter << " пособие(я);\n";
fout << "Рабочий " << a[i].fio.name << " " << a[i].fio.fth << "\tполучает " << counter << " пособие(я);\n";
LenFio[i] = a[i].fio.name.length() + a[i].fio.fth.length() + 1;
counter = 0;
}
fout.close();
Cpy(LenFio);
_getch();
return 0;
}