当前位置:   article > 正文

C语言/C++课程设计---学生管理系统_c++程序设计学习与管理系统

c++程序设计学习与管理系统

        很多大一的同学刚接触C语言都有过被课设困扰的烦恼吧,别担心,幸好你刷到了我这篇文章,本人结合C语言的学习经验和对面向过程开发的理解,特意写了一个关于学生成绩管理系统的程序,希望给还在抓耳挠腮的你一丝丝的灵感。

        

   (一)项目需求:

学习成绩管理系统功能示意图

(二)成品 展示:

封面

录入界面

成绩排名

删除

删除后排名

新增

标题

查询

查询菜单

 注:背景颜色是窗口属性调节的,不是代码弄的!

(三)程序剖析

头文件:

  1. #include<iostream>        //引用c++的输入输出流,方便输入输出字符串
  2. #include<conio.h>        //引用控制台头文件,调用函数getch()等待键盘输入
  3. #include<stdlib.h>        //C语言标准库头文件可调用多种基础函数
  4. #include<stdio.h>        //C语言的输入输出头文件
  5. using namespace std;        //调用c++标准库,功能强大

 学生结构体:

  1. struct students
  2. {
  3.     string name;//姓名 
  4.     string num;//学号 
  5.     int chinese;//语文成绩 
  6.     int math;//数学成绩 
  7.     int english;//英语成绩        
  8.     int sum;//总分 
  9.     int rank;//排名 
  10. }stu[100];

中间学生结构体:

  1. //用于后续"删除”功能的使用,后面会详解。
  2. struct student
  3. {
  4.     string name;//姓名 
  5.     string num;//学号 
  6.     int chinese;//语文成绩 
  7.     int math;//数学成绩 
  8.     int english;//英语成绩        
  9.     int sum;//总分 
  10.     int rank;//排名 
  11. }_stu[100];

函数声明:

  1. void cover();//封面函数声明 
  2. void menu_main();//主菜单函数声明
  3. void menu_search();//搜索菜单函数声明
  4. void menu_single();//单科成绩菜单函数声明

功能实现:

1、录入学生信息

  1. cout<<"Please enter the number of students:"<<endl;
  2. cin>>n;
  3. cout<<"Please enter student information:"<<endl;
  4. cout<<"INCLUDE:";
  5. for(int i = 1; i <= n; i++)
  6. {
  7. cout<<endl<<"Name : "; cin>>stu[i].name;
  8. cout<<"Numbers : "; cin>>stu[i].num;
  9. cout<<"Chinese score : "; cin>>stu[i].chinese;
  10. cout<<"Math score : "; cin>>stu[i].math;
  11. cout<<"English score : "; cin>>stu[i].english;
  12. stu[i].sum = stu[i].chinese + stu[i].math + stu[i].english;
  13. }

2、学生成绩排名

  1. //冒泡排序
  2. for(int i = 1; i <= n ; i++)
  3. {
  4. for(int j = i+1 ; j <= n ; j++)
  5. {
  6. if(stu[j].sum>stu[i].sum)
  7. {
  8. //根据总分排序
  9. int temp = stu[j].sum;
  10. stu[j].sum = stu[i].sum;
  11. stu[i].sum = temp;
  12. //更换学号
  13. string temp0 = stu[j].num;
  14. stu[j].num = stu[i].num;
  15. stu[i].num = temp0;
  16. //更换名字
  17. string temp1 = stu[j].name;
  18. stu[j].name = stu[i].name;
  19. stu[i].name = temp1;
  20. //更换语文成绩
  21. int temp2 = stu[j].chinese;
  22. stu[j].chinese = stu[i].chinese;
  23. stu[i].chinese = temp2;
  24. //更换数学成绩
  25. int temp3 = stu[j].math;
  26. stu[j].math = stu[i].math;
  27. stu[i].math = temp3;
  28. //更换英语成绩
  29. int temp4 = stu[j].english;
  30. stu[j].english = stu[i].english;
  31. stu[i].english = temp4;
  32. }
  33. }
  34. }

3、删除学生信息

