- #include<iostream>
- #include<iomanip>
- #include<string>
- using namespace std;
- class student
- {
- int num;
- char name[20];
- char class1[20];
- double chinese;
- double math;
- double english;
- double youxiu;//优秀率
- double bujige;//不及格率
- double sum;//总成绩
- double aver1;//平均成绩
- public:
- void set()
- {
- cout<<"\t学生学号:";
- cin>>num;
- cout<<"\t学生姓名:";
- cin>>name;
- cout<<"\t学生班级:";
- cin>>class1;
- cout<<"\t语文成绩:";
- cin>>chinese;
- cout<<"\t英语成绩:";
- cin>>english;
- cout<<"\t数学成绩:";
- cin>>math;
- }
- void show()
- {
- cout<<"该学生的学号:"<<num<<endl;
- cout<<"该学生的姓名:"<<name<<endl;
- cout<<"该学生的班级:"<<class1<<endl;
- cout<<"该学生的语文成绩:"<<chinese<<endl;
- cout<<"该学生的数学成绩:"<<math<<endl;
- cout<<"该学生的英语成绩:"<<english<<endl;
- }
- double ad(){return sum=chinese+english+math;}
- double aver()
- {
- aver1=(chinese+english+math)/3;
- return aver1;
- }
- friend void show();
- friend void search();
- friend void change();
- friend void add();
- friend void paixu();
- friend void del();
- };
- void input();
- void show();
- void search();
- void change();
- void add();
- void paixu();
- void del();
- student s[100];
- int n=0;
- int main()
- {
- int select;
- while(1)
- {
- system("cls");
- cout<<"\t ******************欢迎使用******************\n";
- cout<<"\t **************学生成绩管理系统**************\n";
- cout<<"\t *------------------------------------------*\n";
- cout<<"\t * 1——录入学生信息 *\n";
- cout<<"\t * 2——显示学生信息 *\n";
- cout<<"\t * 3——查询学生信息 *\n";
- cout<<"\t * 4——修改学生信息 *\n";
- cout<<"\t * 5——添加学生信息 *\n";
- cout<<"\t * 6——删除学生信息 *\n";
- cout<<"\t * 0——退出 *\n";
- cout<<"\t *------------------------------------------*\n";
- cout<<"\t 你要输入的编号是(0--6):";
- cin>>select;
- if(select==0) break;
- switch(select){
- case 1:
- input(); //调用input函数录入数据
- system("pause");
- break;
- case 2:
- show(); //调用show函数显示学生信息
- system("pause");
- break;
- case 3:
- search(); //调用search函数查询学生信息
- system("pause");
- break;
- case 4:
- change(); //调用change函数修改学生信息
- system("pause");
- break;
- case 5:
- add(); //调用add函数添加学生信息
- system("pause");
- break;
- case 6:
- paixu(); //调用add函数添加学生信息
- system("pause");
- break;
- case 7:
- del(); // 调用del函数删除学生信息
- system("pause");
- break;
- system("pause");
- default:
- cout<<"没有此选项,请重新选择!"<<endl;
- }
- }
- return 0;
- }
- void input() //录入学生信息的函数
- {
- char sel;
- do
- {
- n++;
- cout<<"\t请输入第"<<n<<"个学生信息:\t"<<endl;
- s[n].set();
- cout<<"是否要继续录入学生信息(Y/N):";
- cin>>sel;
- }while(sel=='Y' || sel=='y' );
- }
- void show()
- {
- cout<<left; //设置输出左对齐
- cout<<setw(10)<<"学生学号"
- <<setw(10)<<"学生姓名"
- <<setw(13)<<"学生班级"
- <<setw(12)<<"语文成绩"
- <<setw(12)<<"数学成绩"
- <<setw(12)<<"英语成绩"
- <<endl;
- for(int i=1;i<=n;i++)
- {
- cout<<setw(10)<<s[i].num
- <<setw(10)<<s[i].name
- <<setw(13)<<s[i].class1
- <<setw(12)<<s[i].chinese
- <<setw(12)<<s[i].math
- <<setw(12)<<s[i].english<<endl;
- }
- cout<<endl;
- }
- void search()//查询
- {
- int a,b,i;char c[20];
- cout<<"请选择查询方式:"<<endl;
- cout<<"按学生姓名查询请按1"<<endl;
- cout<<"按学生学号查询请按2"<<endl;
- cin>>a;
- switch(a)
- {
- case 1:
- {char sel;
- do{
- cout<<"请输入你要查的学生的姓名:"<<endl;
- cin>>c;
- for(i=1;i<=n;i++)
- if(strcmp(s[i].name,c)==0)
- {cout<<"你要查的学生信息为:"<<endl;
- cout<<"学生学号:"<<s[i].num<<endl<<"学生姓名:"
- <<s[i].name<<endl<<"学生班级:"
- <<s[i].class1<<endl<<"语文成绩:"
- <<s[i].chinese<<endl<<"数学成绩:"
- <<s[i].math<<endl<<"英语成绩:"
- <<s[i].english<<endl;
- break;
- }
- else if(strcmp(s[i].name,c)!=0&&i==n)
- {cout<<"没有这个学生!"<<endl;break;}
- cout<<"是否要继续查询学生信息(Y/N):";
- cin>>sel;
- }while(sel=='Y' || sel=='y' );
- break;
- }
- case 2:
- { char sel;
- do{
- cout<<"请输入你要查的学生的学号:"<<endl;
- cin>>b;
- for(i=1;i<=n;i++)
- if(s[i].num==b)
- {
- cout<<"你要查的学生信息为:"<<endl;
- cout<<"学生学号:"<<s[i].num<<endl<<"学生姓名:"
- <<s[i].name<<endl<<"学生班级:"
- <<s[i].class1<<endl<<"语文成绩:"
- <<s[i].chinese<<endl<<"数学成绩:"
- <<s[i].math<<endl<<"英语成绩:"
- <<s[i].english<<endl;
- break;
- }
- else if(s[i].num!=b&&i==n)
- {cout<<"没有这个学生!请核对后再输入!"<<endl;break;}
- cout<<"是否要继续查询学生信息(Y/N):";
- cin>>sel;
- }while(sel=='Y' || sel=='y' );
- break;}
- default:
- cout<<"您的输入有误!"<<endl;
- }
- }
- void change()
- {
- { char sel;
- int d,i,e,f,g=0;
- do{
- cout<<"请输入你要修改的学生的学号:"<<endl;
- cin>>d;
- for(i=1;i<=n;i++)
- if(s[i].num==d)
- {
- cout<<"你要修改的学生信息为:"<<endl;
- cout<<"学生学号:"<<s[i].num<<endl<<"学生姓名:"
- <<s[i].name<<endl<<"学生班级:"
- <<s[i].class1<<endl<<"语文成绩:"
- <<s[i].chinese<<endl<<"数学成绩:"
- <<s[i].math<<endl<<"英语成绩:"
- <<s[i].english<<endl;
- e=1;
- break;
- }
- else if(s[i].num!=d&&i==n)
- {cout<<"没有这个学生!请核对后再输入!"<<endl;
- e=0;break;}
- while(e==1)
- { {cout<<"请输入该学生要修改的信息对应的数字:"<<endl;
- cout<<"学生学号:1"
- <<'\t'<<"学生姓名:2"
- <<'\t'<<"学生班级:3"
- <<'\t'<<"语文成绩:4"
- <<'\t'<<"数学成绩:5"
- <<'\t'<<"英语成绩:6"<<endl;
- }
- cin>>f;
- switch(f)
- {case 1:cout<<"\t新的学生学号为:";
- cin>>s[i].num;break;
- case 2:cout<<"\t新的学生姓名为:";
- cin>>s[i].name;break;
- case 3:cout<<"\t新的学生班级为:";
- cin>>s[i].class1;break;
- case 4:cout<<"\t新的语文成绩为:";
- cin>>s[i].chinese;break;
- case 5:cout<<"\t新的数学成绩为:";
- cin>>s[i].math;break;
- case 6:cout<<"\t新的英语成绩为:";
- cin>>s[i].english;break;
- default:cout<<"您的输入有误,请重新输入!";
- cin>>f;}
- e=0;
- g=1;
- }
- if(g==1)
- { cout<<"修改成功!";}
- cout<<"是否要继续修改学生信息(Y/N):";
- cin>>sel;
- }while(sel=='Y' || sel=='y' );
- }
- }
- void add()
- {
- char sel;
- do
- {
- n++;
- cout<<"\n请输入第"<< n <<"个学生信息:\n";
- cout<<"\t学生学号:";
- cin>>s[n].num;
- cout<<"\t学生姓名:";
- cin>>s[n].name;
- cout<<"\t学生班级:";
- cin>>s[n].class1;
- cout<<"\t语文成绩:";
- cin>>s[n].chinese;
- cout<<"\t数学成绩:";
- cin>>s[n].math;
- cout<<"\t英语成绩:";
- cin>>s[n].english;
- cout<<"是否要继续添加学生信息(Y/N):";
- cin>>sel;
- }while(sel=='Y' || sel=='y' );
- }
- void del()
- {
- int j,i,k;char c[10],sel,y;
- do{
- cout<<"请输入你要删除的学生的姓名:"<<endl;
- cin>>c;
- for(i=1;i<=n;i++)
- if(strcmp(s[i].name,c)==0)
- {cout<<"你要删除的学生信息为:"<<endl;
- cout<<"学生学号:"<<s[i].num<<endl
- <<"学生姓名:"<<s[i].name<<endl
- <<"学生班级:"<<s[i].class1<<endl
- <<"语文成绩:"<<s[i].chinese<<endl
- <<"数学成绩:"<<s[i].math<<endl
- <<"英语成绩:"<<s[i].english<<endl;
- cout<<"确认删除?(y/n):";
- cin>>y;
- if(y=='Y'||y=='y')
- {
- for(j=i;j<=n+1;j++)
- {
- s[j]=s[j+1];
- } k=1;
- }
- else
- cout<<"删除失败!"<<endl;
- break;
- }
- else if(strcmp(s[i].name,c)!=0&&i==n)
- {cout<<"没有这个学生!请核对后再输入!"<<endl;
- k=0;break;}
- while(k==1)
- {
- if(y=='Y'||y=='y')
- cout<<"删除成功!";
- n--;
- k=0;
- }
- cout<<"是否要继续删除学生信息(Y/N):";
- cin>>sel;
- }while(sel=='Y' || sel=='y' );
- }
课程设计
最新推荐文章于 2024-03-12 12:49:14 发布