- #include
<iostream>
- #include
<cstring>
- #include
<bits/stdc++.h>//C++万能头文件
- #include
<algorithm>
- #include
<cstdlib>
- using
namespace std;
- int a,j;//j表学生数量,a计数
- void menu()
- {
- cout<<"============================"<<endl;
- cout<<"|"<<"
学生管理系统V1_By李康 "<<"|"<<endl;
- cout<<"|"<<"
1:增加学生信息 "<<"|"<<endl;
- cout<<"|"<<"
2:删除学生信息 "<<"|"<<endl;
- cout<<"|"<<"
3:查找学生信息 "<<"|"<<endl;
- cout<<"|"<<"
4:修改学生信息 "<<"|"<<endl;
- cout<<"|"<<"
5:对学生信息排序 "<<"|"<<endl;
- cout<<"|"<<"
6:显示学生的信息 "<<"|"<<endl;
- cout<<"|"<<"
0:退出程序 "<<"|"<<endl;
- cout<<"============================"<<endl;
- cout<<"请输入:"<<endl;
- }
- class
Stu{
- public:
- void add();
- void delect();
- void look();
- void change();
- void show();
- void sort();
- private:
- long
long num;
- char name[100];
- char sex[50];
- float score;
- }st[101];
- void
Stu::add(){
- //int j;
- cout<<"输入学生人数:";
- cin>>j;
- cout<<"请依次输入学生的姓名,学号,性别和成绩^_^"<<endl;
- for(a=0;a<j;a++)
- {
- cin>>st[a].name>>st[a].num>>st[a].sex>>st[a].score;
- }
- cout<<"输入完毕!"<<endl;
- }
- void
Stu::delect(){
- string str;
- int b;
- cout<<"输入要删除的学生姓名:"<<endl;
- cin>>str;
- for(a=0;a<j;a++)
- {
- if(str==st[a].name)
b=a;
- break;
- }
- for(int
m=b+1;m<j;j++)
- st[m-1]=st[m];
- cout<<"已成功删除!"<<endl;
- j-=1;//学生减少一个
- }
- void
Stu::look(){
- cout<<"请输入要查找学生的学号:"<<endl;
- int x,k=0;
- cin>>x;
- for(a=0;a<j;a++)
- {
- if(st[a].num==x)
- {
- cout<<" "<<st[a].name<<"
"<<st[a].num<<"
"<<st[a].sex<<"
"<<st[a].score<<endl;
- k++;break;
- }
- }
- if(k==0)
cout<<"Sorry!查无此人..."<<endl;
- }
- void
Stu::change(){
- int q,choi;
- char nname[50],nsex[50];
- float nscore;
- cout<<"请输入要修改的同学的学号:"<<endl;
- cin>>q;
- for(a=0;a<j;a++)
- {
- if(q==st[a].num)
break;
- }
- cout<<"请选择:"<<endl;
- cout<<"1:修改姓名"<<endl<<"2:修改性别"<<endl<<"3:修改成绩"<<endl;
- cin>>choi;
- if(choi==1)
- {
- cout<<"请输入修改后的姓名:";
- cin>>nname;
- strcpy(st[a].name,nname);
- }
- else
if(choi==2)
- {
- cout<<"请输入修改后的性别:";
- cin>>nsex;
- strcpy(st[a].sex,nsex);
- //st[a].sex=nsex;
- }
- else
if(choi==3)
- {
- cout<<"请输入修改后的成绩:";
- cin>>nscore;
- st[a].score=nscore;
- }
- cout<<"已成功修改信息!"<<endl;
- }
- void
Stu::show(){
- cout<<"结果为:"<<endl;
- for(a=0;a<j;a++)
- {
- cout<<st[a].name<<"
"<<st[a].num<<"
"<<st[a].sex<<"
"<<st[a].score<<endl;
- }
- }
- void
Stu::sort(){
- cout<<"程序正在以成绩进行排序,请稍等..."<<endl;
- cout<<"排序出错!该功能将在下一版本中更新^_^"<<endl;
- }
-
- int main()
- {
- int i,n;
- Stu student;
- while(1)
- {
- i=0;
- menu();
- cin>>n;
- switch(n)
- {
- case
1:
- student.add();break;
- case
2:
- student.delect();
- student.show();
- break;
- case
3:
- student.look();break;
- case
4:
- student.change();
- student.show();
- break;
- case
5:
- student.sort();break;
- case
6:
- student.show();break;
- case
0:
- i=1;break;
- default:
- cout<<"请输入0-5的数字!"<<endl;
- }
- if(i==1)
break;
- cout<<"按任意键返回菜单!"<<endl;
- getchar();
- getchar();
- system("cls");
- }
- return
0;
- }
posted @
2018-03-24 21:09
外号班长
阅读(
177)
评论()
编辑
收藏
举报