算法:

  1. string del_name;
  2. // struct students _stu[100];
  3. cout<<"Please enter the name of the student whose grade you wish to delete(请输入你要删除成绩的学生的姓名):";
  4. cin>>del_name;
  5. for(int i = 1; i <= n; i++)
  6. {
  7. if(del_name == stu[i].name)//找到了
  8. {
  9. // _stu[i].name = "\\";// \ -是转义字符
  10. // _stu[i].num = "\\" ;
  11. for(int j = 1; j <= i-1; j++)
  12. {
  13. _stu[j].name = stu[j].name;//将i前面的数据转移
  14. _stu[j].num = stu[j].num;
  15. _stu[j].chinese = stu[j].chinese;
  16. _stu[j].math = stu[j].math;
  17. _stu[j].english = stu[j].english;
  18. _stu[j].sum = stu[j].sum;
  19. }
  20. //显然,_stu[i]中和i对应的数据是空的,但是没关系,重新排序就好了 ,此行必在最后面
  21. //name = ' ',num = ' ', c = 0, m = 0, e = 0 ,sum = 0,r = ?
  22. for(int j = i+1; j <= n; j++)
  23. {
  24. _stu[j-1].name = stu[j].name;//将i后面的数据转移
  25. _stu[j-1].num = stu[j].num;
  26. _stu[j-1].chinese = stu[j].chinese;
  27. _stu[j-1].math = stu[j].math;
  28. _stu[j-1].english = stu[j].english;
  29. _stu[j-1].sum = stu[j].sum;
  30. }
  31. n = n - 1;//点睛之笔, 别忘了让整体的数组元素少一
  32. for(int k = 1; k <= n; k++)
  33. {
  34. stu[k].name = _stu[k].name;//换回
  35. stu[k].num = _stu[k].num;
  36. stu[k].chinese = _stu[k].chinese;
  37. stu[k].math = _stu[k].math;
  38. stu[k].english = _stu[k].english;
  39. stu[k].sum = _stu[k].sum;
  40. }
  41. }
  42. }

