较为初始的学生成绩管理系统

 https://github.com/Sophie943790092/Student-performance-management-system  源码可自行下载
1
#include<iostream> 2 #include<fstream>//读入文件 3 #include<string> 4 #include <vector> 5 #include <iterator>// 标准库函数begin(),end() 6 using namespace std; 7 8 9 //学生类 10 class Student 11 { 12 public: 13 Student()//构造函数 14 { 15 16 } 17 18 Student(string szNum, string szName, string szSex)//对象初始化 19 { 20 m_szNum = szNum; 21 m_szName = szName; 22 m_szSex = szSex; 23 m_szPwd = "123";; 24 } 25 26 public: 27 string m_szNum; //学号 28 string m_szName; //姓名 29 string m_szSex; //性别 30 string m_szPwd; //密码 31 }; 32 33 //课程成绩类 34 class Course 35 { 36 public: 37 Course() 38 { 39 m_nRank = 1;//成绩排名,初始化为1 40 } 41 42 Course(string szCourseName, float fScore, string szTeacherName) 43 { 44 m_szCourseName = szCourseName; 45 m_fScore = fScore; 46 m_szTeacherName = szTeacherName; 47 m_nRank = 1; 48 } 49 50 public: 51 string m_szCourseName; //课程名称 52 float m_fScore; //成绩 53 string m_szTeacherName; //任课老师 54 int m_nRank; //等级 55 }; 56 57 //学生课程成绩类 58 class Stu_Course 59 { 60 public: 61 Stu_Course() 62 { 63 m_pStu = NULL; 64 } 65 66 Stu_Course(Student* &pStu) 67 { 68 m_pStu = pStu; 69 } 70 71 ~Stu_Course()//析构函数,释放内存,否则会内存泄漏 !! 72 { 73 if (!m_pStu) 74 { 75 delete m_pStu; 76 m_pStu = NULL; 77 } 78 for (size_t i = 0; i < m_vecCourse.size(); ++i) 79 { 80 delete m_vecCourse.at(i); 81 } 82 } 83 84 void AddCourse(Course* &pCourse) 85 { 86 m_vecCourse.push_back(pCourse); 87 } 88 89 public: 90 Student* m_pStu; //学生类成员 91 vector<Course*> m_vecCourse; //该学生课程类数组成员 92 }; 93 94 //学生课程成绩类数组 95 vector<Stu_Course*> vecStu_Course; 96 97 //从文件读取数据--- 98 void ReadFile() 99 { 100 FILE *fp;//文件指针 101 int n;//文件行数计数 102 if((fp=fopen("Scores.txt","r"))==NULL)//打开文件 103 { 104 return; 105 } 106 for(n=0; !feof(fp); n++)//按行循环遍历文件 107 { 108 Student* pStu = NULL; 109 Course* pCourse = NULL; 110 Stu_Course* pStu_Course = NULL; 111 112 char szNum[50], szName[50], szSex[5], szPwd[50]; 113 float f1, f2, f3, f4; 114 fscanf(fp, "%s %s %s %s %f %f %f %f ", &szNum, &szName, &szSex, &szPwd, &f1, &f2, &f3, &f4); 115 116 pStu = new Student(szNum, szName, szSex); 117 pStu->m_szPwd = szPwd; 118 pStu_Course = new Stu_Course(pStu); 119 120 pCourse = new Course("A", f1, "张三"); 121 pStu_Course->AddCourse(pCourse); 122 pCourse = new Course("B", f2, "李四"); 123 pStu_Course->AddCourse(pCourse); 124 pCourse = new Course("C", f3, "王五"); 125 pStu_Course->AddCourse(pCourse); 126 pCourse = new Course("D", f4, "赵六"); 127 pStu_Course->AddCourse(pCourse); 128 vecStu_Course.push_back(pStu_Course); 129 } 130 fclose(fp);//关闭文件 131 } 132 133 //将存储成绩信息的链表写入文件 134 void WriteFile() 135 { 136 system("cls"); 137 FILE *fp;//文件指针 138 fp=fopen("Scores.txt","w+");//打开文件 139 if (fp == NULL) 140 { 141 return; 142 } 143 for (int i = 0; i < vecStu_Course.size(); ++i) 144 { 145 Student* pStu = vecStu_Course.at(i)->m_pStu; 146 vector<Course*>* vectCourse = &vecStu_Course.at(i)->m_vecCourse; 147 float ff = vectCourse->at(0)->m_fScore; 148 fprintf(fp, "%s %s %s %s %f %f %f %f ", pStu->m_szNum.c_str(), pStu->m_szName.c_str(), pStu->m_szSex.c_str(), pStu->m_szPwd.c_str(), vectCourse->at(0)->m_fScore, vectCourse->at(1)->m_fScore, vectCourse->at(2)->m_fScore, vectCourse->at(3)->m_fScore);//将学生信息写入文件 149 fputs(" ",fp);//文件指针指向下一行 150 } 151 fclose(fp);//关闭文件 152 } 153 154 155 //根据学号查询 156 int Search(string szNum) 157 { 158 int nIndex ,nCount; 159 nIndex = nCount = -1; 160 vector<Stu_Course*>::iterator it = vecStu_Course.begin(); 161 for (; it != vecStu_Course.end(); ++it)//for(....;it != vecStu_Course.end() && it->empty();++it)//isspace应该也可以 162 { 163 ++nCount; 164 string szCurNum = (*it)->m_pStu->m_szNum; 165 if (szCurNum == szNum) 166 { 167 nIndex = nCount; 168 break; 169 } 170 } 171 return nIndex; 172 } 173 174 //登录 175 int Login() 176 { 177 int nType = -1; //初始化为(-1)代表还未运行 //用户类型-- 0:管理员;1:普通用户 178 while(1) 179 { 180 cout << endl << endl; 181 cout << "**********************************************************************" << endl; 182 cout << "*** 欢迎进入成绩管理系统 ***" << endl; 183 cout << "**********************************************************************" << endl << endl << endl; 184 cout << " 请输入用户名:";//注意对好位置 185 string szName, szPwd; 186 cin >> szName; 187 cout << " 请输入密码:"; 188 cin >> szPwd; 189 if (szName == "admin") 190 { 191 if (szPwd == "123") 192 { 193 nType = 0; 194 break; 195 } 196 cout << " 密码错误!" << endl; 197 } 198 else 199 { 200 //用户是否存在 201 bool bFound = false; 202 for (size_t i = 0; i < vecStu_Course.size(); ++i) 203 { 204 string szTempName = vecStu_Course.at(i)->m_pStu->m_szName; 205 if (szTempName == szName) 206 { 207 bFound = true; 208 break; 209 } 210 } 211 if (bFound) //如果用户存在 212 { 213 if (szPwd == "123") 214 { 215 nType = 1; 216 break; 217 } 218 cout << " 密码错误!" << endl; 219 } 220 else //如果用户不存在 221 { 222 cout << " 用户名不存在!" << endl; 223 } 224 } 225 } 226 return nType; 227 } 228 229 //主菜单 230 int Menu(int nType) 231 { 232 system("cls"); 233 int nSelect = -1; 234 if (nType == 0) //如果该用户是管理员,进入后台 235 { 236 cout << "**********************************************************************" << endl; 237 cout << "*** 成绩管理系统 ***" << endl; 238 cout << "**********************************************************************" << endl; 239 cout << "[1]添加学生信息" << endl; 240 cout << "[2]删除学生信息" << endl; 241 cout << "[3]修改学生信息" << endl; 242 cout << "[4]查询指定科目分数最高和最低的学生的个人信息和单科成绩与全科成绩与等级" << endl; 243 cout << "[5]查询指定学生的科目中多次考试中的最高分和最低分与平均成绩" << endl; 244 cout << "[6]查询指定学生的单科班级成绩排名与总分成绩排名" << endl; 245 cout << "[7]查询指定科目的各个等级段的学生人数与姓名和成绩" << endl; 246 cout << "[0]退出" << endl; 247 cout << "**********************************************************************" << endl; 248 cout << "请输入数字0-7选择对应的功能" << endl; 249 cin >> nSelect; 250 while(nSelect < 0 || nSelect > 7) 251 { 252 cout << "输入错误,请重新输入(0-7):" << endl; 253 cin >> nSelect; 254 } 255 } 256 else if (nType == 1) //如果该用户是普通用户,进入客户端(btw好像不太行) 257 { 258 cout << "**********************************************************************" << endl; 259 cout << "*** 成绩管理系统 ***" << endl; 260 cout << "**********************************************************************" << endl; 261 cout << "[1]查询指定科目分数最高和最低的学生的个人信息和单科成绩与全科成绩与等级 " << endl; 262 cout << "[2]查询指定学生的科目中多次考试中的最高分和最低分与平均成绩" << endl; 263 cout << "[3]查询指定学生的单科班级成绩排名与总分成绩排名" << endl; 264 cout << "[4]查询指定科目的各个等级段的学生人数与姓名和成绩" << endl; 265 cout << "[0]退出" << endl; 266 cout << "**********************************************************************" << endl; 267 cout << "请输入数字0-4选择对应的功能" << endl; 268 cin >> nSelect; 269 while(nSelect < 0 || nSelect > 4) 270 { 271 cout << "输入错误,请重新输入(0-4):" << endl; 272 cin >> nSelect; 273 } 274 if (nSelect != 0) 275 { 276 nSelect += 3; 277 } 278 } 279 return nSelect; 280 } 281 282 //添加学生信息 283 void InputFromKeyboard() 284 { 285 int nStuCount = 0; 286 cout << "请输入你要添加的学生的个数:" << endl; 287 cin >> nStuCount; 288 cout << endl; 289 for(int i = 0;i < nStuCount; ++i) 290 { 291 Student* pStu = NULL;//定义指向student结构体的指针 292 Course* pCourse = NULL; 293 Stu_Course* pStu_Course = NULL; 294 295 string szNum, szName, szSex; 296 int nCourseCount = 0; 297 298 cout << "请输入该学生的学号:" << endl; 299 cin >> szNum; 300 int nIndex =Search(szNum);//查询当前学号的学生信息 301 while(nIndex >= 0) 302 { 303 cout << "该学号已存在,请重新输入:" << endl; 304 cin >> szNum; 305 nIndex = Search(szNum);//查询当前学号的学生信息 306 } 307 308 //如果不存在,则输入的学生信息 309 cout << "请输入该学生的姓名:" << endl; 310 cin >> szName; 311 312 cout << "请输入该学生的性别:" << endl; 313 cin >> szSex; 314 315 pStu = new Student(szNum, szName, szSex); 316 pStu_Course = new Stu_Course(pStu); 317 318 cout << "请输入该生的课程数" << endl; 319 cin >> nCourseCount; 320 321 for (int j = 0; j < nCourseCount; ++j) 322 { 323 string szCourseName, szTeacherName;//课程名,该课程任课老师名 324 float fScore; 325 326 cout << "请输入第" << j + 1 << "科课程名称:" << endl; 327 cin >> szCourseName; 328 329 cout << "请输入该课程分数:" << endl; 330 cin >> fScore;//课程分数 331 332 cout << "请输入该课程任课老师:" << endl; 333 cin >> szTeacherName; 334 335 pCourse = new Course(szCourseName, fScore, szTeacherName); 336 pStu_Course->AddCourse(pCourse); 337 } 338 vecStu_Course.push_back(pStu_Course); 339 } 340 } 341 342 //创建输入学生信息函数 343 void Input() 344 { 345 system("cls"); 346 printf("********************************************************************** "); 347 printf(" [1]文件输入 "); 348 printf(" [2]键盘输入 "); 349 printf("********************************************************************** "); 350 printf("请输入数字1-2选择输入方式:"); 351 int nInputType; 352 scanf("%d",&nInputType);//用C语言来控制格式化输入输出出会方便一点 353 while(nInputType < 1 || nInputType > 2) 354 { 355 printf("输入错误,请重新输入(1-2):"); 356 scanf("%d",&nInputType); 357 } 358 359 if (nInputType == 1) 360 { 361 ReadFile(); 362 } 363 else if (nInputType == 2) 364 { 365 InputFromKeyboard(); 366 } 367 368 printf("录入完成! "); 369 } 370 371 //删除学生信息 372 void Delete() 373 { 374 int n = -1; 375 system("cls"); 376 string szNum; 377 cout << "请输入该学生的学号:" << endl; 378 cin >> szNum; 379 int nIndex = Search(szNum);//查询当前学号的学生信息 380 if (nIndex < 0) //未查询到该学生的信息 381 { 382 cout << "未查询到该学生的信息!" << endl; 383 } 384 else//查询到当前学号的学生信息 385 { 386 Stu_Course* pStu_Course = vecStu_Course.at(nIndex); 387 //打印该学生的信息 388 cout << "该学生的信息为:" << endl; 389 cout << "==========================================" << endl; 390 cout << "学号:" << pStu_Course->m_pStu->m_szNum << endl; 391 cout << "姓名:" <<pStu_Course->m_pStu->m_szName << endl; 392 cout << "性别:" << pStu_Course->m_pStu->m_szSex << endl; 393 cout << "确定要删除该学生的信息吗?" << endl; 394 cout << "如果是请输入'y',如果不是请按任意键!" << endl; 395 char a; 396 cin >> a; 397 if(a == 'y')//确认删除该学生的信息 398 { 399 vecStu_Course.erase(vecStu_Course.begin() + nIndex, vecStu_Course.begin() + nIndex + 1); 400 cout << "已删除该学生的信息!!" << endl; 401 } 402 else 403 { 404 cout << "已经取消删除!!" << endl; 405 fflush(stdin); 406 } 407 } 408 } 409 410 //修改学生信息 411 void Modify() 412 { 413 int n = -1; 414 system("cls"); 415 string szNum; 416 cout << "请输入该学生的学号:" << endl; 417 cin >> szNum; 418 int nIndex = Search(szNum);//查询当前学号的学生信息 419 if (nIndex < 0)//未查询到该学生的信息 420 { 421 cout << "未查询到该学生的信息!" << endl; 422 } 423 else//查询到当前学号的学生信息 424 { 425 Stu_Course* pStu_Course = vecStu_Course.at(nIndex); 426 //打印该学生的信息 427 cout << "该学生的信息为:" << endl; 428 cout << "==========================================" << endl; 429 cout << "学号:" << pStu_Course->m_pStu->m_szNum << endl; 430 cout << "姓名:" << pStu_Course->m_pStu->m_szName << endl; 431 cout << "性别:" << pStu_Course->m_pStu->m_szSex << endl; 432 433 vector<Course*>* pVect = &pStu_Course->m_vecCourse; 434 while(1) 435 { 436 //选择要修改成绩的课程 437 cout << "**********************************************************************" << endl; 438 for (size_t i = 0; i < pVect->size(); ++i) 439 { 440 string szCourseName =pVect->at(i)->m_szCourseName; 441 cout << "[" << i + 1 << "] " << szCourseName << endl; 442 } 443 cout << " [0]回到上一级菜单" << endl; 444 cout << "**********************************************************************" << endl; 445 cout << "请输入数字1-" << pVect->size() << "选择要修改成绩信息的课程(回到上一级菜单请输入0):" << endl; 446 int nCourse; 447 cin >> nCourse;//要修改成绩信息的课程 448 while(nCourse < 0 || nCourse > pVect->size()) 449 { 450 cout << "输入错误,请重新输入(0-" << pVect->size() << "):" << endl; 451 cin >> nCourse;//要修改成绩信息的课程 452 } 453 if (nCourse == 0) 454 { 455 system("cls"); 456 break; 457 } 458 cout << "请输入该课程成绩:" << endl; 459 float fScore; 460 cin >> fScore;//输入的课程成绩 461 Course* pCourse = pVect->at(nCourse - 1); 462 pCourse->m_fScore = fScore; 463 464 //打印该学生修改后的信息 465 cout << "该学生修改后的信息为:" << endl; 466 cout << "==========================================" << endl; 467 cout << "学号:" << pStu_Course->m_pStu->m_szNum << endl; 468 cout << "姓名:" << pStu_Course->m_pStu->m_szName << endl; 469 cout << "性别:" << pStu_Course->m_pStu->m_szSex << endl; 470 for (size_t i = 0; i < pVect->size(); ++i) 471 { 472 string szCourseName =pVect->at(i)->m_szCourseName; 473 cout << szCourseName << " "; 474 } 475 cout << endl; 476 for (size_t i = 0; i < pVect->size(); ++i) 477 { 478 float fScore =pVect->at(i)->m_fScore; 479 cout << fScore << " "; 480 } 481 cout << endl; 482 } 483 } 484 } 485 486 //(2)可输出指定科目分数最高和最低的学生的个人信息和单科成绩与全科成绩与等级 487 void Func_1() 488 { 489 system("cls"); 490 while(1) 491 { 492 int n = -1; 493 string szCourseName; 494 cout << "请输入要查找的课程名称:(回到上一级菜单请输入0)" << endl; 495 cin >> szCourseName; 496 if (szCourseName == "0") 497 { 498 break; 499 } 500 //该课程分数最高和最低的学生课程成绩类 501 Stu_Course* pMax, *pMin; 502 pMax = pMin = NULL; 503 //该课程最高分数和最低分数 504 float fMax, fMin; 505 fMax = -9999.0; 506 fMin = 9999.0; 507 for (int i = 0; i < vecStu_Course.size(); ++i) 508 { 509 //当前学生课程数组 510 vector<Course*> vectCourse = vecStu_Course.at(i)->m_vecCourse;//动态数组 511 for (int j = 0; j < vectCourse.size(); ++j) 512 { 513 if (vectCourse.at(j)->m_szCourseName == szCourseName) 514 { 515 if (vectCourse.at(j)->m_fScore > fMax) 516 { 517 fMax = vectCourse.at(j)->m_fScore; 518 pMax = vecStu_Course.at(i); 519 } 520 if (vectCourse.at(j)->m_fScore < fMin) 521 { 522 fMin = vectCourse.at(j)->m_fScore; 523 pMin = vecStu_Course.at(i); 524 } 525 break; 526 } 527 } 528 } 529 530 if (pMax == NULL)//未查询到该学生的信息 531 { 532 cout << "未查询到该课程最高分的学生信息!" << endl; 533 return; 534 } 535 if (pMin == NULL)//未查询到该学生的信息 536 { 537 cout << "未查询到该课程最低分的学生信息!" << endl; 538 return; 539 } 540 //打印该学生的信息 541 cout << szCourseName << "分数最高的学生信息为:" << endl; 542 cout << "==========================================" << endl; 543 cout << "学号:" << pMax->m_pStu->m_szNum << endl; 544 cout << "姓名:" << pMax->m_pStu->m_szName << endl; 545 cout << "性别:" << pMax->m_pStu->m_szSex << endl; 546 547 for (int i = 0; i < pMax->m_vecCourse.size(); ++i) 548 { 549 string szCourseName = pMax->m_vecCourse.at(i)->m_szCourseName; 550 cout << szCourseName << " "; 551 } 552 cout << endl; 553 for (int i = 0; i < pMax->m_vecCourse.size(); ++i) 554 { 555 float fScore = pMax->m_vecCourse.at(i)->m_fScore; 556 cout << fScore << " "; 557 } 558 cout << endl; 559 560 cout << szCourseName << "分数最低的学生信息为:" << endl; 561 cout << "==========================================" << endl; 562 cout << "学号:" << pMin->m_pStu->m_szNum << endl; 563 cout << "姓名:" << pMin->m_pStu->m_szName << endl; 564 cout << "性别:" << pMin->m_pStu->m_szSex << endl; 565 566 for (int i = 0; i < pMin->m_vecCourse.size(); ++i) 567 { 568 string szCourseName = pMin->m_vecCourse.at(i)->m_szCourseName; 569 cout << szCourseName << " "; 570 } 571 cout << endl; 572 for (int i = 0; i < pMin->m_vecCourse.size(); ++i) 573 { 574 float fScore = pMin->m_vecCourse.at(i)->m_fScore; 575 cout << fScore << " "; 576 } 577 cout << endl; 578 } 579 } 580 581 //(3)可输出指定学生的科目中多次考试中的最高分和最低分与平均成绩 582 void Func_2() 583 { 584 system("cls"); 585 while(1) 586 { 587 int n = -1; 588 string szNum; 589 cout << "请输入要查找的学生学号:(回到上一级菜单请输入0)" << endl; 590 cin >> szNum; 591 if (szNum == "0") 592 { 593 break; 594 } 595 Stu_Course* pStu_Course = NULL; 596 for (int i = 0; i < vecStu_Course.size(); ++i) 597 { 598 if (vecStu_Course.at(i)->m_pStu->m_szNum == szNum) 599 { 600 pStu_Course = vecStu_Course.at(i); 601 break; 602 } 603 } 604 605 if (pStu_Course == NULL)//未查询到该学生的信息 606 { 607 cout << "未查询到该学生信息!" << endl; 608 } 609 else 610 { 611 //打印该学生的信息 612 cout << "该学生信息为:" << endl; 613 cout << "==========================================" << endl; 614 cout << "学号:" << pStu_Course->m_pStu->m_szNum << endl; 615 cout << "姓名:" << pStu_Course->m_pStu->m_szName << endl; 616 cout << "性别:" << pStu_Course->m_pStu->m_szSex << endl; 617 618 float fMax, fMin, fSum; 619 fMax = -9999.0; 620 fMin = 9999.0; 621 fSum = 0.0; 622 vector<Course*> vectCourse = pStu_Course->m_vecCourse; 623 for (int i = 0; i < vectCourse.size(); ++i) 624 { 625 fSum += vectCourse.at(i)->m_fScore; 626 if (vectCourse.at(i)->m_fScore > fMax) 627 { 628 fMax = vectCourse.at(i)->m_fScore; 629 } 630 if (vectCourse.at(i)->m_fScore < fMin) 631 { 632 fMin = vectCourse.at(i)->m_fScore; 633 } 634 } 635 cout << "各科最高分:" << fMax << endl; 636 cout << "各科最低分:" << fMin << endl; 637 cout << "平均成绩:" << fSum / vectCourse.size()<< endl; 638 cout << endl; 639 } 640 } 641 } 642 643 //(4)可输出指定学生的单科班级成绩排名与总分成绩排名 644 void Func_3() 645 { 646 system("cls"); 647 while(1) 648 { 649 int n = -1; 650 string szNum; 651 cout << "请输入要查找的学生学号:(回到上一级菜单请输入0)" << endl; 652 cin >> szNum; 653 if (szNum == "0") 654 { 655 break; 656 } 657 Stu_Course* pStu_Course = NULL; 658 for (int i = 0; i < vecStu_Course.size(); ++i) 659 { 660 if (vecStu_Course.at(i)->m_pStu->m_szNum == szNum) 661 { 662 pStu_Course = vecStu_Course.at(i); 663 break; 664 } 665 } 666 667 if (pStu_Course == NULL)//未查询到该学生的信息 668 { 669 cout << "未查询到该学生信息!" << endl; 670 } 671 else 672 { 673 //打印该学生的信息 674 cout << "该学生信息为:" << endl; 675 cout << "==========================================" << endl; 676 cout << "学号:" << pStu_Course->m_pStu->m_szNum << endl; 677 cout << "姓名:" << pStu_Course->m_pStu->m_szName << endl; 678 cout << "性别:" << pStu_Course->m_pStu->m_szSex << endl; 679 680 vector<Course*> vectCourse = pStu_Course->m_vecCourse; 681 int nCourseCount = vectCourse.size(); 682 int nSumRank = 1; 683 for (int i = 0; i < vecStu_Course.size(); ++i) 684 { 685 vector<Course*> vectTempCourse = vecStu_Course.at(i)->m_vecCourse; 686 int nTempSum = 0; 687 int nSum = 0; 688 for (int j = 0; j < nCourseCount; ++j) 689 { 690 nSum += vectCourse.at(j)->m_fScore; 691 nTempSum += vectTempCourse.at(j)->m_fScore; 692 if (vectCourse.at(j)->m_fScore < vectTempCourse.at(j)->m_fScore) 693 { 694 ++vectCourse.at(j)->m_nRank; 695 } 696 } 697 if(nSum < nTempSum) 698 { 699 ++nSumRank; 700 } 701 } 702 //输出单科班级成绩排名与总分成绩排名 703 for (int i = 0; i < vectCourse.size(); ++i) 704 { 705 string szCourseName = vectCourse.at(i)->m_szCourseName; 706 cout << szCourseName << " "; 707 } 708 cout << "总成绩" << endl; 709 for (int i = 0; i < vectCourse.size(); ++i) 710 { 711 int nRank = vectCourse.at(i)->m_nRank; 712 cout << nRank << " "; 713 } 714 cout << nSumRank << endl; 715 } 716 } 717 } 718 719 //(5)可输出指定科目的各个等级段的学生人数与姓名和成绩 720 void Func_4() 721 { 722 system("cls"); 723 while(1) 724 { 725 int n = -1; 726 string szCourseName; 727 cout << "请输入要查找的课程名称:(回到上一级菜单请输入0)" << endl; 728 cin >> szCourseName; 729 if (szCourseName == "0") 730 { 731 break; 732 } 733 vector<Stu_Course*> vect1; //<60 734 vector<Stu_Course*> vect2; //60-79 735 vector<Stu_Course*> vect3; //80-89 736 vector<Stu_Course*> vect4; //>=90 737 int nNum[4] = {0}; 738 for (int i = 0; i < vecStu_Course.size(); ++i) 739 { 740 //当前学生课程数组 741 vector<Course*> vectCourse = vecStu_Course.at(i)->m_vecCourse; 742 for (int j = 0; j < vectCourse.size(); ++j) 743 { 744 if (vectCourse.at(j)->m_szCourseName == szCourseName) 745 { 746 if (vectCourse.at(j)->m_fScore < 60.0) 747 { 748 vect1.push_back(vecStu_Course.at(i)); 749 ++nNum[0]; 750 } 751 else if (vectCourse.at(j)->m_fScore >= 60.0 && vectCourse.at(j)->m_fScore < 80.0) 752 { 753 vect2.push_back(vecStu_Course.at(i)); 754 ++nNum[1]; 755 } 756 else if (vectCourse.at(j)->m_fScore >= 80.0 && vectCourse.at(j)->m_fScore < 90.0) 757 { 758 vect3.push_back(vecStu_Course.at(i)); 759 ++nNum[2]; 760 } 761 else 762 { 763 vect4.push_back(vecStu_Course.at(i)); 764 ++nNum[3]; 765 } 766 break; 767 } 768 } 769 } 770 771 //打印该学生的信息 772 cout << "==========================================" << endl; 773 cout << "<60: " << vect1.size() << "" << endl; 774 for (int i = 0; i < vect1.size(); ++i) 775 { 776 string szName = (vect1.at(i))->m_pStu->m_szName; 777 cout << szName << " "; 778 } 779 cout << endl << endl; 780 781 cout << "60-79: " << vect2.size() << "" << endl; 782 for (int i = 0; i < vect2.size(); ++i) 783 { 784 string szName = (vect2.at(i))->m_pStu->m_szName; 785 cout << szName << " "; 786 } 787 cout << endl << endl; 788 789 cout << "80-89: " << vect3.size() << "" << endl; 790 for (int i = 0; i < vect3.size(); ++i) 791 { 792 string szName = (vect3.at(i))->m_pStu->m_szName; 793 cout << szName << " "; 794 } 795 cout << endl << endl; 796 797 cout << ">=90: " << vect4.size() << "" << endl; 798 for (int i = 0; i < vect4.size(); ++i) 799 { 800 string szName = (vect4.at(i))->m_pStu->m_szName; 801 cout << szName << " "; 802 } 803 cout << endl << endl; 804 } 805 } 806 807 //结束、退出 808 void End() 809 { 810 system("cls"); 811 WriteFile(); 812 cout << "谢谢使用!" << endl; 813 exit(0);//退出 814 } 815 816 int main() 817 { 818 //Init(); //初始化学生课程成绩类数组 819 int nType = Login(); //登录 820 while(1) 821 { 822 int n = Menu(nType);//菜单 823 switch(n) 824 { 825 case 1: 826 { 827 Input(); //(1)对各类中的实现进行添加 828 break; 829 } 830 case 2: 831 { 832 Delete(); //对各类中的实现进行删除 833 break; 834 } 835 case 3: 836 { 837 Modify(); //对各类中的实现进行修改 838 break; 839 } 840 case 4: 841 { 842 Func_1(); //(2)可输出指定科目分数最高和最低的学生的个人信息和单科成绩与全科成绩与等级 843 break; 844 } 845 case 5: 846 { 847 Func_2(); //(3)可输出指定学生的科目中多次考试中的最高分和最低分与平均成绩 848 break; 849 } 850 case 6: 851 { 852 Func_3(); //(4)可输出指定学生的单科班级成绩排名与总分成绩排名 853 break; 854 } 855 case 7: 856 { 857 Func_4(); //(5)可输出指定科目的各个等级段的学生人数与姓名和成绩 858 break; 859 } 860 case 0: 861 { 862 End(); //结束,退出 863 } 864 } 865 } 866 system("pause"); 867 return 0; 868 }
//代码注释将后续进一步完善!
//后续还将给出变量命名表格及具体代码知识点详解
原文地址:https://www.cnblogs.com/SophieWang-cmu/p/12729040.html