include stdafx define using namespace std struct idk string name strin

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
#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;
}