4、查询学生成绩

  1. //基本上就是字符串比较
  2. int mark;
  3. do{
  4. menu_search();
  5. cin>>mark;
  6. if(mark == 1)
  7. {
  8. string num;
  9. cout<<"Input number:";
  10. cin>>num;
  11. for(int i = 1; i <= n; i++)
  12. {
  13. if(num == stu[i].num)
  14. {
  15. cout<<"Name : "<<stu[i].name<<endl;
  16. cout<<"Chinese score : "<<stu[i].chinese<<endl;
  17. cout<<"Math score : "<<stu[i].math<<endl;
  18. cout<<"Englsih score : "<<stu[i].english<<endl;
  19. cout<<"Sum of score : "<<stu[i].sum<<endl;
  20. cout<<"Rank of student "<<stu[i].rank<<endl;
  21. getch();
  22. }
  23. }
  24. }
  25. if(mark == 2)
  26. {
  27. string name;
  28. cout<<"Input name : ";
  29. cin>>name;
  30. for(int i = 1; i <= n; i++)
  31. {
  32. if(name == stu[i].name)
  33. {
  34. cout<<"Number : "<<stu[i].num<<endl;
  35. cout<<"Chinese score : "<<stu[i].chinese<<endl;
  36. cout<<"Math score : "<<stu[i].math<<endl;
  37. cout<<"Englsih score : "<<stu[i].english<<endl;
  38. cout<<"Sum of score : "<<stu[i].sum<<endl;
  39. cout<<"Rank of student "<<stu[i].rank<<endl;
  40. getch();
  41. }
  42. }
  43. }
  44. if(mark == 3)
  45. {
  46. int sum;
  47. cout<<"Input sum of score : ";
  48. cin>>sum;
  49. for(int i = 1; i <= n; i++)
  50. {
  51. if(sum == stu[i].sum)
  52. {
  53. cout<<"Number : "<<stu[i].num<<endl;
  54. cout<<"Name : "<<stu[i].name<<endl;
  55. cout<<"Chinese score : "<<stu[i].chinese<<endl;
  56. cout<<"Math score : "<<stu[i].math<<endl;
  57. cout<<"Englsih score : "<<stu[i].english<<endl;
  58. cout<<"Rank of student "<<stu[i].rank<<endl;
  59. getch();
  60. }
  61. }
  62. }
  63. if(mark == 4)
  64. {
  65. int find;
  66. int search;
  67. do{
  68. menu_single();
  69. cin>>find;
  70. if(find == 1)//查语文
  71. {
  72. for(int i = 1; i <= n; i++)
  73. {
  74. _stu[i].name = stu[i].name;
  75. _stu[i].num = stu[i].num;
  76. _stu[i].chinese = stu[i].chinese;
  77. }
  78. for(int i = 1; i <= n; i++)
  79. {
  80. for(int j = i+1; j <= n; j++)
  81. {
  82. if(_stu[i].chinese < _stu[j].chinese)
  83. { //更换语文成绩
  84. int temp2 = _stu[j].chinese;
  85. _stu[j].chinese = _stu[i].chinese;
  86. _stu[i].chinese = temp2;
  87. //更换学号
  88. string temp0 = _stu[j].num;
  89. _stu[j].num = _stu[i].num;
  90. _stu[i].num = temp0;
  91. //更换名字
  92. string temp1 = _stu[j].name;
  93. _stu[j].name = _stu[i].name;
  94. _stu[i].name = temp1;
  95. }
  96. }
  97. }
  98. cout<<"Chinese transcripts : "<<endl;
  99. cout<<"Name\tNumber\tChinese : "<<endl;
  100. for(int i = 1; i <= n; i++)
  101. {
  102. cout<<_stu[i].name<<'\t'<<_stu[i].num<<'\t'<<_stu[i].chinese<<endl;
  103. }
  104. cout<<"Failure list of Chinese grades (score < 60 ): "<<endl;
  105. cout<<"Name\tNumber\tChinese : "<<endl;
  106. for(int i = 1; i <= n; i++)
  107. {
  108. if(_stu[i].chinese < 60)
  109. cout<<_stu[i].name<<'\t'<<_stu[i].num<<'\t'<<_stu[i].chinese<<endl;
  110. }
  111. cout<<"For a quick search, press 5,(快捷搜索);"<<"Return to the parent directory , press 0 "<<endl;
  112. cin>>search;
  113. if(search == 5)
  114. {
  115. do{
  116. system("cls");
  117. int con;
  118. string S_name,S_num;
  119. cout<<"[Quick search]"<<endl<<endl;
  120. cout<<"Press '1' to continue,press '0' to stop ."<<endl;
  121. getch();
  122. cin>>con;
  123. if(con == 1)
  124. {
  125. cout<<"Please enter the name and student id"<<endl;
  126. cout<<"Name: "; cin>>S_name; cout<<"ID : "; cin>>S_num;
  127. for(int i = 1; i <= n; i++)
  128. {
  129. if(S_name == _stu[i].name && S_num == _stu[i].num)
  130. {
  131. cout<<"Chinese : "<<_stu[i].chinese<<endl;
  132. }
  133. }
  134. getch();
  135. }
  136. if(con == 0)
  137. search = 0;
  138. }while( search!= 0);
  139. }
  140. cout<<"After the display is complete, press any key to return to the parent directory (@^V^@);"<<endl;
  141. getch();
  142. }

5、修改学生成绩

  1. string name,_name,num;
  2. int chinese,math,english,sum;
  3. cout<<"Please enter the name of the person whose score you want to change:(你要修改谁的成绩?):";
  4. cin>>name;
  5. cout<<"Please re-enter the correct information (请重新输入正确的信息):"<<endl;
  6. cout<<"Name : "<<' '; cin>>_name;
  7. cout<<"Number : "<<' '; cin>>num;
  8. cout<<"Chinese : "<<' '; cin>>chinese;
  9. cout<<"English : "<<' '; cin>>english;
  10. cout<<"Math : "<<' '; cin>>math;
  11. sum = chinese + english + math;
  12. for(int i = 1; i <= n; i++)
  13. {
  14. if(name == stu[i].name)
  15. {
  16. stu[i].name = _name;
  17. stu[i].num = num;
  18. stu[i].chinese = chinese;
  19. stu[i].math = math;
  20. stu[i].english = english;
  21. stu[i].sum = sum;
  22. }
  23. }

6、显示学生成绩

  1. system("cls");//清屏函数
  2. cout<<"Student grades are as follows:"<<endl;
  3. cout<<"学号\t姓名\t语文\t数学\t英语\t总分\t名次"<<endl;
  4. for(int i = 1; i <= n; i++)
  5. {
  6. stu[i].rank = i;
  7. cout<<stu[i].num<<'\t'<<stu[i].name<<'\t'<<stu[i].
  8. chinese<<'\t'<<stu[i].math<<'\t'<<stu[i].english<<
  9. '\t'<<stu[i].sum<<'\t'<<stu[i].rank<<endl;
  10. }
  11. getch();

注:单科成绩单与不及格名单都在查询功能模块内,详细功能请参考下面完整代码。

(四)程序源代码

  1. #include<iostream>
  2. #include<conio.h>
  3. #include<stdlib.h>
  4. #include<stdio.h>
  5. using namespace std;
  6. struct students
  7. {
  8. string name;//姓名
  9. string num;//学号
  10. int chinese;//语文成绩
  11. int math;//数学成绩
  12. int english;//英语成绩
  13. int sum;//总分
  14. int rank;//排名
  15. }stu[100];
  16. //替身
  17. struct student
  18. {
  19. string name;//姓名
  20. string num;//学号
  21. int chinese;//语文成绩
  22. int math;//数学成绩
  23. int english;//英语成绩
  24. int sum;//总分
  25. int rank;//排名
  26. }_stu[100];
  27. void cover();//封面函数声明
  28. void menu_main();
  29. void menu_search();
  30. void menu_single();
  31. int main()
  32. {
  33. cover();
  34. getch();
  35. int n;
  36. int flag;
  37. system("cls");
  38. cout<<"Please enter the number of students:"<<endl;
  39. cin>>n;
  40. cout<<"Please enter student information:"<<endl;
  41. cout<<"INCLUDE:"<<endl;
  42. for(int i = 1; i <= n; i++)
  43. {
  44. cout<<"----------------the number of "<<i<<" student:-------------------"<<endl;
  45. cout<<"Name : "; cin>>stu[i].name;
  46. cout<<"Numbers : "; cin>>stu[i].num;
  47. cout<<"Chinese score : "; cin>>stu[i].chinese;
  48. cout<<"Math score : "; cin>>stu[i].math;
  49. cout<<"English score : "; cin>>stu[i].english;
  50. stu[i].sum = stu[i].chinese + stu[i].math + stu[i].english;
  51. }
  52. do{
  53. menu_main();
  54. cin>>flag;
  55. if(flag == 1)//新加一位
  56. {
  57. n = n+1;
  58. cout<<"Please enter new student information : "<<endl;
  59. cout<<"INCLUDE:";
  60. cout<<endl<<"Name : "; cin>>stu[n].name;
  61. cout<<"Numbers : "; cin>>stu[n].num;
  62. cout<<"Chinese score : "; cin>>stu[n].chinese;
  63. cout<<"Math score : "; cin>>stu[n].math;
  64. cout<<"English score : "; cin>>stu[n].english;
  65. stu[n].sum = stu[n].chinese + stu[n].math + stu[n].english;
  66. cout<<"Add to complete (^v^)!"<<endl;
  67. getch();
  68. }
  69. if(flag == 2)//成绩排名
  70. {
  71. //冒泡排序
  72. for(int i = 1; i <= n ; i++)
  73. {
  74. for(int j = i+1 ; j <= n ; j++)
  75. {
  76. if(stu[j].sum>stu[i].sum)
  77. {
  78. //根据总分排序
  79. int temp = stu[j].sum;
  80. stu[j].sum = stu[i].sum;
  81. stu[i].sum = temp;
  82. //更换学号
  83. string temp0 = stu[j].num;
  84. stu[j].num = stu[i].num;
  85. stu[i].num = temp0;
  86. //更换名字
  87. string temp1 = stu[j].name;
  88. stu[j].name = stu[i].name;
  89. stu[i].name = temp1;
  90. //更换语文成绩
  91. int temp2 = stu[j].chinese;
  92. stu[j].chinese = stu[i].chinese;
  93. stu[i].chinese = temp2;
  94. //更换数学成绩
  95. int temp3 = stu[j].math;
  96. stu[j].math = stu[i].math;
  97. stu[i].math = temp3;
  98. //更换英语成绩
  99. int temp4 = stu[j].english;
  100. stu[j].english = stu[i].english;
  101. stu[i].english = temp4;
  102. }
  103. }
  104. }
  105. //rank
  106. for(int i = 1; i <= n; i++)
  107. {
  108. stu[i].rank = i;
  109. }
  110. cout<<"The student ranking is complete !(^v^)!"<<endl;
  111. getch();
  112. }
  113. if(flag == 3)//查询学生成绩
  114. {
  115. int mark;
  116. do{
  117. menu_search();
  118. cin>>mark;
  119. if(mark == 1)
  120. {
  121. string num;
  122. cout<<"Input number:";
  123. cin>>num;
  124. for(int i = 1; i <= n; i++)
  125. {
  126. if(num == stu[i].num)
  127. {
  128. cout<<"Name : "<<stu[i].name<<endl;
  129. cout<<"Chinese score : "<<stu[i].chinese<<endl;
  130. cout<<"Math score : "<<stu[i].math<<endl;
  131. cout<<"Englsih score : "<<stu[i].english<<endl;
  132. cout<<"Sum of score : "<<stu[i].sum<<endl;
  133. cout<<"Rank of student "<<stu[i].rank<<endl;
  134. getch();
  135. }
  136. }
  137. }
  138. if(mark == 2)
  139. {
  140. string name;
  141. cout<<"Input name : ";
  142. cin>>name;
  143. for(int i = 1; i <= n; i++)
  144. {
  145. if(name == stu[i].name)
  146. {
  147. cout<<"Number : "<<stu[i].num<<endl;
  148. cout<<"Chinese score : "<<stu[i].chinese<<endl;
  149. cout<<"Math score : "<<stu[i].math<<endl;
  150. cout<<"Englsih score : "<<stu[i].english<<endl;
  151. cout<<"Sum of score : "<<stu[i].sum<<endl;
  152. cout<<"Rank of student "<<stu[i].rank<<endl;
  153. getch();
  154. }
  155. }
  156. }
  157. if(mark == 3)
  158. {
  159. int sum;
  160. cout<<"Input sum of score : ";
  161. cin>>sum;
  162. for(int i = 1; i <= n; i++)
  163. {
  164. if(sum == stu[i].sum)
  165. {
  166. cout<<"Number : "<<stu[i].num<<endl;
  167. cout<<"Name : "<<stu[i].name<<endl;
  168. cout<<"Chinese score : "<<stu[i].chinese<<endl;
  169. cout<<"Math score : "<<stu[i].math<<endl;
  170. cout<<"Englsih score : "<<stu[i].english<<endl;
  171. cout<<"Rank of student "<<stu[i].rank<<endl;
  172. getch();
  173. }
  174. }
  175. }
  176. if(mark == 4)
  177. {
  178. int find;
  179. int search;
  180. do{
  181. menu_single();
  182. cin>>find;
  183. if(find == 1)//查语文
  184. {
  185. for(int i = 1; i <= n; i++)
  186. {
  187. _stu[i].name = stu[i].name;
  188. _stu[i].num = stu[i].num;
  189. _stu[i].chinese = stu[i].chinese;
  190. }
  191. for(int i = 1; i <= n; i++)
  192. {
  193. for(int j = i+1; j <= n; j++)
  194. {
  195. if(_stu[i].chinese < _stu[j].chinese)
  196. { //更换语文成绩
  197. int temp2 = _stu[j].chinese;
  198. _stu[j].chinese = _stu[i].chinese;
  199. _stu[i].chinese = temp2;
  200. //更换学号
  201. string temp0 = _stu[j].num;
  202. _stu[j].num = _stu[i].num;
  203. _stu[i].num = temp0;
  204. //更换名字
  205. string temp1 = _stu[j].name;
  206. _stu[j].name = _stu[i].name;
  207. _stu[i].name = temp1;
  208. }
  209. }
  210. }
  211. cout<<"Chinese transcripts : "<<endl;
  212. cout<<"Name\tNumber\tChinese : "<<endl;
  213. for(int i = 1; i <= n; i++)
  214. {
  215. cout<<_stu[i].name<<'\t'<<_stu[i].num<<'\t'<<_stu[i].chinese<<endl;
  216. }
  217. cout<<"Failure list of Chinese grades (score < 60 ): "<<endl;
  218. cout<<"Name\tNumber\tChinese : "<<endl;
  219. for(int i = 1; i <= n; i++)
  220. {
  221. if(_stu[i].chinese < 60)
  222. cout<<_stu[i].name<<'\t'<<_stu[i].num<<'\t'<<_stu[i].chinese<<endl;
  223. }
  224. cout<<"For a quick search, press 5,(快捷搜索);"<<"Return to the parent directory , press 0 "<<endl;
  225. cin>>search;
  226. if(search == 5)
  227. {
  228. do{
  229. system("cls");
  230. int con;
  231. string S_name,S_num;
  232. cout<<"[Quick search]"<<endl<<endl;
  233. cout<<"Press '1' to continue,press '0' to stop ."<<endl;
  234. getch();
  235. cin>>con;
  236. if(con == 1)
  237. {
  238. cout<<"Please enter the name and student id"<<endl;
  239. cout<<"Name: "; cin>>S_name; cout<<"ID : "; cin>>S_num;
  240. for(int i = 1; i <= n; i++)
  241. {
  242. if(S_name == _stu[i].name && S_num == _stu[i].num)
  243. {
  244. cout<<"Chinese : "<<_stu[i].chinese<<endl;
  245. }
  246. }
  247. getch();
  248. }
  249. if(con == 0)
  250. search = 0;
  251. }while( search!= 0);
  252. }
  253. cout<<"After the display is complete, press any key to return to the parent directory (@^V^@);"<<endl;
  254. getch();
  255. }
  256. if(find == 2)//查数学
  257. {
  258. for(int i = 1; i <= n; i++)
  259. {
  260. _stu[i].name = stu[i].name;
  261. _stu[i].num = stu[i].num;
  262. _stu[i].math = stu[i].math;
  263. }
  264. for(int i = 1; i <= n; i++)
  265. {
  266. for(int j = i+1; j <= n; j++)
  267. {
  268. if(_stu[i].math < _stu[j].math)
  269. { //更换数学成绩
  270. int temp2 = _stu[j].math;
  271. _stu[j].math = _stu[i].math;
  272. _stu[i].math = temp2;
  273. //更换学号
  274. string temp0 = _stu[j].num;
  275. _stu[j].num = _stu[i].num;
  276. _stu[i].num = temp0;
  277. //更换名字
  278. string temp1 = _stu[j].name;
  279. _stu[j].name = _stu[i].name;
  280. _stu[i].name = temp1;
  281. }
  282. }
  283. }
  284. cout<<"math transcripts : "<<endl;
  285. cout<<"Name\tNumber\tMath : "<<endl;
  286. for(int i = 1; i <= n; i++)
  287. {
  288. cout<<_stu[i].name<<'\t'<<_stu[i].num<<'\t'<<_stu[i].math<<endl;
  289. }
  290. cout<<"Failure list of math grades (score < 60 ): "<<endl;
  291. cout<<"Name\tNumber\tMath : "<<endl;
  292. for(int i = 1; i <= n; i++)
  293. {
  294. if(_stu[i].math < 60)
  295. cout<<_stu[i].name<<'\t'<<_stu[i].num<<'\t'<<_stu[i].math<<endl;
  296. }
  297. cout<<"For a quick search, press 5,(快捷搜索);"<<"Return to the parent directory , press 0 "<<endl;
  298. cin>>search;
  299. if(search == 5)
  300. {
  301. do{
  302. system("cls");
  303. int con;
  304. string S_name,S_num;
  305. cout<<"[Quick search]"<<endl<<endl;
  306. cout<<"Press '1' to continue,press '0' to stop ."<<endl;
  307. getch();
  308. cin>>con;
  309. if(con == 1)
  310. {
  311. cout<<"Please enter the name and student id"<<endl;
  312. cout<<"Name: "; cin>>S_name; cout<<"ID : "; cin>>S_num;
  313. for(int i = 1; i <= n; i++)
  314. {
  315. if(S_name == _stu[i].name && S_num == _stu[i].num)
  316. {
  317. cout<<"Math : "<<_stu[i].math<<endl;
  318. }
  319. }
  320. getch();
  321. }
  322. if(con == 0)
  323. search = 0;
  324. }while( search!= 0);
  325. }
  326. cout<<"After the display is complete, press any key to return to the parent directory(@^V^@);"<<endl;
  327. getch();
  328. }
  329. if(find == 3)//查英语
  330. {
  331. for(int i = 1; i <= n; i++)
  332. {
  333. _stu[i].name = stu[i].name;
  334. _stu[i].num = stu[i].num;
  335. _stu[i].english = stu[i].english;
  336. }
  337. for(int i = 1; i <= n; i++)
  338. {
  339. for(int j = i+1; j <= n; j++)
  340. {
  341. if(_stu[i].english < _stu[j].english)
  342. {
  343. //更换英语成绩
  344. int temp2 = _stu[j].english;
  345. _stu[j].english = _stu[i].english;
  346. _stu[i].english = temp2;
  347. //更换学号
  348. string temp0 = _stu[j].num;
  349. _stu[j].num = _stu[i].num;
  350. _stu[i].num = temp0;
  351. //更换名字
  352. string temp1 = _stu[j].name;
  353. _stu[j].name = _stu[i].name;
  354. _stu[i].name = temp1;
  355. }
  356. }
  357. }
  358. cout<<"english transcripts : "<<endl;
  359. cout<<"Name\tNumber\tEnglish : "<<endl;
  360. for(int i = 1; i <= n; i++)
  361. {
  362. cout<<_stu[i].name<<'\t'<<_stu[i].num<<'\t'<<_stu[i].english<<endl;
  363. }
  364. cout<<"Failure list of english grades (score < 60 ): "<<endl;
  365. cout<<"Name\tNumber\tEnglish : "<<endl;
  366. for(int i = 1; i <= n; i++)
  367. {
  368. if(_stu[i].english < 60)
  369. cout<<_stu[i].name<<'\t'<<_stu[i].num<<'\t'<<_stu[i].english<<endl;
  370. }
  371. cout<<"For a quick search, press 5,(快捷搜索);"<<"Return to the parent directory , press 0 "<<endl;
  372. cin>>search;
  373. if(search == 5)
  374. {
  375. do{
  376. system("cls");
  377. int con;
  378. string S_name,S_num;
  379. cout<<"[Quick search]"<<endl<<endl;
  380. cout<<"Press '1' to continue,press '0' to stop ."<<endl;
  381. getch();
  382. cin>>con;
  383. if(con == 1)
  384. {
  385. cout<<"Please enter the name and student id"<<endl;
  386. cout<<"Name: "; cin>>S_name; cout<<"ID : "; cin>>S_num;
  387. for(int i = 1; i <= n; i++)
  388. {
  389. if(S_name == _stu[i].name && S_num == _stu[i].num)
  390. {
  391. cout<<"English : "<<_stu[i].english<<endl;
  392. }
  393. }
  394. getch();
  395. }
  396. if(con == 0)
  397. search = 0;
  398. }while( search!= 0);
  399. }
  400. cout<<"After the display is complete, press any key to return to the parent directory(@^V^@);"<<endl;
  401. getch();
  402. }
  403. }while(find != 0);
  404. }
  405. }while(mark != 0);
  406. cout<<"All content is displayed"<<endl;
  407. getch();
  408. }
  409. if(flag == 4)//修改成绩
  410. {
  411. string name,_name,num;
  412. int chinese,math,english,sum;
  413. cout<<"Please enter the name of the person whose score you want to change:(你要修改谁的成绩?):";
  414. cin>>name;
  415. cout<<"Please re-enter the correct information (请重新输入正确的信息):"<<endl;
  416. cout<<"Name : "<<' '; cin>>_name;
  417. cout<<"Number : "<<' '; cin>>num;
  418. cout<<"Chinese : "<<' '; cin>>chinese;
  419. cout<<"English : "<<' '; cin>>english;
  420. cout<<"Math : "<<' '; cin>>math;
  421. sum = chinese + english + math;
  422. for(int i = 1; i <= n; i++)
  423. {
  424. if(name == stu[i].name)
  425. {
  426. stu[i].name = _name;
  427. stu[i].num = num;
  428. stu[i].chinese = chinese;
  429. stu[i].math = math;
  430. stu[i].english = english;
  431. stu[i].sum = sum;
  432. }
  433. }
  434. cout<<"Modified completed !(^v^)!"<<endl;
  435. getch();
  436. }
  437. if(flag == 5)//删除成绩
  438. {
  439. string del_name;
  440. // struct students _stu[100];
  441. cout<<"Please enter the name of the student whose grade you wish to delete(请输入你要删除成绩的学生的姓名):";
  442. cin>>del_name;
  443. for(int i = 1; i <= n; i++)
  444. {
  445. if(del_name == stu[i].name)//找到了
  446. {
  447. // _stu[i].name = "\\";// \ -是转义字符
  448. // _stu[i].num = "\\" ;
  449. for(int j = 1; j <= i-1; j++)
  450. {
  451. _stu[j].name = stu[j].name;//将i前面的数据转移
  452. _stu[j].num = stu[j].num;
  453. _stu[j].chinese = stu[j].chinese;
  454. _stu[j].math = stu[j].math;
  455. _stu[j].english = stu[j].english;
  456. _stu[j].sum = stu[j].sum;
  457. }
  458. //显然,_stu[i]中和i对应的数据是空的,但是没关系,重新排序就好了 ,此行必在最后面
  459. //name = ' ',num = ' ', c = 0, m = 0, e = 0 ,sum = 0,r = ?
  460. for(int j = i+1; j <= n; j++)
  461. {
  462. _stu[j-1].name = stu[j].name;//将i后面的数据转移
  463. _stu[j-1].num = stu[j].num;
  464. _stu[j-1].chinese = stu[j].chinese;
  465. _stu[j-1].math = stu[j].math;
  466. _stu[j-1].english = stu[j].english;
  467. _stu[j-1].sum = stu[j].sum;
  468. }
  469. n = n - 1;//点睛之笔, 别忘了让整体的数组元素少一
  470. for(int k = 1; k <= n; k++)
  471. {
  472. stu[k].name = _stu[k].name;//换回
  473. stu[k].num = _stu[k].num;
  474. stu[k].chinese = _stu[k].chinese;
  475. stu[k].math = _stu[k].math;
  476. stu[k].english = _stu[k].english;
  477. stu[k].sum = _stu[k].sum;
  478. }
  479. }
  480. }
  481. cout<<"Delete finished, please reorder(删除完毕,请重新排序)!(^v^)!"<<endl;
  482. getch();
  483. }
  484. if(flag == 6)//显示学生成绩信息
  485. {
  486. system("cls");
  487. cout<<"Student grades are as follows:"<<endl;
  488. cout<<"学号\t姓名\t语文\t数学\t英语\t总分\t名次"<<endl;
  489. for(int i = 1; i <= n; i++)
  490. {
  491. stu[i].rank = i;
  492. cout<<stu[i].num<<'\t'<<stu[i].name<<'\t'<<stu[i].
  493. chinese<<'\t'<<stu[i].math<<'\t'<<stu[i].english<<
  494. '\t'<<stu[i].sum<<'\t'<<stu[i].rank<<endl;
  495. }
  496. getch();
  497. }
  498. }while(flag != 0);
  499. return 0;
  500. }
  501. void cover()
  502. {
  503. cout<<"====================================================================================="<<endl<<"*"
  504. <<" *"<<endl<<"*"
  505. <<" *"<<endl<<"*"
  506. <<" *"<<endl<<"*"
  507. <<" *"<<endl<<"*"
  508. <<" *"<<endl<<"*"
  509. <<" *"<<endl<<"*"
  510. <<" *"<<endl<<"*"
  511. <<" *"<<endl<<"*"
  512. <<" *"<<endl<<"*"
  513. <<" *"<<endl;
  514. cout<<"* Welcome to the Student Achievement Management System *"<<endl;//欢迎使用学生成绩管理系统
  515. cout<<"* ( 欢 迎 使 用 学 生 成 绩 管 理 系 统 ) *" <<endl;
  516. cout<<"* *"<<endl<<
  517. "* *"<<endl
  518. <<"* *"<<endl
  519. <<"* *"<<endl
  520. <<"* *"<<endl
  521. <<"* *"<<endl
  522. <<"* *"<<endl
  523. <<"* *"<<endl
  524. <<"* *"<<endl
  525. <<"* *"<<endl
  526. <<"* *"<<endl
  527. <<"=====================================================================================";
  528. }
  529. void menu_main()//主页菜单
  530. {
  531. system("cls");
  532. cout<<endl;
  533. cout<<"====================================================================================="<<endl;
  534. cout<<"* The home page menu *"<<endl;
  535. cout<<"====================================================================================="<<endl;
  536. cout<<"* 1 : Add(添加) a new classmate information; *"<<endl;
  537. cout<<"* 2 : Student Achievement Ranking(排名); *"<<endl;
  538. cout<<"* 3 : Inquire(查询) student grades information; *"<<endl;
  539. cout<<"* 4 : Change(修改) student grades information; *"<<endl;
  540. cout<<"* 5 : Delete(删除) student grades information; *"<<endl;
  541. cout<<"* 6 : Display(展示) student information; *"<<endl;
  542. cout<<"* 0 : Pressing '0' : Exit to system ; *"<<endl;
  543. cout<<"====================================================================================="<<endl;
  544. }
  545. void menu_search()//查询菜单
  546. {
  547. system("cls");
  548. cout<<endl;
  549. cout<<"-------------------------------------------------------------------------------------"<<endl;
  550. cout<<"* Inquiry Modes: *"<<endl;
  551. cout<<"-------------------------------------------------------------------------------------"<<endl;
  552. cout<<"* 1:Student number query; *"<<endl;
  553. cout<<"* 2:Name query; *"<<endl;
  554. cout<<"* 3:Total score query; *"<<endl;
  555. cout<<"* 4: Single subject score(单科成绩) query *"<<endl;
  556. cout<<"* and fail statistics(不及格统计); *"<<endl;
  557. cout<<"* 0: Return main menu. *"<<endl;
  558. cout<<"-------------------------------------------------------------------------------------"<<endl;
  559. }
  560. void menu_single()//单科查询
  561. {
  562. system("cls");
  563. cout<<endl;
  564. cout<<"-------------------------------------------------------------------------------------"<<endl;
  565. cout<<"* Subjects area : *"<<endl;
  566. cout<<"-------------------------------------------------------------------------------------"<<endl;
  567. cout<<"* 1: Chinese transcript; *"<<endl;
  568. cout<<"* 2: Math transcript; *"<<endl;
  569. cout<<"* 3: English transcript; *"<<endl;
  570. cout<<"* 0: Return to the parent directory; *"<<endl;
  571. cout<<"* Attention: Press the 1 or 2 or 3 key to select; *"<<endl;
  572. cout<<"-------------------------------------------------------------------------------------"<<endl;
  573. }

注:本程序全部采用面向过程编程,思路和逻辑都属于C语言范畴,但输入输出为了方便都采用了cout,cin等高级语法,读者可自行更改;并且大量提示信息都采用英文书写更显高级感,读者觉得看着不方便也可自行改成中文;最后,谢谢大家的阅读与采纳。

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/weixin_40725706/article/detail/893725
推荐阅读
相关标签
  

闽ICP备14008679号