-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path5_11_17_Task3-4
96 lines (88 loc) · 2.53 KB
/
5_11_17_Task3-4
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
#include <iostream>
using namespace std;
struct Student {
public:
char FIO[512];
int mark[6];
double middleMark() {
double r = 0;
for (int i = 0; i < 6; i++) {
r = r + mark[i];
}
return r/6;
}
bool goneAway() {
bool r = 0;
int schet_dolgov = 0;
for (int i = 0; i < 6; i++) {
if (mark[i] <= 2) schet_dolgov++;
}
if (schet_dolgov >= 3) r = 1;
return r;
}
bool grantEarned() {
bool r = 1;
for (int i = 0; i < 6; i++) {
if (mark[i] <= 3) r = 0;
}
return r;
}
}student[10000];
double middleClassMark(int n, Student ar[]){
for(int i = 0; i < n - 1; i++){
for(int j = i + 1; j < n; j++){
if(ar[i].middleMark() > ar[j].middleMark()) swap(ar[i], ar[j]);
}
}
double r = 0;
for(int i = 2; i < n - 2; i++){
r = r + ar[i].middleMark();
}
return r/(n-4);
}
int awayGoers(int n, Student ar[]){
int r = 0;
for(int i = 0; i < n; i++){
if(ar[i].goneAway()) r++;
}
return r;
}
int grantGetters(int n, Student ar[]){
int r = 0;
for(int i = 0; i < n; i++)if(ar[i].grantEarned() == 1) r++;
return r;
}
int dutiers(int n, Student ar[]){
int r = 0;
for(int i = 0; i < n; i++){
bool dolgnik = 0;
for(int j = 0; j < 6; j++) if(ar[i].mark[j] <= 2) dolgnik = 1;
if(dolgnik) r++;
}
return r;
}
int main() {
int n;
cout << "Type students quantity\n";
cin >> n;
for(int i = 0; i<n; i++) {
cout << "Type the marks of " << i+1 << " student(break with space)\n";
for(int j = 0; j < 6; j++) cin >> student[i].mark[j];
cout << "Type the students' lastnname. Type the dot at the end.\n";
int j = 0;
do{
cin >> student[i].FIO[j];
j++;
}while(student[i].FIO[j-1] != '.');
cout << student[i].middleMark() << ";\n";
int dutyCounter = 0;
for(int j = 0; j < 6; j++){
if(student[i].mark[j] <= 2) dutyCounter++;
}
if(student[i].goneAway()){cout << " has gone away\n";}
else if(dutyCounter == 1)cout << " has duty\n";
else if(student[i].grantEarned()){cout << " has grant for education\n";}
}
cout << "Middle class mark is " << middleClassMark(n, student) << "; There are " << dutiers(n, student) << " dutiers in the class; " << awayGoers(n, student) << " had gone away; " << grantGetters(n, student) << " have grants for education";
return 0;
}