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 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348
| #include <iostream> #include "compareManager.h" #include "competitor.h" #include <fstream> #include <string> #include <deque> using namespace std;
compareManager::compareManager() { this->initCompetition(); }
compareManager::~compareManager() {
}
void compareManager::Show_Menu() { cout << "欢迎使用活动比赛流程管理系统!" << endl; cout << "输入“1”开始演讲比赛,输入“0”退出程序:"; }
void compareManager::Design_Process(int choice) { while (true) { if (choice != 1) { cout << "请输入参赛选手人数:"; cin >> this->first_Num; } else this->import_Competitor(); cout << "请输入晋级(决赛)参赛人数:"; cin >> this->scond_Num; cout << "请输入评委人数:"; cin >> this->judges_Num; int judge; cout << "评分时是否去掉一个最高分和最低分?(“1”表示“是”,“0”表示“否”):"; cin >> judge; if (judge == 1) { this->Whether_To_Remove = true; } else if(judge== 0) { this->Whether_To_Remove = false; } else { continue; } cout << "本次比赛分为初赛和决赛,初赛一共有" << this->first_Num << "人,其中晋级" << this->scond_Num << "人"<<endl<<"是否正确?(“1”表示“是”,“0”表示“否”):"; cin >> judge; if (judge == 1) { break; } else { continue; }
} }
void compareManager::createCompetitor() { for (int i = 0; i < this->first_Num; i++) { string name; string song; cout << "输入选手" << i + 1 << "的姓名:"; cin >> name; cout << "输入选手" << i + 1 << "歌曲名:"; cin >> song; Competitor ct; ct.name = name; ct.song = song; ct.n_Score[0] = 0; ct.n_Score[1] = 0; this->v1.push_back(i + 10001);
this->m_Competitor.insert(make_pair(i + 10001, ct)); } }
void compareManager::import_Competitor() { ifstream f; string line; f.open("Competitor_Data.csv", ios::in); if (!f.is_open()) { cout << "Error:打开文件失败,请确保目录下有该文件!程序自动退出…" << endl; exit(1); } getline(f, line); int count = 0; while (getline(f, line)) { string str; vector<string> v_data;
Competitor ct; istringstream readstr(line); while (getline(readstr, str, ',')) { v_data.push_back(str); } ct.class_ = v_data[0]; ct.name = v_data[1]; ct.category = v_data[2]; ct.song = v_data[3];
v_data.clear(); ct.n_Score[0] = 0; ct.n_Score[1] = 0; this->v1.push_back(count + 10001);
this->m_Competitor.insert(make_pair(count + 10001, ct)); count++; } this->first_Num = count; }
void compareManager::Show_info() { for (map<int, Competitor>::iterator it = this->m_Competitor.begin(); it != this->m_Competitor.end(); it++) { cout << "选手编号:" << it->first << " 姓名:" << it->second.name << " 分数:" << it->second.n_Score[this->m_Index - 1] << endl; } }
void compareManager::initCompetition() { this->v1.clear(); this->v2.clear(); this->vVictory.clear(); this->m_Competitor.clear(); this->first_Num = 0; this->scond_Num = 0; this->m_Index = 1; }
void compareManager::Start_Competition() { this->Competition_Draw(); this->Competition_Contest(); this->show_Score(); this->Competition_Draw(); this->Competition_Contest(); this->show_Score(); }
void compareManager::Competition_Draw() { cout << "第<<" << this->m_Index << ">>比赛正在抽签…" << endl; cout << "——————————————————————————" << endl; cout << "抽签结果如下:" << endl; ofstream p; string file_Name = "第" + to_string(this->m_Index) + "轮抽签顺序.csv"; if (this->m_Index == 1) { p.open(file_Name, ios::out | ios::trunc); p << "编号" << "," << "班级" << "," << "姓名" << "," << "种类" << "," << "节目" << endl; srand(static_cast<unsigned int>(time(0))); random_shuffle(v1.begin(), v1.end()); for (vector<int>::iterator it = v1.begin(); it != v1.end(); it++) { cout << *it << " "; cout << m_Competitor[*it].class_<<" " << m_Competitor[*it].name<<"的"<<m_Competitor[*it].category <<" "<<m_Competitor[*it].song << endl; p << *it << "," << m_Competitor[*it].class_ << "," << m_Competitor[*it].name << "," << m_Competitor[*it].category << "," << m_Competitor[*it].song << endl; } cout << endl; } if (this->m_Index == 2) { p.open(file_Name, ios::out | ios::trunc); p << "编号" << "," << "班级" << "," << "姓名" << "," << "种类" << "," << "节目" << endl; random_shuffle(v2.begin(), v2.end()); for (vector<int>::iterator it = v2.begin(); it != v2.end(); it++) { cout << *it << " "; cout << this->m_Competitor[*it].name << endl; p << *it << "," << m_Competitor[*it].class_ << "," << m_Competitor[*it].name << "," << m_Competitor[*it].category << "," << m_Competitor[*it].song << endl; } cout << endl; } p.close(); cout << "——————————————————————————" << endl; cout << "抽签顺序已经输出在文件目录下!" << endl<<"按任意键开始比赛"; system("pause"); cout << endl; }
void compareManager::Competition_Contest() { cout << "——————第" << this->m_Index << "轮比赛正式开始!——————" << endl; vector<int>v_Src; if (this->m_Index == 1) v_Src = v1; else v_Src = v2; ofstream p; string file_Name1 = "第" + to_string(this->m_Index) + "轮选手得分.csv"; p.open(file_Name1, ios::out | ios::trunc); p << "编号" << "," << "姓名" << "," << "平均分" << endl;
multimap<double, int, greater<double>> Score;
for (vector<int>::iterator it = v_Src.begin(); it != v_Src.end(); it++) { deque<double> d; cout << "选手" << *it <<" " << this->m_Competitor[*it].name << "正在比赛!下面请为他(她)打分!" << endl; for (int i = 0; i < this->judges_Num; i++) { cout << "第" << i + 1 << "位评委打分:" ; double score; cin >> score; d.push_back(score);
} sort(d.begin(), d.end(), greater<double>()); if (this->Whether_To_Remove) { d.pop_front(); d.pop_back(); } double sum = accumulate(d.begin(), d.end(), 0.0f); double avg = sum / (double)d.size(); cout << "他(她)的平均分是:" << avg; p << *it << "," << this->m_Competitor[*it].name << "," << avg << endl; this->m_Competitor[*it].n_Score[this->m_Index - 1] = avg; Score.insert(make_pair(avg, *it)); cout << endl; } p.close(); for (multimap<double, int, greater<double>>::iterator it = Score.begin(); it != Score.end(); it++) { cout << " 编号:" << it->second << " 姓名:" << this->m_Competitor[it->second].name << " 分数:" << this->m_Competitor[it->second].n_Score[this->m_Index - 1] << endl; } ofstream f; string file_Name2 = "第" + to_string(this->m_Index) + "轮优胜者名单.csv"; f.open(file_Name2, ios::out | ios::trunc); f << "编号" << "," << "姓名" << "," << "分数" << endl; int count = 0; for (multimap<double, int, greater<double>>::iterator it = Score.begin(); it != Score.end() && count<this->scond_Num; it++,count++) { if (this->m_Index == 1) { v2.push_back((*it).second); } else { vVictory.push_back((*it).second); } f << (*it).second << "," << this->m_Competitor[it->second].name << "," << this->m_Competitor[it->second].n_Score[this->m_Index - 1] << endl; } Score.clear(); f.close(); cout << "第"<<this->m_Index<<"轮所有选手的平均分已经输出在文件目录下!"<<endl; cout << "——————第" << this->m_Index << "轮比赛结束——————" << endl; system("pause"); }
void compareManager::show_Score() { cout << "——————第" << this-> m_Index << "轮比赛优胜者如下——————" << endl; vector<int> v; if (this->m_Index == 1) v = v2; else v = vVictory; for (vector<int>::iterator it = v.begin(); it != v.end(); it++) { cout << "选手编号:" << *it << " 姓名:" << this->m_Competitor[*it].name << " 分数:" << this->m_Competitor[*it].n_Score[this->m_Index - 1] << endl; } cout << endl; system("pause"); if(this->m_Index==1) system("cls");
this->m_Index++; }
int compareManager::print_first_Num() { return this->first_Num; }
int compareManager::print_scond_Num() { return this->scond_Num; }
void compareManager::Exit() { cout << "欢迎下次使用!" << endl; system("pause"); exit(0);
}
|