- 01
- 02
- 03
- 04
- 05
- 06
- 07
- 08
- 09
- 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
int main() {
ifstream input_file;
input_file.open("DATA");
string line;
while (getline(input_file, line)) {
size_t i = 0, j = 0;
string fname, sname;
float score;
char c = line[0];
while((c != ' ') && (j < line.size())) {
c = line[j];
j++;
}
fname = line.substr(i, j - i - 1);
i = j;
j += 1;
c = line[i];
while((c != ' ') && (j < line.size())) {
c = line[j];
j++;
}
sname = line.substr(i, j - i - 1);
i = j;
j += 1;
score = stof(line.substr(i, line.size()));
Data dat;
dat.fname = fname;
dat.sname = sname;
dat.score = score;
vec.push_back(dat);
}
const auto comp_fname = [](Data a, Data b){return a.fname >= b.fname;};
const auto comp_sname = [](Data a, Data b){return a.sname >= b.sname;};
const auto comp_score = [](Data a, Data b){return a.score >= b.score;};
const auto dcomp_fname = [](Data a, Data b){return a.fname < b.fname;};
const auto dcomp_sname = [](Data a, Data b){return a.sname < b.sname;};
const auto dcomp_score = [](Data a, Data b){return a.score < b.score;};
print(vec);
char choice = 0, order = 0;
cout << "Как сортировать (0 - Fфмилия, 1 - Iмя, 2 - CpegHuu_6aJlJl): ";
cin >> choice;
cout << "А в какмо порядке?7? (0 - по убыванию, 1 - по возрастанию)Ж ";
cin >> order;
if (choice == '0') {
if (order == '0') {
sort(vec.begin(), vec.end(), comp_fname);
} else {
sort(vec.begin(), vec.end(), dcomp_fname);
}
} else if (choice == '1') {
if (order == '0') {
sort(vec.begin(), vec.end(), comp_sname);
} else {
sort(vec.begin(), vec.end(), dcomp_sname);
}
} else if (choice == '2') {
if (order == '0') {
sort(vec.begin(), vec.end(), comp_score);
} else {
sort(vec.begin(), vec.end(), dcomp_score);
}
}
// и т.д. ...