-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSiaod.cpp
More file actions
159 lines (139 loc) · 5.48 KB
/
Copy pathSiaod.cpp
File metadata and controls
159 lines (139 loc) · 5.48 KB
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
// Siaod.cpp : Этот файл содержит функцию "main". Здесь начинается и заканчивается выполнение программы.
//
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
static vector<string> disciplines = { "math", "science", "programming", "history" };
struct Exam_record
{
int stud_id;
int exam_id;
int exam_score;
int activity_score;
int exam_mark;
};
int score_to_mark(int summary_score);
void insert_record(vector<Exam_record>& records, int stud_id, int exam_id, int exam_score, int activity_score);
void insert_record(vector<Exam_record>& records);
void change_exam_score(vector<Exam_record>& records);
void print_records(vector<Exam_record>& records);
void print_records(vector<Exam_record>& records, int stud_id);
void print_records(vector<Exam_record>& records, int exam_id);
void print_records(vector<Exam_record>& records,int stud_id, int exam_id);
int main()
{
vector<Exam_record> records;
insert_record(records, 1, 0, 43, 20);
insert_record(records, 1, 1, 39, 18);
insert_record(records, 2, 0, 18, 3);
insert_record(records, 2, 1, 43, 20);
insert_record(records, 2, 2, 22, 7);
//change_exam_score(records);
//insert_record(records);
print_records(records);
cout << endl;
print_records(records, 2);
cout << "done" << endl;
return 0;
}
int score_to_mark(int summary_score)
{
int mark;
if (summary_score <= 16) mark = 2;
else if (summary_score <= 45) mark = 3;
else if (summary_score <= 60) mark = 4;
else mark = 5;
return mark;
}
void insert_record(vector<Exam_record>& records, int stud_id, int exam_id, int exam_score, int activity_score)
{
Exam_record newRecord = {stud_id, exam_id, exam_score, activity_score, score_to_mark(exam_score + activity_score)};
bool flag = true; // the records is not a dublicate
for (int i = 0; i < records.size(); i++)
{
if (records[i].stud_id == newRecord.stud_id && records[i].exam_id == newRecord.exam_id) //existing record will be changed
{
records[i].exam_score = exam_score;
records[i].activity_score = activity_score;
records[i].exam_mark = score_to_mark(exam_score + activity_score);
flag = false;
break;
}
}
if (flag) records.push_back(newRecord);
}
void insert_record(vector<Exam_record>& records) // input with a keyboard
{
int stud_id, exam_id, exam_score, activity_score;
cout << "insert student's id" << endl;
cin >> stud_id;
cout << "insert exam's id: ";
for (int i = 0; i < disciplines.size(); i++) cout << disciplines[i] << " - " << i << ", ";
cout << endl;
cin >> exam_id;
cout << "insert score for the exam" << endl;
cin >> exam_score;
cout << "insert score for the activity" << endl;
cin >> activity_score;
insert_record(records, stud_id, exam_id, exam_score, activity_score);
}
void change_exam_score(vector<Exam_record>& records)
{
int stud_id, exam_id, exam_score;
cout << "insert student's id" << endl;
cin >> stud_id;
cout << "insert exam's id: ";
for (int i = 0; i < disciplines.size(); i++) cout << disciplines[i] << " - " << i << ", ";
cout << endl;
cin >> exam_id;
cout << "insert new exam's score" << endl;
cin >> exam_score;
bool flag = true; // the records does not exist
for (int i = 0; i < records.size(); i++)
{
if (records[i].stud_id == stud_id && records[i].exam_id == exam_id) //existing record will be changed
{
records[i].exam_score = exam_score;
records[i].exam_mark = score_to_mark(exam_score + records[i].activity_score);
flag = false;
break;
}
}
if (flag) cout << "error: no existing record found" << endl;
}
void print_records(vector<Exam_record>& records)//printing all
{
sort(records.begin(), records.end(), [](Exam_record a, Exam_record b){
return (a.stud_id <= b.stud_id);
});
for(int i = 0; i < records.size(); i++)
{
cout << "student: " << records[i].stud_id << ", discipline: " << disciplines[records[i].exam_id] << ", exam score: "
<< records[i].exam_score << ", activity_score: " << records[i].activity_score << ", mark: " << records[i].exam_mark << endl;
}
}
void print_records(vector<Exam_record>& records, int stud_id) //printing all for one student
{
sort(records.begin(), records.end(), [](Exam_record a, Exam_record b){
return (a.stud_id <= b.stud_id);
});
for(int i = 0; i < records.size(); i++)
{
if(records[i].stud_id == stud_id) cout << "student: " << records[i].stud_id << ", discipline: " << disciplines[records[i].exam_id]
<< ", exam score: " << records[i].exam_score << ", activity_score: " << records[i].activity_score
<< ", mark: " << records[i].exam_mark << endl;
}
}
void print_records(vector<Exam_record>& records,int stud_id, int exam_id) //printing one exam for one student
{
sort(records.begin(), records.end(), [](Exam_record a, Exam_record b){
return (a.stud_id <= b.stud_id);
});
for(int i = 0; i < records.size(); i++)
{
if(records[i].exam_id == exam_id && records[i].stud_id == stud_id) cout << "student: " << records[i].stud_id
<< ", discipline: " << disciplines[records[i].exam_id] << ", exam score: "
<< records[i].exam_score << ", activity_score: " << records[i].activity_score << ", mark: " << records[i].exam_mark << endl;
}
}