[C/C++]结课作业-学生管理系统

浅浅的花香味﹌ 2024-04-24 20:32 167阅读 0赞
  • ?个人主页:北·海
  • ?CSDN新晋作者
  • ?欢迎 ?点赞✍评论⭐收藏
  • ✨收录专栏:C/C++
  • ?希望作者的文章能对你有所帮助,有不足的地方请在评论区留言指正,大家一起学习交流!?
  1. #ifndef OOP_PROJECT_STUDENT_H
  2. #define OOP_PROJECT_STUDENT_H
  3. #define NAME_MAX 20
  4. #define STU_MAX 100
  5. #include<iostream>
  6. using namespace std;
  7. class Student {
  8. public:
  9. static int numStudent;
  10. void Input(Student stu[]); //输入学生成绩
  11. void Statistic(Student stu[]); //统计数据
  12. void Lookup(Student stu[]); //查找学生成绩
  13. void Modify(Student stu[]); //修改学生成绩
  14. void Delete(Student stu[]); //删除学生成绩
  15. void Output(Student stu[]); //显示全部学生成绩
  16. void Sort(Student stu[]);//排序
  17. void Sling(Student stu[]); //查找挂科
  18. private:
  19. int num; //学号
  20. char name[NAME_MAX]; //姓名
  21. char class_0[NAME_MAX]; //班级
  22. float elec; //电子成绩
  23. float c_program; //C++成绩
  24. float english; //英语成绩
  25. float math; //高等数学成绩
  26. float physics; //物理成绩
  27. float sport; //体育
  28. float polity; //政治
  29. float average; //平均分
  30. bool CheckScore(float score);
  31. };
  32. #endif //OOP_PROJECT_STUDENT_H

