include time include string include stdio include stdlib define 20 str

  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
#include <time.h>
#include <string>
#include <stdio.h>
#include <stdlib.h>
#define N 20
struct student {
int year;
char male;
std::string name;
};
student* FillData(int n) {
srand(time(NULL));
if (n > 20) n = 20;
student* result = new struct student [n];
for (int i = 0; i < n; i++) {
switch (i) {
case 0:
result[i].name = "Арапов";
result[i].male = 'M';
break;
case 1:
result[i].name = "Бабченков";
result[i].male = 'M';
break;
case 2:
result[i].name = "Бильданов";
result[i].male = 'M';
break;
case 3:
result[i].name = "Большаков";
result[i].male = 'M';
break;
case 4:
result[i].name = "Гаврилов";
result[i].male = 'M';
break;
case 5:
result[i].name = "Ефимова";
result[i].male = 'F';
break;
case 6:
result[i].name = "Замащиков";
result[i].male = 'M';
break;
case 7:
result[i].name = "Зуев";
result[i].male = 'M';
break;
case 8:
result[i].name = "Комаров";
result[i].male = 'M';
break;
case 9:
result[i].name = "Коренева";
result[i].male = 'F';
break;
case 10:
result[i].name = "Козлова";
result[i].male = 'F';
break;
case 11:
result[i].name = "Кузнецов";
result[i].male = 'M';
break;
case 12:
result[i].name = "Mатуляк";
result[i].male = 'M';
break;
case 13:
result[i].name = "Mоргулян";
result[i].male = 'M';
break;
case 14:
result[i].name = "Николаев";
result[i].male = 'M';
break;
case 15:
result[i].name = "Панас";
result[i].male = 'M';
break;
case 16:
result[i].name = "Петров";
result[i].male = 'M';
break;
case 17:
result[i].name = "Рауткин";
result[i].male = 'M';
break;
case 18:
result[i].name = "Самуров";
result[i].male = 'M';
break;
case 19:
result[i].name = "Старченко";
result[i].male = 'M';
break;
}
result[i].year = 1990 + rand() % 10;
}
return result;
}
int main() {
FILE* file1 = fopen("full.txt", "w");
FILE* file2 = fopen("filtered.txt", "w");
student* data = FillData(N);
for (int i = 0; i < N; i++) {
fprintf(file1, "%s %d %c\n", data[i].name.c_str(), data[i].year, data[i].male);
}
for (int i = 0; i < N; i++) {
if (data[i].male == 'M' && data[i].year < 1996)
fprintf(file2, "%s %d %c\n", data[i].name.c_str(), data[i].year, data[i].male);
}
delete [] data;
fclose(file1);
fclose(file2);
}