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 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527
| #include<iostream> #include<stdlib.h> #include<malloc.h> #include<string.h> #include<windows.h> #include<conio.h> #include<iomanip> #include<string.h> #include <algorithm> #include <fstream> #include <queue> using namespace std; #define clc system("cls") #define color system("color F1")
struct score { int chinese; int math; int english; int tec; int all; }; struct student { string name; string number; char sex; string phonenum; struct score score; } stu[2001];
bool cmp1(student a, student b) { return a.name < b.name; }
bool cmp2(student a, student b) { return a.number < b.number; }
bool cmp3(student a, student b) { return a.score.all > b.score.all; }
struct cmp4 { bool operator()(const student &a, const student &b) { return a.score.all < b.score.all; } };
void checkstu(); void inputscore(); void sort_number(); void sort_score(); void change_score(); void show_rank(); void del_score(); void sort_name(); void input_message(); void show_selfscore(); void change_selfmessage(); void print_teachermenu(); void print_stumenu(); void show_score();
int tot, cnt ;
void show_score() { cout << setw(8) << "姓名" << setw(8) << "学号" << setw(8) << "语文" << setw(8); cout << "数学" << setw(8) << "英语" << setw(8) << "理综" << setw(8) << "总分" << '\n'; for(int i = 1; i <= tot; ++i) { cout << setw(8) << stu[i].name << setw(8) << stu[i].number << setw(8) << stu[i].score.chinese; cout << setw(8) << stu[i].score.math << setw(8) << stu[i].score.english << setw(8); cout << stu[i].score.tec << setw(8) << stu[i].score.all << '\n'; } }
void toxy(int x,int y) { COORD pos= {x,y}; HANDLE Out=GetStdHandle(STD_OUTPUT_HANDLE); SetConsoleCursorPosition(Out,pos); }
void checkstu() { clc; color; cout << setw(8) << "姓名" << setw(8) << "学号" << setw(8) << "性别" << setw(8) << "电话" << '\n'; for(int i = 1; i <= tot; ++i) { cout << setw(8) << stu[i].name << setw(8); cout << stu[i].number << setw(8) << stu[i].sex << setw(14); cout << stu[i].phonenum << '\n'; } cout << "请按回车键即可返回。" << '\n'; getchar(); string c; getline(cin,c); if(c == "\n") print_stumenu(); }
void inputscore() { clc; color; cout << "姓名 语文 数学 英语 理综" << '\n'; for(int i = cnt+1 ; i <= tot; ++i) { cout << stu[i].name << " "; cin >> stu[i].score.chinese >> stu[i].score.math >> stu[i].score.english; cin >> stu[i].score.tec; stu[i].score.all = stu[i].score.chinese + stu[i].score.math + stu[i].score.english; stu[i].score.all += stu[i].score.tec; } cout << "请按回车键返回." << '\n'; getchar(); string c; getline(cin,c); if(c == "\n") print_stumenu(); }
void sort_score() { clc; color; sort(stu + 1, stu + tot + 1, cmp3); cout << "排序成功。" << '\n'; show_score(); cout << "按回车即可保存并返回." << '\n'; getchar(); string c; getline(cin,c); if(c == "\n") print_stumenu(); }
void change_score() { clc; color; cout << "请输入您要修改的对应学生的姓名:" << '\n'; string s; cin >> s; for(int i = 1; i <= tot ; ++i) { if(stu[i].name == s) { cout << "请重新输入他的语文成绩;" << '\n'; cin >> stu[i].score.chinese; cout << "请重新输入他的数学成绩;" << '\n'; cin >> stu[i].score.math; cout << "请重新输入他的英语成绩;" << '\n'; cin >> stu[i].score.english; cout << "请重新输入他的理综成绩;" << '\n'; cin >> stu[i].score.tec; stu[i].score.all = stu[i].score.chinese + stu[i].score.math + stu[i].score.english + stu[i].score.tec; } } cout << "请按回车返回: " << '\n'; getchar(); string c; getline(cin,c); if(c == "\n") print_stumenu(); }
void del_score() { clc; color; cout << "请输入您要删除的学生的姓名:" << '\n'; string s; cin >> s; int index; for(int i = 1; i <= tot; ++i) { if(stu[i].name == s) { index = i; break; } } for(int i = index; i + 1 <= tot; ++i) { stu[i] = stu[i + 1]; } tot--; cout << "按回车即可保存并返回." << '\n'; getchar(); string c; getline(cin,c); if(c == "\n") print_stumenu(); }
void sort_name() { clc; color; sort(stu + 1, stu + tot + 1,cmp1); cout << "排序成功。" << '\n'; show_score(); cout << "按回车即可保存并返回." << '\n'; getchar(); string c; getline(cin,c); if(c == "\n") print_stumenu(); }
void sort_number() { clc; color; sort(stu + 1, stu + tot + 1, cmp2); cout << "排序成功." << '\n'; show_score(); cout << "按回车即可保存并返回." << '\n'; getchar(); string c; getline(cin,c); if(c == "\n") print_stumenu(); }
void input_message() { clc; color; cout << "请输入您的姓名: " << '\n'; cin >> stu[++tot].name; cout << "请输入您的学号: (后两位即可)" << '\n'; cin >> stu[tot].number; cout << "请输入您的性别: (M男 F女)" << '\n'; cin >> stu[tot].sex ; getchar(); cout << "请输入您的电话号码: " << '\n'; cin >> stu[tot].phonenum; cout << "按回车即可保存并返回." << '\n'; getchar(); string c; getline(cin,c); if(c == "\n") print_stumenu(); }
void show_selfscore() { clc; color; cout << "请输入您的名字: " << '\n'; string s; cin >> s; int flag = 0; for(int i = 1; i <= tot; ++i) { if(stu[i].name == s) { flag = 1; printf("语文: %d\n", stu[i].score.chinese); printf("数学: %d\n", stu[i].score.math); printf("英语: %d\n", stu[i].score.english); printf("理综: %d\n", stu[i].score.tec); printf("总成绩: %d\n", stu[i].score.all); } } if(!flag) cout << "抱歉,您还未录入信息." << '\n'; cout << "请按回车键返回." << '\n'; getchar(); string c; getline(cin,c); if(c == "\n") print_stumenu(); }
void show_rank() { clc; color; priority_queue<student, vector<student>, cmp4 >P; for(int i = 1; i <= tot; ++i) { P.push(stu[i]); } cout << setw(8) << "姓名" << setw(8) << "学号" << setw(8) << "语文" << setw(8) << "数学"; cout << setw(8) << "英语" << setw(8) << "理综" << setw(8) << "总分" << '\n'; while(!P.empty()) { student a = P.top(); cout << setw(8) << a.name << setw(8) << a.number << setw(8) << a.score.chinese << setw(8) << a.score.math << setw(8); cout << a.score.english << setw(8) << a.score.tec << setw(8) << a.score.all << '\n'; P.pop(); } cout << "请按回车键返回." << '\n'; getchar(); string c; getline(cin,c); if(c == "\n") print_stumenu(); }
void change_selfmessage() { clc; color; cout << "请输入您的名字: " << '\n'; string s; cin >> s; for(int i = 1; i <= tot; ++i) { if(stu[i].name == s) { cout << "请重新修改您的学号: " << '\n'; cin >> stu[i].number ; cout << "请重新修改您的性别: " << '\n'; cin >> stu[i].sex ; cout << "请重新修改您的电话号码: " << '\n'; cin >> stu[i].phonenum; break; } } cout << "请按回车键返回并保存: " << '\n'; getchar(); string c; getline(cin,c); if(c == "\n") print_stumenu(); }
void printmenu() { int num; string s; color; clc; toxy(20,1); cout << "*****欢迎来到学生信息管理系统!*****" << '\n'; cout << "请说明您是 1. 老师" << '\n'; cout << " 2. 学生" << '\n'; cout << " 3. 退出" << '\n'; cin >> num; if(num == 1) { clc; cout << "请输入您的老师验证码: (123456)" << '\n'; cin >> s; while(s != "123456") { cout << "您的输入错误,请重新输入: " << '\n'; cin >> s; } if(s == "123456") print_teachermenu(); } else if(num == 2) { clc; print_stumenu(); } else if(num == 3) { exit(0); } } void print_teachermenu() { int num; do { clc; color; toxy(20,1); cout << "***欢迎来到教师端.***" << '\n'; cout << "1. 检查学生信息录入情况." << '\n'; cout << "2. 学生成绩录入." << '\n'; cout << "3. 将成绩按照学号排序." << '\n'; cout << "4. 将成绩按照成绩大小排序." << '\n'; cout << "5. 对成绩进行修改." << '\n'; cout << "6. 删除成绩." << '\n'; cout << "7. 返回主菜单." << '\n'; cout << "8. 按照名字的字典序排序" << '\n'; cout << '\n'; cout << "请输入您的操作数字: " << '\n'; cin >> num; switch(num) { case 1: { checkstu(); break; } case 2: { inputscore(); break; } case 3: { sort_number(); break; } case 4: { sort_score(); break; } case 5: { change_score(); break; } case 6: { del_score(); break; } case 7: { printmenu(); break; } case 8: { sort_name(); break; } default: { cout << "非法数字." << '\n'; break; } } } while(1); }
void print_stumenu() { int num; do { clc; color; toxy(20, 1); cout << "*****欢迎来到学生端*****" << '\n'; cout << "1. 输入学生个人基本信息." << '\n'; cout << "2. 查看个人成绩." << '\n'; cout << "3. 查看所在班级成绩排名." << '\n'; cout << "4. 查看所在班级学生基本信息." << '\n'; cout << "5. 修改个人基本信息" << '\n'; cout << "6. 返回主菜单." << '\n'; cin >> num; switch(num) { case 1: { input_message(); break; } case 2: { show_selfscore(); break; } case 3: { show_rank(); break; } case 4: { checkstu(); break; } case 5: { change_selfmessage(); break; } case 6: { printmenu(); break; } default: { cout << "非法字符." << '\n'; break; } } }while(1); }
int main() { for(int i = 1; i <= 2000; ++i) { stu[i].score.all = stu[i].score.chinese = 0; stu[i].score.chinese = stu[i].score.english = 0; stu[i].score.math = stu[i].score.tec = 0; } tot = 0, cnt = 0; int n = 0; ifstream in("C:\\Users\\Administrator\\Desktop\\dd.txt",ios::in); while(!in.eof() && n < 10) { ++tot; in >> stu[tot].name >> stu[tot].number >> stu[tot].sex >> stu[tot].phonenum >> stu[tot].score.chinese >> stu[tot].score.math >> stu[tot].score.english >> stu[tot].score.tec; stu[tot].score.all = stu[tot].score.chinese + stu[tot].score.math + stu[tot].score.english + stu[tot].score.tec; n++; } cnt = tot; printmenu(); }
|