student.cpp

  1. #include <cstring>
  2. #include "Student.h"
  3. int Student::numStudent = 0;
  4. //输入学生信息
  5. void Student::Input(Student *stu) {
  6. char sign = 0;
  7. int c = 0;
  8. cout << endl << "======>> 请输入学生成绩 <<======" << endl;
  9. while (sign != 'n' && sign != 'N') {
  10. cout << "班级:";
  11. cin >> stu[Student::numStudent].class_0;
  12. loop: //循环
  13. cout << "学号:";
  14. cin >> stu[Student::numStudent].num;
  15. for(int k = 0;k<numStudent;k++){
  16. if (stu[Student::numStudent].num == stu[k].num){
  17. cout << "您输入的学号已存在!请重新输入。" << endl;
  18. goto loop; //继续执行循环
  19. }
  20. }
  21. cout << "姓名:";
  22. cin >> stu[Student::numStudent].name;
  23. cout << "电子技术成绩:";
  24. cin >> stu[Student::numStudent].elec;
  25. while (!CheckScore(stu[Student::numStudent].elec)){
  26. cout << " 对不起,请输入1-100之间的数字!!\n";
  27. cout << "电子技术成绩:";
  28. cin >> stu[Student::numStudent].elec;
  29. }
  30. cout << "大学英语成绩:";
  31. cin >> stu[Student::numStudent].english;
  32. while (!CheckScore(stu[Student::numStudent].english)){
  33. cout << " 对不起,请输入1-100之间的数字!!\n";
  34. cout << "大学英语成绩:";
  35. cin >> stu[Student::numStudent].english;
  36. }
  37. cout << "C++程序设计成绩:";
  38. cin >> stu[Student::numStudent].c_program;
  39. while (!CheckScore(stu[Student::numStudent].c_program)){
  40. cout << " 对不起,请输入1-100之间的数字!!\n";
  41. cout << "C++程序设计成绩:";
  42. cin >> stu[Student::numStudent].c_program;
  43. }
  44. cout << "政治成绩:";
  45. cin >> stu[Student::numStudent].polity;
  46. while (!CheckScore(stu[Student::numStudent].polity)){
  47. cout << " 对不起,请输入1-100之间的数字!!\n";
  48. cout << "政治成绩:";
  49. cin >> stu[Student::numStudent].polity;
  50. }
  51. cout << "大学体育成绩:";
  52. cin >> stu[Student::numStudent].sport;
  53. while (!CheckScore(stu[Student::numStudent].sport)){
  54. cout << " 对不起,请输入1-100之间的数字!!\n";
  55. cout << "大学体育成绩:";
  56. cin >> stu[Student::numStudent].sport;
  57. }
  58. cout << "高等数学成绩:";
  59. cin >> stu[Student::numStudent].math;
  60. while (!CheckScore(stu[Student::numStudent].math)){
  61. cout << " 对不起,请输入1-100之间的数字!!\n";
  62. cout << "高等数学成绩:";
  63. cin >> stu[Student::numStudent].math;
  64. }
  65. cout << "物理成绩:";
  66. cin >> stu[Student::numStudent].physics;
  67. while (!CheckScore(stu[Student::numStudent].physics)){
  68. cout << " 对不起,请输入1-100之间的数字!!\n";
  69. cout << "物理成绩:";
  70. cin >> stu[Student::numStudent].physics;
  71. }
  72. stu[Student::numStudent].average = (stu[Student::numStudent].elec + stu[Student::numStudent].c_program + stu[Student::numStudent].physics + stu[Student::numStudent].english + stu[Student::numStudent].math +
  73. stu[Student::numStudent].sport + stu[Student::numStudent].polity) / 7;
  74. cout << " 平均分为:" << stu[Student::numStudent].average << endl;
  75. cout << "提示:是否继续写入学生成绩 ?(y/n)";
  76. cin >> sign;
  77. Student::numStudent++;
  78. }
  79. }
  80. 统计信息
  81. void Student::Statistic(Student *stu) {
  82. cout << endl << "\t\t================>> \t 输出学生统计数据 \t <<===================\t\n" << endl;
  83. cout << "-------------------------------------------------------------------------------------------------------" << endl;
  84. cout << "班级" << "\t\t" << "学号" << "\t" << "姓名" << "\t\t" << "电子" << "\t" << "C++" << "\t" << "物理" << "\t"
  85. << "英语" << "\t" << "数学" << "\t" << "体育" << "\t"<< "政治" << "\t" << "平均分" << endl;
  86. cout << "--------------------------------------------------------------------------------------------------------" << endl;
  87. for (int i = 0; i < Student::numStudent; i++)
  88. {
  89. cout << "----------------------------------------------------------------------------------------------------" << endl;
  90. cout << stu[i].class_0 << "\t\t" << stu[i].num << "\t" << stu[i].name << "\t\t"
  91. << stu[i].elec << "\t" << stu[i].c_program << "\t" << stu[i].physics << "\t"
  92. << stu[i].english << "\t" << stu[i].math << "\t" << stu[i].sport << "\t"
  93. << stu[i].polity << "\t" << stu[i].average << endl;
  94. }
  95. }
  96. //查询学生信息
  97. void Student::Lookup(Student *stu) {
  98. int s;
  99. cout << endl << "======>> 查找学生成绩 <<======" << endl;
  100. cout << "请输入要查找学生的学号:";
  101. cin>>s;
  102. for(int i = 0 ;i<Student::numStudent;i++){
  103. if(stu[i].num == s){
  104. cout << "----------------------------" << endl;
  105. cout << "班级:" << stu[i].class_0 << endl;
  106. cout << "学号:" << stu[i].num << endl;
  107. cout << "姓名:" << stu[i].name << endl;
  108. cout << "电子技术:" << stu[i].elec << endl;
  109. cout << "C++程序设计:" << stu[i].c_program << endl;
  110. cout << "物理:" << stu[i].physics << endl;
  111. cout << "大学英语:" << stu[i].english << endl;
  112. cout << "高等数学:" << stu[i].math << endl;
  113. cout << "大学体育:" << stu[i].sport << endl;
  114. cout << "政治:" << stu[i].polity << endl;
  115. cout << "平均分:" << stu[i].average << endl;
  116. return;
  117. }
  118. }
  119. cout<<"未找到该学生信息!"<<endl;
  120. }
  121. //修改学生信息
  122. void Student::Modify(Student *stu) {
  123. int s;
  124. cout << endl << "======>> 修改学生成绩 <<======" << endl;
  125. cout << "请输入要修改成绩学生的学号:";
  126. cin >> s;
  127. cout<<(stu[1]).math<<endl;
  128. for(int i = 0 ;i<Student::numStudent;i++){
  129. if((stu[i]).num == s){
  130. cout<<"找到该学生了,请重新输入该学生成绩:"<<endl;
  131. cout<<"学生学号不能被修改!"<<endl;
  132. cout << "学生班级:";
  133. cin >> (stu[i]).class_0;
  134. cout << "姓名:";
  135. cin >> (stu[i]).name;
  136. cout << "电子技术成绩:";
  137. cin >> (stu[i]).elec;
  138. cout << "C++成绩:";
  139. cin >> (stu[i]).c_program;
  140. cout << "物理成绩:";
  141. cin >> (stu[i]).physics;
  142. cout << "大学英语成绩:";
  143. cin >> (stu[i]).english;
  144. cout << "高等数学成绩:";
  145. cin >> (stu[i]).math;
  146. cout << "大学体育成绩:";
  147. cin >> (stu[i]).sport;
  148. cout << "政治:";
  149. cin >> (stu[i]).polity;
  150. (stu[i]).average = ((stu[i]).elec + (stu[i]).c_program + (stu[i]).physics +
  151. (stu[i]).english + (stu[i]).math + (stu[i]).sport + (stu[i]).polity) / 7;
  152. cout<<"修改成功"<<endl;
  153. }
  154. }
  155. }
  156. //删除学生信息
  157. void Student::Delete(Student *stu) {
  158. int s,j;
  159. char c = 0;
  160. cout << endl << "======>> 删除学生成绩 <<======" << endl;
  161. cout << "请输入要删除的学生的学号:";
  162. cin >> s;
  163. for(int i = 0 ;i<Student::numStudent;i++){
  164. if(stu[i].num == s){
  165. cout<<"学生已找到,是否删除(y/n):";
  166. cin>>c;
  167. if(c == 'y'||c =='Y'){
  168. for (j = i; j < Student::numStudent - 1; j++)
  169. {
  170. stu[j] = stu[j+1];//调用默认拷贝构造函数
  171. }
  172. cout << "======>> 提示:已成功删除!" << endl;
  173. Student::numStudent--;
  174. return;
  175. }
  176. }
  177. }
  178. }
  179. //输出所有学生信息
  180. void Student::Output(Student *stu) {
  181. cout << endl << "======>> 显示全部学生成绩 <<======" << endl;
  182. if (Student::numStudent == 0) {
  183. cout << "没有记录"<<endl;
  184. }
  185. else {
  186. cout << "------------------------------------------------------------------------------------" << endl;
  187. cout << "班级" << "\t" << "学号" << "\t" << "姓名" << "\t"
  188. << "电子" << "\t" << "C++" << "\t" << "物理" << "\t"
  189. << "英语" << "\t" << "数学" << "\t" << "体育" << "\t"
  190. << "政治" << "\t" << "平均分" << endl;
  191. cout << "------------------------------------------------------------------------------------" << endl;
  192. for (int i = 0; i < Student::numStudent; i++) {
  193. cout << stu[i].class_0 << "\t" << stu[i].num << "\t" << stu[i].name << "\t"
  194. << stu[i].elec << "\t" << stu[i].c_program << "\t" << stu[i].physics << "\t"
  195. << stu[i].english << "\t" << stu[i].math << "\t" << stu[i].sport << "\t"
  196. << stu[i].polity << "\t" << stu[i].average << endl;
  197. }
  198. cout << "------------------------------------------------------------------------------------" << endl;
  199. }
  200. }
  201. //排序管理界面
  202. int page()
  203. {
  204. int c;
  205. do {
  206. cout << "******************************************************" << endl;
  207. cout << "----------------欢迎查看各科成绩排名----------------" << endl;
  208. cout << "***************************************************" << endl;
  209. cout << " * 【1】电子技术成绩排名 * " << endl;
  210. cout << " * 【2】C++成绩排名 * " << endl;
  211. cout << " * 【3】物理成绩排名 * " << endl;
  212. cout << " * 【4】英语成绩排名 * " << endl;
  213. cout << " * 【5】高等数学成绩排名 * " << endl;
  214. cout << " * 【6】体育成绩排名 * " << endl;
  215. cout << " * 【7】政治成绩排名 * " << endl;
  216. cout << " * 【8】平均分排名 * " << endl;
  217. cout << " * 【0】退出 * " << endl;
  218. cout << "***************************************************" << endl;
  219. cout << "请选择您的操作 (0-8):" << endl;
  220. cin>>c;
  221. } while (c<0||c>9);
  222. return c;
  223. }
  224. //主页面
  225. int menu() {
  226. int c;
  227. do {
  228. cout << "******************************************************" << endl;
  229. cout << "------------欢迎使用高校学生成绩信息管理系统-----------" << endl;
  230. cout << "******************************************************" << endl;
  231. cout << "----------------欢迎使用学生成绩管理系统---------------" << endl;
  232. cout << " * 【1】输入学生成绩 * " << endl;
  233. cout << " * 【2】显示统计数据 * " << endl;
  234. cout << " * 【3】查找学生成绩 * " << endl;
  235. cout << " * 【4】修改学生成绩 * " << endl;
  236. cout << " * 【5】删除学生成绩 * " << endl;
  237. cout << " * 【6】按各科成绩排列 * " << endl;
  238. cout << " * 【7】显示学生成绩 * " << endl;
  239. cout << " * 【8】显示学生挂科情况 * " << endl;
  240. cout << " * 【0】退出管理系统 * " << endl;
  241. cout << "******************************************************" << endl;
  242. cout << "请选择您的操作 (0-8):" << endl;
  243. cin>>c;
  244. } while (c<0||c>=9);
  245. return c;
  246. }
  247. //排序
  248. void Student::Sort(Student *stu) {
  249. //按学科成绩排
  250. int res;
  251. while(1)
  252. {
  253. res = page(); //调用page()函数
  254. switch (res)
  255. {
  256. case 1:
  257. for (int i = 0; i < Student::numStudent - 1; i++)
  258. for (int j = 0; j < Student::numStudent - 1; j++)
  259. if (stu[j].elec < stu[j + 1].elec) {
  260. Student temp = stu[j];
  261. stu[j] = stu[j + 1];
  262. stu[j + 1] = temp;
  263. }
  264. Output(stu);
  265. break;
  266. case 2:
  267. for (int i = 0; i < Student::numStudent - 1; i++)
  268. for (int j = 0; j < Student::numStudent - 1; j++)
  269. if (stu[j].c_program < stu[j + 1].c_program) {
  270. Student temp = stu[j];
  271. stu[j] = stu[j + 1];
  272. stu[j + 1] =temp;
  273. }
  274. Output(stu);
  275. break;
  276. case 3:
  277. for (int i = 0; i < Student::numStudent - 1; i++)
  278. for (int j = 0; j < Student::numStudent - 1; j++)
  279. if (stu[j].physics < stu[j + 1].physics) {
  280. Student temp = stu[j];
  281. stu[j] = stu[j + 1];
  282. stu[j + 1] =temp;
  283. }
  284. Output(stu);
  285. break;
  286. case 4:
  287. for (int i = 0; i < Student::numStudent - 1; i++)
  288. for (int j = 0; j < Student::numStudent - 1; j++)
  289. if (stu[j].english < stu[j + 1].english) {
  290. Student temp = stu[j];
  291. stu[j] = stu[j + 1];
  292. stu[j + 1] =temp;
  293. }
  294. Output(stu);
  295. break;
  296. case 5:
  297. for (int i = 0; i < Student::numStudent - 1; i++)
  298. for (int j = 0; j < Student::numStudent - 1; j++)
  299. if (stu[j].math < stu[j + 1].math) {
  300. Student temp = stu[j];
  301. stu[j] = stu[j + 1];
  302. stu[j + 1] =temp;
  303. }
  304. Output(stu);
  305. break;
  306. case 6:
  307. for (int i = 0; i < Student::numStudent - 1; i++)
  308. for (int j = 0; j < Student::numStudent - 1; j++)
  309. if (stu[j].sport < stu[j + 1].sport) {
  310. Student temp = stu[j];
  311. stu[j] = stu[j + 1];
  312. stu[j + 1] =temp;
  313. }
  314. Output(stu);
  315. break;
  316. case 7:
  317. for (int i = 0; i < Student::numStudent - 1; i++)
  318. for (int j = 0; j < Student::numStudent - 1; j++)
  319. if (stu[j].polity < stu[j + 1].polity) {
  320. Student temp = stu[j];
  321. stu[j] = stu[j + 1];
  322. stu[j + 1] =temp;
  323. }
  324. Output(stu);
  325. break;
  326. case 8:
  327. for (int i = 0; i < Student::numStudent - 1; i++)
  328. for (int j = 0; j < Student::numStudent - 1; j++)
  329. if (stu[j].average < stu[j + 1].average) {
  330. Student temp = stu[j];
  331. stu[j] = stu[j + 1];
  332. stu[j + 1] =temp;
  333. }
  334. Output(stu);
  335. break;
  336. case 0:
  337. cout << endl << "=============正在返回上一级==========\n" << endl;
  338. menu();
  339. return;
  340. }
  341. }
  342. }
  343. //检测成绩输入范围
  344. bool Student::CheckScore(float score) {
  345. if(score>-1 && score<=100)
  346. return true;
  347. else
  348. return false;
  349. }
  350. //挂科情况
  351. void Student::Sling(Student *stu) {
  352. int i, j, k,count ;
  353. cout << " " << endl;
  354. cout << "**********************学生挂科情况*********************" << endl;
  355. cout << " " << endl;
  356. for (i = 0; i < Student::numStudent; i++)
  357. {
  358. for (j = 0; j < 6; j++)
  359. {
  360. count = 0;
  361. if (stu[i].elec < 60) count++;
  362. if (stu[i].c_program < 60) count++;
  363. if (stu[i].physics < 60) count++;
  364. if (stu[i].english < 60) count++;
  365. if (stu[i].math < 60) count++;
  366. if (stu[i].sport < 60) count++;
  367. if (stu[i].polity < 60) count++;
  368. }
  369. cout << stu[i].name << " " << "有" << count << "门课挂科" << endl;
  370. cout << "--------------------------------------------------------" << endl;
  371. }
  372. }
  373. int main(){
  374. Student* stu = new Student[STU_MAX];
  375. Student StartUp;
  376. while (1) //无限循环
  377. {
  378. int res = menu();
  379. switch (res) //调用menu()函数
  380. {
  381. case 1:
  382. StartUp.Input(stu);
  383. break;
  384. case 2:
  385. StartUp.Statistic(stu);
  386. break;
  387. case 3:
  388. StartUp.Lookup(stu);
  389. break;
  390. case 4:
  391. StartUp.Modify(stu);
  392. break;
  393. case 5:
  394. StartUp.Delete(stu);
  395. break;
  396. case 6:
  397. StartUp.Sort(stu);
  398. break;
  399. case 7:
  400. StartUp.Output(stu);
  401. break;
  402. case 8:
  403. StartUp.Sling(stu);
  404. break;
  405. case 0:
  406. cout << endl << "================感谢您使用学生成绩管理系统==============\n" << endl;
  407. exit(0);
  408. }
  409. }
  410. return 0;
  411. }

开发环境:Windows

编辑器:clion

发表评论

表情:
评论列表 (有 0 条评论,167人围观)

还没有评论,来说两句吧...

相关阅读

    相关 JAVA作品——超市管理系统

    项目描述:一个简单的超市管理系统,能够实现用户登入和注册功能,共分为前台和后台两个主要界面,普通用户界面操作权限收到限制,只能对商品和销售记录进行简单查询操作,后台中可以进行商

    相关 Review学生作业管理系统

    让后台立即响应前端,前端不等待处理过程 描述:学生作业管理系统里面有一个邮件提醒的功能,如果不加以处理前端就会一直等待返回结果不会弹出发送成功的提示,直到邮件已经发送出去