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
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
| #include "stdafx.h"
#include <iostream>
#include <fstream>
#include <stdlib.h>
#include <Windows.h>
using namespace std;
void main()
{
SetConsoleCP(1251);
SetConsoleOutputCP(1251);
setlocale(LC_ALL,"Russian");
int count=KolStrok();
Tab *Table=new Tab[count];
Free(Table,count);
GetText(Table);
Prin(Table,count);
GetData();
if(count==KolStrok()) PopularGirlName(Table,count);
else
{
delete []Table;
count=KolStrok();
Tab *Table2=new Tab[count];
Free(Table2,count);
GetText(Table2);
Prin(Table2,count);
PopularGirlName(Table2,count);
}
system("pause");
}
struct Tab
{
char name[13],family[13],otchestvo[13];
char pol;
int age,course;
};
int KolStrok()
{
ifstream f("input.txt");
int count=1;
while (!f.eof())
{
if (f.get()=='\n')
count++;
}
f.close();
return count;
}
void GetText(Tab *Table)
{
ifstream f("input.txt");
int stroka=0,pole=0,pos=0;
bool write=false;
char s;
while (!f.eof())
{
f.get(s);
if(s=='>')
{
write=false;
pos=0;
pole++;
}
if(write==true)
{
switch (pole)
{
case 0:
{
Table[stroka].family[pos]=s;
pos++;
break;
}
case 1:
{
Table[stroka].name[pos]=s;
pos++;
break;
}
case 2:
{
Table[stroka].otchestvo[pos]=s;
pos++;
break;
}
case 3:
{
Table[stroka].pol=s;
break;
}
case 4:
{
Table[stroka].age=atoi(&s)*10;
f.get(s);
Table[stroka].age+=atoi(&s);
pos++;
break;
}
case 5:
{
Table[stroka].course=atoi(&s);
break;
}
}
}
if(s=='<') write=true;
if(s=='\n')
{
stroka++;
pole=0;
}
}
f.close();
}
void Free(Tab *Table, int razm)
{
for (int i = 0; i < razm; i++)
{
for(int j=0;j<13;j++)
{
Table[i].family[j]=NULL;
Table[i].name[j]=NULL;
Table[i].otchestvo[j]=NULL;
}
Table[i].pol=NULL;
}
}
void Prin(Tab *Table, int razm)
{
for (int i = 0; i < razm; i++)
{
cout<<Table[i].family<<" "<<Table[i].name<<" "<<Table[i].otchestvo<<" "<<Table[i].pol<<" "<<Table[i].age<<" "<<Table[i].course<<endl;
}
cout<<endl;
}
void GetData()
{
Tab Table;
char answer;
bool norm;
do
{
norm=false;
cout<<"Хотите ли вы добавить запись?(д/н): ";
cin>>answer;
if(answer=='н' || answer=='Н' || answer=='д' || answer=='Д') norm=true;
else do
{
cout<<"Ответьте корректно:";
cin>>answer;
if(answer=='н' || answer=='Н' || answer=='д' || answer=='Д') norm=true;
} while(norm==false);
if(answer=='д' || answer=='Д')
{
cout<<"Введите фамилию:";
cin>>Table.family;
cout<<"Введите имя:";
cin>>Table.name;
cout<<"Введите отчество:";
cin>>Table.otchestvo;
norm=false;
cout<<"Введите пол (м/ж):";
cin>>Table.pol;
if(Table.pol=='М' || Table.pol=='Ж') {}
else if(Table.pol=='м') Table.pol='М';
else if(Table.pol=='ж') Table.pol='Ж';
else do
{
cout<<"Введите пол корректно:";
cin>>Table.pol;
if(Table.pol=='м' || Table.pol=='М')
{
Table.pol='М';
norm=true;
}
if(Table.pol=='ж' || Table.pol=='Ж')
{
Table.pol='Ж';
norm=true;
}
} while(norm==false);
cout<<"Введите возраст:";
cin>>Table.age;
if(Table.age>=16 && Table.age<=35) {}
else do
{
cout<<"Введите возраст корректно (16-35):";
cin>>Table.age;
} while(Table.age<16 || Table.age>35);
cout<<"Введите курс:";
cin>>Table.course;
if(Table.course>=1 && Table.course<=5) {}
else do
{
cout<<"Введите курс корректно (1-5):";
cin>>Table.course;
} while(Table.course<1 || Table.course>5);
ofstream out("input.txt", ios::app);
out<<'\n'<<"<"<<Table.family<<">,<"<<Table.name<<">,<"<<Table.otchestvo<<">,<"<<Table.pol<<">,<"<<Table.age<<">,<"<<Table.course<<">";
out.close();
}
} while(answer=='д' || answer=='Д');
cout<<endl;
}
void PopularGirlName(Tab *Table, int razm)
{
int str,kol=1,max=0;
for (int i = 0; i < razm; i++)
{
if(Table[i].pol=='Ж')
for (int j = 0; j < razm; j++)
if(strcmp(Table[i].name,Table[j].name)==0) kol++;
if(kol>max)
{
max=kol;
str=i;
}
kol=1;
}
if(max==0) cout<<"Женские имена отсутствуют.";
else cout<<"Самое распространенное женское имя: "<<Table[str].name<<". Количество: "<<max-1<<endl;
} |