C++学生信息管理系统V1(课后作业)

  1. #include <iostream>
  2. #include <cstring>
  3. #include <bits/stdc++.h>//C++万能头文件
  4. #include <algorithm>
  5. #include <cstdlib>
  6. using namespace std;
  7. int a,j;//j表学生数量,a计数
  8. void menu()
  9. {
  10. cout<<"============================"<<endl;
  11. cout<<"|"<<" 学生管理系统V1_By李康 "<<"|"<<endl;
  12. cout<<"|"<<" 1:增加学生信息 "<<"|"<<endl;
  13. cout<<"|"<<" 2:删除学生信息 "<<"|"<<endl;
  14. cout<<"|"<<" 3:查找学生信息 "<<"|"<<endl;
  15. cout<<"|"<<" 4:修改学生信息 "<<"|"<<endl;
  16. cout<<"|"<<" 5:对学生信息排序 "<<"|"<<endl;
  17. cout<<"|"<<" 6:显示学生的信息 "<<"|"<<endl;
  18. cout<<"|"<<" 0:退出程序 "<<"|"<<endl;
  19. cout<<"============================"<<endl;
  20. cout<<"请输入:"<<endl;
  21. }
  22. class Stu{
  23. public:
  24. void add();
  25. void delect();
  26. void look();
  27. void change();
  28. void show();
  29. void sort();
  30. private:
  31. long long num;
  32. char name[100];
  33. char sex[50];
  34. float score;
  35. }st[101];
  36. void Stu::add(){
  37. //int j;
  38. cout<<"输入学生人数:";
  39. cin>>j;
  40. cout<<"请依次输入学生的姓名,学号,性别和成绩^_^"<<endl;
  41. for(a=0;a<j;a++)
  42. {
  43. cin>>st[a].name>>st[a].num>>st[a].sex>>st[a].score;
  44. }
  45. cout<<"输入完毕!"<<endl;
  46. }
  47. void Stu::delect(){
  48. string str;
  49. int b;
  50. cout<<"输入要删除的学生姓名:"<<endl;
  51. cin>>str;
  52. for(a=0;a<j;a++)
  53. {
  54. if(str==st[a].name) b=a;
  55. break;
  56. }
  57. for(int m=b+1;m<j;j++)
  58. st[m-1]=st[m];
  59. cout<<"已成功删除!"<<endl;
  60. j-=1;//学生减少一个
  61. }
  62. void Stu::look(){
  63. cout<<"请输入要查找学生的学号:"<<endl;
  64. int x,k=0;
  65. cin>>x;
  66. for(a=0;a<j;a++)
  67. {
  68. if(st[a].num==x)
  69. {
  70. cout<<" "<<st[a].name<<" "<<st[a].num<<" "<<st[a].sex<<" "<<st[a].score<<endl;
  71. k++;break;
  72. }
  73. }
  74. if(k==0) cout<<"Sorry!查无此人..."<<endl;
  75. }
  76. void Stu::change(){
  77. int q,choi;
  78. char nname[50],nsex[50];
  79. float nscore;
  80. cout<<"请输入要修改的同学的学号:"<<endl;
  81. cin>>q;
  82. for(a=0;a<j;a++)
  83. {
  84. if(q==st[a].num) break;
  85. }
  86. cout<<"请选择:"<<endl;
  87. cout<<"1:修改姓名"<<endl<<"2:修改性别"<<endl<<"3:修改成绩"<<endl;
  88. cin>>choi;
  89. if(choi==1)
  90. {
  91. cout<<"请输入修改后的姓名:";
  92. cin>>nname;
  93. strcpy(st[a].name,nname);
  94. }
  95. else if(choi==2)
  96. {
  97. cout<<"请输入修改后的性别:";
  98. cin>>nsex;
  99. strcpy(st[a].sex,nsex);
  100. //st[a].sex=nsex;
  101. }
  102. else if(choi==3)
  103. {
  104. cout<<"请输入修改后的成绩:";
  105. cin>>nscore;
  106. st[a].score=nscore;
  107. }
  108. cout<<"已成功修改信息!"<<endl;
  109. }
  110. void Stu::show(){
  111. cout<<"结果为:"<<endl;
  112. for(a=0;a<j;a++)
  113. {
  114. cout<<st[a].name<<" "<<st[a].num<<" "<<st[a].sex<<" "<<st[a].score<<endl;
  115. }
  116. }
  117. void Stu::sort(){
  118. cout<<"程序正在以成绩进行排序,请稍等..."<<endl;
  119. cout<<"排序出错!该功能将在下一版本中更新^_^"<<endl;
  120. }
  121.  
  122. int main()
  123. {
  124. int i,n;
  125. Stu student;
  126. while(1)
  127. {
  128. i=0;
  129. menu();
  130. cin>>n;
  131. switch(n)
  132. {
  133. case 1:
  134. student.add();break;
  135. case 2:
  136. student.delect();
  137. student.show();
  138. break;
  139. case 3:
  140. student.look();break;
  141. case 4:
  142. student.change();
  143. student.show();
  144. break;
  145. case 5:
  146. student.sort();break;
  147. case 6:
  148. student.show();break;
  149. case 0:
  150. i=1;break;
  151. default:
  152. cout<<"请输入0-5的数字!"<<endl;
  153. }
  154. if(i==1) break;
  155. cout<<"按任意键返回菜单!"<<endl;
  156. getchar();
  157. getchar();
  158. system("cls");
  159. }
  160. return 0;
  161. }
posted @ 2018-03-24 21:09  外号班长  阅读(177)  评论(0编辑  收藏  举报