-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathrandom_roll_call.cpp
More file actions
194 lines (184 loc) · 3.75 KB
/
Copy pathrandom_roll_call.cpp
File metadata and controls
194 lines (184 loc) · 3.75 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
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
#include <iostream>
#include <time.h>
#include <fstream>
#include <algorithm>
#include <stdlib.h>
using namespace std;
struct student {
int number=0;//号码
double grade = 0;//绩点
double pastp = 0;//缺勤系数
double nownumber = 0;//现在缺勤次数
int here[20] = { 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1 }; //到没到
}stu[90];
bool cmp(student x, student y)
{
if (x.pastp == y.pastp) return x.grade < y.grade;
else return x.pastp > y.pastp;
}
double E = 0, numerator = 0, denominator = 0;
string s1 = "软件工程", s2 = "数据库系统原理", s3 = "计算机操作系统", s4 = "计算机图形学", s5 = "大学应用写作";
void read_save1();
void read_save2();
void read_save3();
void read_save4();
void read_save5();
void final_result();
void address_E(string s);
int pastp_add(int x, int y);
int main()
{
read_save1();
address_E(s1);
read_save2();
address_E(s2);
read_save3();
address_E(s3);
read_save4();
address_E(s4);
read_save5();
address_E(s5);
final_result();
}
int pastp_add(int x, int y)
{
if (stu[x].here[y] == 0)//没到
{
stu[x].nownumber++;//现在缺勤次数增加1
if (stu[x].nownumber == 1)
{
stu[x].pastp += 0.05; //缺第一次 + 0.05 ,第二次 + 0.5 ,第三次 + 0.5,用以保证偶尔一次缺课不会被一直点名,三次抽取概率增加
}
else if (stu[x].nownumber > 1)
{
stu[x].pastp += 0.5;
}
numerator++;
cout<<"缺勤"<<" ";
return 1;
}
else
return 0;
}
void address_E(string s)
{
int m,m1,m2;
cout << s << "的抽点方案如下:" << endl;
//处理分子
for (int i = 0; i < 20; i++)//对于每一门课的20次课
{
sort(stu, stu + 90, cmp);
cout <<"第"<< i+1 << "次课抽点的同学号码为:" ;
for (int j = 0; j < 6; j++)//6个
{
cout << stu[j].number<<" " ;
if (stu[j].here[i] == 0)//没到
{
numerator++;
cout<<"缺勤"<<" ";
stu[j].pastp += 0.5;
}
else
cout<<"出勤"<<" ";
}
int temp = rand() % 4;//0-3个人
if (temp == 3)//点了3个人
{
int num = (rand() % (7 - 5) + 6);//在除了前几个人里的排名前二抽一个
cout << stu[num].number << " ";
m=pastp_add(num, i);
if(m==0)
cout<<"出勤"<<" ";
denominator += 1;
}
cout << endl;
}
//处理分母
denominator += 120;//前5-8个取了6个
cout << endl;
}
void read_save1() //输入第一门课的所有数据
{
ifstream infile;
infile.open("output1.txt"); //注意文件的路径
for (int i = 0; i < 90; i++)
{
infile >> stu[i].number;
infile >> stu[i].grade;
infile >> stu[i].pastp;
for (int j = 0; j < 20; j++)
{
infile >> stu[i].here[j];
}
}
infile.close();
}
void read_save2() //输入第二门课的所有数据
{
ifstream infile;
infile.open("output2.txt"); //注意文件的路径
for (int i = 0; i < 90; i++)
{
infile >> stu[i].number;
infile >> stu[i].grade;
infile >> stu[i].pastp;
for (int j = 0; j < 20; j++)
{
infile >> stu[i].here[j];
}
}
infile.close();
}
void read_save3()//输入第三门课的所有数据
{
ifstream infile;
infile.open("output3.txt"); //注意文件的路径
for (int i = 0; i < 90; i++)
{
infile >> stu[i].number;
infile >> stu[i].grade;
infile >> stu[i].pastp;
for (int j = 0; j < 20; j++)
{
infile >> stu[i].here[j];
}
}
infile.close();
}
void read_save4()//输入第四门课的所有数据
{
ifstream infile;
infile.open("output4.txt"); //注意文件的路径
for (int i = 0; i < 90; i++)
{
infile >> stu[i].number;
infile >> stu[i].grade;
infile >> stu[i].pastp;
for (int j = 0; j < 20; j++)
{
infile >> stu[i].here[j];
}
}
infile.close();
}
void read_save5()//输入第五门课的所有数据
{
ifstream infile;
infile.open("output5.txt"); //注意文件的路径
for (int i = 0; i < 90; i++)
{
infile >> stu[i].number;
infile >> stu[i].grade;
infile >> stu[i].pastp;
for (int j = 0; j < 20; j++)
{
infile >> stu[i].here[j];
}
}
infile.close();
}
void final_result()
{
E = numerator / denominator;
cout << E << endl;
}