第1个回答 推荐于2017-11-24
#include<iostream>
#include<cstring>
#include<iomanip>
#include<windows.h>
using namespace std;
//声明抽象类Person类
class Person
{
public:
Person() {};
~Person() {};
virtual void setperson() =0; //纯虚函数输入信息
virtual void getperson() =0; //纯虚函数输出信息
};
//声明学生信息类
class Student:public Person //公有继承
{
public:
Student() {};
~Student() {};
void setnumber(int num){number=num;}
void setname(char *n){strcpy(name,n);}
void setgrade(char *g){strcpy(grade,g);}
int getnumber(){return number;}
char *getname(){return name;}
char *getgrade(){return grade;}
void setstudent() //输入函数
{
cout<<"请输入学生学号:";
cin>>number;
cout<<"请输入学生姓名:";
cin>>name;
cout<<"请输入学生所在班级:";
cin>>grade;
}
private:
char name[20]; //学生姓名
char grade[20]; //学生所在班级
int number; //学生学号
};
//声明成绩类
class Score
{
public:
Score() {};
~Score() {};
void setenglish(float E){english=E;}
void setmath(float M){math=M;}
void setphysics(float P){physics=P;}
void setsports(float S){sports=S;}
void setcomputer(float C){computer=C;}
float getenglish(){return english;}
float getmath(){return math;}
float getphysics(){return physics;}
float getsports(){return sports;}
float getcomputer(){return computer;}
void setscore() //输入函数
{
cout<<"请输入英语成绩:";
cin>>english;
cout<<"请输入数学成绩:";
cin>>math;
cout<<"请输入物理成绩:";
cin>>physics;
cout<<"请输入体育成绩:";
cin>>sports;
cout<<"请输入C++成绩:";
cin>>computer;
}
float total(); //计算学分绩
private:
float english;
float math;
float physics;
float sports;
float computer;
};
float Score::total()
{ float zong;
zong=english*2+math*4+physics*4+sports*1+computer*3;
return zong/14.0;
}
//声明学生成绩信息类
class stuscore:public Student,public Score //多重继承
{
public:
stuscore() {};
~stuscore() {};
void setstuscore(); //输入学生成绩信息
void printf1(){cout<<" "<<getnumber()<<" "<<getname()<<" "<<getenglish();}
void printf2(){cout<<" "<<getnumber()<<" "<<getname()<<" "<<getmath();}
void printf3(){cout<<" "<<getnumber()<<" "<<getname()<<" "<<getphysics();}
void prinft4(){cout<<" "<<getnumber()<<" "<<getname()<<" "<<getsports();}
void printf5(){cout<<" "<<getnumber()<<" "<<getname()<<" "<<getcomputer();}
void print()
{
cout<<" "<<getnumber()<<" "<<getname()<<" "<<getenglish()<<" "<<getmath()<<" "<<getphysics()<<" "<<getsports()<<" "<<getcomputer()<<endl;
}
};
void stuscore::setstuscore() //定义输入函数
{
setstudent();
setscore();
}
void menu();
int func1(stuscore stusco[]);
void func2(stuscore stusco[],int m);
void func3(stuscore stusco[],int m);
void func4(stuscore stusco[],int m);
void func5(stuscore stusco[],int m);
int i=-1;
int f;
int number;
char name[20];
float english;
float math;
float physics;
float sports;
float computer;
//主函数
void main()
{
stuscore stusco[20];
int n;
menu();
cout<<"请输入1~7之间的数字"<<endl;
cout<<"请输入菜单选项:";
cin>>n;
while(1)
{
switch(n)
{
case 1:f=func1(stusco);break;
case 2:func2(stusco,f);break;
case 3:func3(stusco,f);break;
case 4:func4(stusco,f);break;
case 5:func5(stusco,f);break;
case 7:exit(0);
}
}
}
//主菜单函数
void menu()
{
system("color D");
cout<<"欢迎进入学生成绩管理系统!"<<endl;
cout<<"*********************************************************"<<endl;
cout<<"-------------------学生成绩管理系统----------------------"<<endl;
cout<<"*********************************************************"<<endl;
cout<<"* 1. 学生成绩录入 *"<<endl;
cout<<"* 2. 学生成绩查询 *"<<endl;
cout<<"* 3. 学生成绩修改 *"<<endl;
cout<<"* 4. 单科所有学生成绩查询 *"<<endl;
cout<<"* 5. 单科成绩统计 *"<<endl;
cout<<"* (平均成绩及各个成绩区间所占比例) *"<<endl;
cout<<"* 6. 学生总成绩排名 *"<<endl;
cout<<"* 7. 退出系统 *"<<endl;
cout<<endl;
}
//录入成绩函数
int func1(stuscore stusco[])
{ char p;
do{
i++;
stusco[i].setstuscore();
cout<<"输入成功!";
cout<<"是否还要继续输入(继续输入请按y,退出请按n):"<<endl;
cin>>p;
}while(p=='y');
return i+1;
}
//查询成绩函数
void func2(stuscore stusco[])
{
int k;
cout<<"--------[1] 按姓名查询------------"<<endl;
cout<<"--------[2] 按学号查询------------"<<endl;
cout<<"请输入查询方式(1或2):";
cin>>k;
if(k==1)
{
char n='y';
int u[10];
while(n=='y')
{
int j=0;
cout<<"请输入要查询的学生姓名:";
cin>>name;
int t=0;
for(;t<f;t++)
if(strcmp(name,stusco[t].getname())==0)
{ u[j]=t;
j++;
}
if(j==0)
{ cout<<"没有你要查询的学生名字!";//没有找到
cout<<"是否退出?退出请按n"<<endl;
cin>>n;
}
for(int b=0;b<j;b++)
{
if(j<2)
{
t=u[b];
cout<<" 学号"<<" 姓名"<<" 英语"<<" 数学"<<" 物理"<<" 体育"<<" C++ "<<" 学分绩"<<endl;
cout<<" "<<stusco[t].getnumber()<<" "<<stusco[t].getname()<<" "<<stusco[t].getenglish()<<" "<<stusco[t].getmath()
<<" "<<stusco[t].getphysics()<<" "<<stusco[t].getsports()<<" "<<stusco[t].getcomputer()<<" "<<stusco[t].total()<<endl;
cout<<"是否继续查询(继续请按y,退出按n):"<<endl;
cin>>n;
}
else
{
t=u[b];
}
}
}
}
if(k==2)
{
char n='y';
while(n=='y')
{
int j=0;
cout<<"请输入要查询的学生的学号:";
cin>>number;
int t=0;
for(;t<f;t++)
{
if(number==stusco[t].getnumber())
{
cout<<" 学号"<<" 姓名"<<" 英语"<<" 数学"<<" 物理"<<" 体育"<<" C++ "<<" 学分绩"<<endl;
cout<<" "<<stusco[t].getnumber()<<" "<<stusco[t].getname()<<" "<<stusco[t].getenglish()<<" "<<stusco[t].getmath()
<<" "<<stusco[t].getphysics()<<" "<<stusco[t].getsports()<<" "<<stusco[t].getcomputer()<<" "<<stusco[t].total()<<endl;
cout<<"是否继续查询(继续请按y,退出按n):"<<endl;
cin>>n;
}
else
{ cout<<"没有你要查询的学生!";
cout<<"是否退出?退出请按n"<<endl;
cin>>n;
}
}
}
}
}
//修改信息函数
void func3(stuscore stusco[],int m)
{
int j=0,b[20],r;
int flag;
char n='y';
while(n=='y')
{
cout<<"请输入要修改成绩的学生学号:";
cin>>number;
flag=0;
int d;
for(int t=0;t<m;t++)
if(number==stusco[t].getnumber())
do{
b[j]=t;
cout<<"请选择要修改的信息:"<<endl;
cout<<"1.修改英语成绩"<<endl;
cout<<"2.修改数学成绩"<<endl;
cout<<"3.修改物理成绩"<<endl;
cout<<"4.修改体育成绩"<<endl;
cout<<"5.修改C++成绩"<<endl;
cout<<"请选择1~5之间的数字:";
cin>>d;
if(d==1)
{
cout<<"请输入新的英语成绩:";
cin>>english;
stusco[t].setenglish(english);
}
else if(d==2)
{
cout<<"请输入新的数学成绩:";
cin>>math;
stusco[t].setmath(math);
}
else if(d==3)
{
cout<<"请输入新的物理成绩:";
cin>>physics;
stusco[t].setphysics(physics);
}
else if(d==4)
{
cout<<"请输入新的体育成绩:";
cin>>sports;
stusco[t].setsports(sports);
}
else if(d==5)
{
cout<<"请输入新的C++成绩:";
cin>>computer;
stusco[t].setcomputer(computer);
}
flag=1;
j++;
}while(d<1||d>5);
if(flag==0)
{
cout<<"没有您要找的学生!"<<endl;
cout<<"请重新输入(退出请按n)";
cin>>n;
}
else
{
cout<<"是否继续修改(继续请按y,退出请按n):";
cin>>n;
}
}
cout<<"修改后的学生成绩:"<<endl;
cout<<" 学号姓名英语数学物理体育C++ "<<endl;
for(int t=0;t<j;t++)
{
r=b[t];
stusco[r].print();
}
}
//单科所有学生成绩查询
void func4(stuscore stusco[],int m)
{
int k;
char n='y';
while(n=='y')
{
cout<<"1.英语"<<endl;
cout<<"2.数学"<<endl;
cout<<"3.物理"<<endl;
cout<<"4.体育"<<endl;
cout<<"5.C++"<<endl;
cout<<endl;
cout<<"请输入1~5之间的数字选择查询的科目:";
cin>>k;
if(k==1)
{
for(int t=0;t<m;t++)
stusco[t].printf1();
}
else if(k==2)
{
for(int t=0;t<m;t++)
stusco[t].printf2();
}
else if(k==3)
{
for(int t=0;t<m;t++)
stusco[t].printf3();
}
else if(k==4)
{
for(int t=0;t<m;t++)
stusco[t].prinft4();
}
else if(k==5)
{
for(int t=0;t<m;t++)
stusco[t].printf5();
}
cout<<"是否继续查询?(继续请是按y,退出请按n):";
cin>>n;
}
}
void func5(stuscore stusco[],int m)
{
int k;
float excellence;
float well;
float pass;
float fail;
int exc=0,wel=0,pas=0,fai=0;
cout<<"1.英语"<<endl;
cout<<"2.数学"<<endl;
cout<<"3.物理"<<endl;
cout<<"4.体育"<<endl;
cout<<"5.C++"<<endl;
cout<<endl;
cout<<"请输入1~5之间的数字选择需要统计的科目:";
cin>>k;
if(k==1)
{
for(int t=0;t<m;t++)
{if(stusco[t].getenglish()>=85) ++exc;
else if(stusco[t].getenglish()>=70) ++wel;
else if(stusco[t].getenglish()>=60) ++pas;
else if(stusco[t].getenglish()<60) ++fai;
}
excellence=exc/m;
well=wel/m;
pass=pas/m;
fail=fai/m;
cout<<"英语成绩统计结果为"<<endl;
cout<<"优秀率:"<<excellence<<endl;
cout<<"良好率:"<<well<<endl;
cout<<"及格率:"<<pass<<endl;
cout<<"不及格率:"<<fail<<endl;
}
else if(k==2)
{
for(int t=0;t<m;t++)
{if(stusco[t].getmath()>=85) ++exc;
else if(stusco[t].getmath()>=70) ++wel;
else if(stusco[t].getmath()>=60) ++pas;
else if(stusco[t].getmath()<60) ++fai;
}
excellence=exc/m;
well=wel/m;
pass=pas/m;
fail=fai/m;
cout<<"数学成绩统计结果为"<<endl;
cout<<"优秀率:"<<excellence<<endl;
cout<<"良好率:"<<well<<endl;
cout<<"及格率:"<<pass<<endl;
cout<<"不及格率:"<<fail<<endl;
}
else if(k==3)
{
for(int t=0;t<m;t++)
{if(stuscco[t].getphysics()>=85) ++exc;
else if(stusco[t].getphysics()>=70) ++wel;
else if(stusco[t].getphysics()>=60) ++pas;
else if(stusco[t].getphysics()<60) ++fai;
}
excellence=exc/m;
well=wel/m;
pass=pas/m;
fail=fai/m;
cout<<"物理成绩统计结果为"<<endl;
cout<<"优秀率:"<<excellence<<endl;
cout<<"良好率:"<<well<<endl;
cout<<"及格率:"<<pass<<endl;
cout<<"不及格率:"<<fail<<endl;
}
else if(k==4)
{
for(int t=0;t<m;t++)
{if(stuscco[t].getsports()>=85) ++exc;
else if(stusco[t].getsports()>=70) ++wel;
else if(stusco[t].getsports()>=60) ++pas;
else if(stusco[t].getsports()<60) ++fai;
}
excellence=exc/m;
well=wel/m;
pass=pas/m;
fail=fai/m;
cout<<"体育成绩统计结果为"<<endl;
cout<<"优秀率:"<<excellence<<endl;
cout<<"良好率:"<<well<<endl;
cout<<"及格率:"<<pass<<endl;
cout<<"不及格率:"<<fail<<endl;
}
else if(k==5)
{
for(int t=0;t<m;t++)
{if(stuscco[t].getcomputer()>=85) ++exc;
else if(stusco[t].getcomputer()>=70) ++wel;
else if(stusco[t].getcomputer()>=60) ++pas;
else if(stusco[t].getcomputer()<60) ++fai;
}
excellence=exc/m;
well=wel/m;
pass=pas/m;
fail=fai/m;
cout<<"C++成绩统计结果为"<<endl;
cout<<"优秀率:"<<excellence<<endl;
cout<<"良好率:"<<well<<endl;
cout<<"及格率:"<<pass<<endl;
cout<<"不及格率:"<<fail<<endl;
}
}本回答被提问者和网友采纳