
帮忙用C++编写一个学生成绩管理系统,拜托啦~~~
主要功能:(1)能按学期、按班级完成对学生成绩的录入、修改(2)能按班级统计学生的成绩,求学生的总分及平均分,并能根据学生的平均成绩进行排序(3)能查询学生成绩,不及格科...
主要功能:
(1)能按学期、按班级完成对学生成绩的录入、修改
(2)能按班级统计学生的成绩,求学生的总分及平均分,并能根据学生的平均成绩进行排序
(3)能查询学生成绩,不及格科目及学生名单
(4)能按班级输出学生的成绩单 展开
(1)能按学期、按班级完成对学生成绩的录入、修改
(2)能按班级统计学生的成绩,求学生的总分及平均分,并能根据学生的平均成绩进行排序
(3)能查询学生成绩,不及格科目及学生名单
(4)能按班级输出学生的成绩单 展开
展开全部
/***************************student头文件***************************************/
#ifndef _STUDENT_H_
#define _STUDENT_H_
#include<string>
using namespace std;
class CStudent
{
private:
string strName;
double chinese;
double english;
double math;
public:
CStudent();
CStudent(string Name,double c,double m,double e);
CStudent operator+(CStudent s);
friend ostream &operator<<(ostream&out,CStudent s)
/* {
out<<s.strName<<"("<<s.chinese<<","<<s.math<<","<<s.english<<")"<<endl;
return out;
}*/
void SetChinese(double a);
void SetMath(double a);
void SetEnglish(double a);
string returnName();
double returnChinese();
double returnEnglish();
double returnMath();
double returnTotalPerformance();
double returnAverage();
~CStudent(){}
};
#endif
/**************************student源文件*********************************/
#include<iostream>
#include "student.h"
using namespace std;
CStudent::CStudent()
{
strName="General Student";
chinese=0;
math=0;
english=0;
}
CStudent::CStudent(std::string Name,double m,double c,double e)
{
strName=Name;
math=m;
chinese=c;
english=e;
}
CStudent CStudent::operator + (CStudent s)
{
CStudent temp;
temp.strName="Total Performance";
temp.chinese=this->chinese+s.chinese;
temp.math=this->math+s.math;
temp.english=this->english+s.english;
return temp;
}
ostream &operator<<(ostream&out,CStudent s)
{
out<<s.strName<<"("<<s.chinese<<","<<s.math<<","<<s.english<<")"<<endl;
return out;
}
void CStudent::SetChinese(double a)
{
chinese=a;
}
void CStudent::SetEnglish(double a)
{
english=a;
}
void CStudent::SetMath(double a)
{
math=a;
}
double CStudent::returnChinese(){return chinese;}
double CStudent::returnEnglish(){return english;}
double CStudent::returnMath(){return math;}
double CStudent::returnTotalPerformance(){return chinese+english+math;}
double CStudent::returnAverage(){return (chinese+english+math)/3;}
string CStudent::returnName(){return strName;}
/*************************main函数****************************/
#include<iostream>
#include "student.h"
using namespace std;
int main()
{
CStudent student1("XiaoMing",50,80,98);
CStudent student2("XiaoHua",70,78,68);
CStudent student3("NingJian",89,78,83);
cout<<student1<<endl;
cout<<student2<<endl;
cout<<student3<<endl;
student1.SetChinese(56);
student1.SetEnglish(87);
student1.SetMath(87);
//计算不同学生学科的总成绩
CStudent General;
General=student1+student2+student3;
cout<<General;
//查看多人各科目的平均成绩
cout<<"Average of Chinese :"<<General.returnChinese()/3
<<"\nAverage of Math :"<<General.returnMath()/3
<<"\nAverage of English :"<<General.returnEnglish()/3<<endl;
//查看个人平均成绩
cout<<"Average of students : \n";
cout<<student1.returnName()<<" : "<<student1.returnAverage()<<endl;
cout<<student2.returnName()<<" : "<<student2.returnAverage()<<endl;
cout<<student3.returnName()<<" : "<<student3.returnAverage()<<endl;
//查看个人总成绩
cout<<"Total of students : \n";
cout<<student1.returnName()<<" : "<<student1.returnTotalPerformance()<<endl;
cout<<student2.returnName()<<" : "<<student2.returnTotalPerformance()<<endl;
cout<<student3.returnName()<<" : "<<student3.returnTotalPerformance()<<endl;
cin.get();
return 0;
}
楼主给分吧
#ifndef _STUDENT_H_
#define _STUDENT_H_
#include<string>
using namespace std;
class CStudent
{
private:
string strName;
double chinese;
double english;
double math;
public:
CStudent();
CStudent(string Name,double c,double m,double e);
CStudent operator+(CStudent s);
friend ostream &operator<<(ostream&out,CStudent s)
/* {
out<<s.strName<<"("<<s.chinese<<","<<s.math<<","<<s.english<<")"<<endl;
return out;
}*/
void SetChinese(double a);
void SetMath(double a);
void SetEnglish(double a);
string returnName();
double returnChinese();
double returnEnglish();
double returnMath();
double returnTotalPerformance();
double returnAverage();
~CStudent(){}
};
#endif
/**************************student源文件*********************************/
#include<iostream>
#include "student.h"
using namespace std;
CStudent::CStudent()
{
strName="General Student";
chinese=0;
math=0;
english=0;
}
CStudent::CStudent(std::string Name,double m,double c,double e)
{
strName=Name;
math=m;
chinese=c;
english=e;
}
CStudent CStudent::operator + (CStudent s)
{
CStudent temp;
temp.strName="Total Performance";
temp.chinese=this->chinese+s.chinese;
temp.math=this->math+s.math;
temp.english=this->english+s.english;
return temp;
}
ostream &operator<<(ostream&out,CStudent s)
{
out<<s.strName<<"("<<s.chinese<<","<<s.math<<","<<s.english<<")"<<endl;
return out;
}
void CStudent::SetChinese(double a)
{
chinese=a;
}
void CStudent::SetEnglish(double a)
{
english=a;
}
void CStudent::SetMath(double a)
{
math=a;
}
double CStudent::returnChinese(){return chinese;}
double CStudent::returnEnglish(){return english;}
double CStudent::returnMath(){return math;}
double CStudent::returnTotalPerformance(){return chinese+english+math;}
double CStudent::returnAverage(){return (chinese+english+math)/3;}
string CStudent::returnName(){return strName;}
/*************************main函数****************************/
#include<iostream>
#include "student.h"
using namespace std;
int main()
{
CStudent student1("XiaoMing",50,80,98);
CStudent student2("XiaoHua",70,78,68);
CStudent student3("NingJian",89,78,83);
cout<<student1<<endl;
cout<<student2<<endl;
cout<<student3<<endl;
student1.SetChinese(56);
student1.SetEnglish(87);
student1.SetMath(87);
//计算不同学生学科的总成绩
CStudent General;
General=student1+student2+student3;
cout<<General;
//查看多人各科目的平均成绩
cout<<"Average of Chinese :"<<General.returnChinese()/3
<<"\nAverage of Math :"<<General.returnMath()/3
<<"\nAverage of English :"<<General.returnEnglish()/3<<endl;
//查看个人平均成绩
cout<<"Average of students : \n";
cout<<student1.returnName()<<" : "<<student1.returnAverage()<<endl;
cout<<student2.returnName()<<" : "<<student2.returnAverage()<<endl;
cout<<student3.returnName()<<" : "<<student3.returnAverage()<<endl;
//查看个人总成绩
cout<<"Total of students : \n";
cout<<student1.returnName()<<" : "<<student1.returnTotalPerformance()<<endl;
cout<<student2.returnName()<<" : "<<student2.returnTotalPerformance()<<endl;
cout<<student3.returnName()<<" : "<<student3.returnTotalPerformance()<<endl;
cin.get();
return 0;
}
楼主给分吧
展开全部
#include<iostream>
#include<string>
#include<fstream>
#include<stdlib.h>
using namespace std;
class Stu
{
public:
char name[8];
int number;
double English,Math,Cjj,Total,Average;
Stu()
{
English=0;
Math=0;
Cjj=0;
Total=0;
Average=0;
strcpy(name,"无");
number=0;
return;
}
~Stu(){}
Stu(double Eng,double Mat,double C,int num,char s3[8]);
void getname();
void getnumber();
void getEnglish();
void getMath();
void getCjj();
double getTotal();
double getAverage();
};
Stu::Stu(double Eng,double Mat,double C,int num,char s3[8])
{
English=Eng;Math=Mat;Cjj=C;number=num;strcpy(name,s3);
}
void Stu::getname()
{
char s[8];
cout<<"名字:";
cin>>s;
strcpy(name,s);
}
void Stu::getnumber()
{
int n;
cout<<"学号:";
cin>>n;
number=n;
}
void Stu::getEnglish()
{
double E;
cout<<"英语:";
cin>>E;
English=E;
}
void Stu::getMath()
{
double m;
cout<<"数学:";
cin>>m;
Math=m;
}
void Stu::getCjj()
{
double c;
cout<<"C++: ";
cin>>c;
Cjj=c;
}
double Stu::getTotal()
{
return Total=English+Math+Cjj;
}
double Stu::getAverage()
{
return Average=Total/3.0;
}
void output1(Stu &p)
{
cout<<"\t\t"<<p.name<<"\t"<<p.number<<"\t"<<p.English<<"\t"<<p.Math<<"\t"<<p.Cjj<<"\n";
}
void output2(Stu &p)
{
cout<<"\t"<<p.name<<"\t"<<p.number<<"\t"<<p.English<<"\t"<<p.Math<<"\t"<<p.Cjj<<"\t"<<p.Average<<"\t"<<p.Total<<"\n";
}
void input(Stu &p)
{
p.getname();
p.getnumber();
p.getEnglish();
p.getMath();
p.getCjj();
p.getTotal();
p.getAverage();
}
void order(Stu &p1,Stu &p2,Stu &p3,Stu &p4,Stu &p5,Stu &p6)
{
sheji:
char *name[6]={p1.name,p2.name,p3.name,p4.name,p5.name,p6.name};
int number[6]={p1.number,p2.number,p3.number,p4.number,p5.number,p6.number};
double English[6]={p1.English,p2.English,p3.English,p4.English,p5.English,p6.English};
double Math[6]={p1.Math,p2.Math,p3.Math,p4.Math,p5.Math,p6.Math};
double Cjj[6]={p1.Cjj,p2.Cjj,p3.Cjj,p4.Cjj,p5.Cjj,p6.Cjj};
double Total[6]={p1.Total,p2.Total,p3.Total,p4.Total,p5.Total,p6.Total};
double Average[6]={p1.Average,p2.Average,p3.Average,p4.Average,p5.Average,p6.Average};
Stu soure[6]={p1,p2,p3,p4,p5,p6};
char *s1,s2[8];
double *p;
int n;
double mat;
cout<<"\t\t主菜单"<<endl;
cout<<"\t1.查询平均分排名;"<<endl;
cout<<"\t2.查询个人情况;"<<endl;
cout<<"\t3.查询各科平均成绩;"<<endl;
cout<<"\t4.输出班级成绩;"<<endl;
cout<<"\t5.修改各人成绩;"<<endl;
cout<<"\t6.查询不及格成绩;"<<endl;
cout<<"\t0.退出;"<<endl;
int q;
cout<<"请选择你要进行的操作:";
cin>>q;
if(q==1)
{
p=Average;
cout<<"\t**********以平均成绩进行排名**********"<<endl;
strcpy(s2,"均分");
for(int i1=1;i1<6;i1++)
{
for(int j1=0;j1<6-i1;j1++)
if(p[j1]<=p[j1+1])
{
mat=p[j1],p[j1]=p[j1+1],p[j1+1]=mat;
s1=name[j1],name[j1]=name[j1+1],name[j1+1]=s1;
n=number[j1],number[j1]=number[j1+1],number[j1+1]=n;
}
}
cout<<"\t\t名次\t姓名\t学号\t"<<s2<<"\n";
for(i1=0;i1<6;i1++)
cout<<"\t\t"<<i1+1<<"\t"<<name[i1]<<"\t"<<number[i1]<<"\t"<<p[i1]<<endl;
cout<<endl;
goto sheji;
}
if(q==2)
{
int w;
cout<<"请输入你要查询的同学的学号:";
cin>>w;
cout<<"\t姓名\t学号\t英语\t数学\tC++\t均分\t总分"<<"\n";
for(int i=0;i<6;i++)
{
if(w==number[i])
output2(soure[i]);
}
goto sheji;
}
else if(q==3)
{
cout<<"\t**********各科平均成绩**********"<<endl;
double a1=0,b=0,d=0,e=0,h=0;
for(int j=0;j<6;j++)
{
a1+=English[j];
}
cout<<"\t英语的平均分为\t"<<(double(a1/5.0))<<endl;
for(int i=0;i<6;i++)
{
b+=Math[i];
}
cout<<"\t数学的平均分为\t"<<(double(b/5.0))<<endl;
for(int k=0;k<6;k++)
{
e+=Cjj[k];
}
cout<<"\tC++的平均分为\t"<<(double(e/5.0))<<endl;
goto sheji;
}
else if(q==4)
{
ofstream file("d:\\student.txt");
if(!file)
{
cout<<"student.txt can't open.\n";
abort();
}
file<<"\t姓名\t学号\t英语\t数学\tC++\t均分\t总分"<<"\n";
for(int i=0;i<6;i++)
{
file<<"\t"<<name[i]<<"\t"<<number[i]<<"\t"<<English[i]<<"\t"<<Math[i]<<"\t"<<Cjj[i]<<"\t"<<Average[i]<<"\t"<<Total[i]<<"\n";
}
file.close();
cout<<"计算机-1的成绩单已输入到了D:\\student.txt中。希望你查看!"<<endl;
goto sheji;
}
else if(q==5)
{
cout<<"\t**********在这里对学生成绩进行修改**********"<<endl;
int b1;
cout<<"请输入你要修改学生的学号:"<<endl;
cin>>b1;
if(b1==p1.number)
{
p1=Stu();
input(p1);
cout<<"\t修改成功!!"<<endl;
}
else if(b1==p2.number)
{
p2=Stu();
input(p2);
cout<<"\t修改成功!!"<<endl;
}
else if(b1==p3.number)
{
p3=Stu();
input(p3);
cout<<"\t修改成功!!"<<endl;
}
else if(b1==p4.number)
{
p4=Stu();
input(p4);
cout<<"\t修改成功!!"<<endl;
}
else if(b1==p5.number)
{
p5=Stu();
input(p5);
cout<<"\t修改成功!!"<<endl;
}
else if(b1==p1.number)
{
p1=Stu();
input(p1);
cout<<"\t修改成功!!"<<endl;
}
else if(b1!=p1.number||b1!=p2.number||b1!=p3.number||b1!=p4.number||b1!=p5.number||b1!=p6.number)
{
cout<<"对不起!该学号不存在!请确认后在输入!"<<endl;
}
goto sheji;
}
else if(q==6)
{
cout<<"**********统计有不及格科目的同学***********"<<endl;
for(int i=0;i<6;i++)
{
if(English[i]<60||Math[i]<60||Cjj[i]<60)
{
cout<<"\t姓名\t学号\t英语\t数学\tC++\t均分\t总分"<<"\n";
output2(soure[i]);
}
}
goto sheji;
}
else if(q==0)
{
cout<<"谢谢你的支持!"<<endl;
exit(1);
}
}
void main()
{
Stu m1,m2,m3,m4,m5,m6;
void Stu::getname();
{
cout<<" ****************欢迎来到成绩管理系统***************"<<endl;
cout<<"请对各学生的成绩进行输入:"<<endl;
input(m1);
input(m2);
input(m3);
input(m4);
input(m5);
input(m6);
cout<<"你输入的是:"<<endl;
cout<<"\t\t姓名\t学号\t英语\t数学\tC++"<<"\n";
output1(m1);
output1(m2);
output1(m3);
output1(m4);
output1(m5);
output1(m6);
order(m1,m2,m3,m4,m5,m6);
}
}
#include<string>
#include<fstream>
#include<stdlib.h>
using namespace std;
class Stu
{
public:
char name[8];
int number;
double English,Math,Cjj,Total,Average;
Stu()
{
English=0;
Math=0;
Cjj=0;
Total=0;
Average=0;
strcpy(name,"无");
number=0;
return;
}
~Stu(){}
Stu(double Eng,double Mat,double C,int num,char s3[8]);
void getname();
void getnumber();
void getEnglish();
void getMath();
void getCjj();
double getTotal();
double getAverage();
};
Stu::Stu(double Eng,double Mat,double C,int num,char s3[8])
{
English=Eng;Math=Mat;Cjj=C;number=num;strcpy(name,s3);
}
void Stu::getname()
{
char s[8];
cout<<"名字:";
cin>>s;
strcpy(name,s);
}
void Stu::getnumber()
{
int n;
cout<<"学号:";
cin>>n;
number=n;
}
void Stu::getEnglish()
{
double E;
cout<<"英语:";
cin>>E;
English=E;
}
void Stu::getMath()
{
double m;
cout<<"数学:";
cin>>m;
Math=m;
}
void Stu::getCjj()
{
double c;
cout<<"C++: ";
cin>>c;
Cjj=c;
}
double Stu::getTotal()
{
return Total=English+Math+Cjj;
}
double Stu::getAverage()
{
return Average=Total/3.0;
}
void output1(Stu &p)
{
cout<<"\t\t"<<p.name<<"\t"<<p.number<<"\t"<<p.English<<"\t"<<p.Math<<"\t"<<p.Cjj<<"\n";
}
void output2(Stu &p)
{
cout<<"\t"<<p.name<<"\t"<<p.number<<"\t"<<p.English<<"\t"<<p.Math<<"\t"<<p.Cjj<<"\t"<<p.Average<<"\t"<<p.Total<<"\n";
}
void input(Stu &p)
{
p.getname();
p.getnumber();
p.getEnglish();
p.getMath();
p.getCjj();
p.getTotal();
p.getAverage();
}
void order(Stu &p1,Stu &p2,Stu &p3,Stu &p4,Stu &p5,Stu &p6)
{
sheji:
char *name[6]={p1.name,p2.name,p3.name,p4.name,p5.name,p6.name};
int number[6]={p1.number,p2.number,p3.number,p4.number,p5.number,p6.number};
double English[6]={p1.English,p2.English,p3.English,p4.English,p5.English,p6.English};
double Math[6]={p1.Math,p2.Math,p3.Math,p4.Math,p5.Math,p6.Math};
double Cjj[6]={p1.Cjj,p2.Cjj,p3.Cjj,p4.Cjj,p5.Cjj,p6.Cjj};
double Total[6]={p1.Total,p2.Total,p3.Total,p4.Total,p5.Total,p6.Total};
double Average[6]={p1.Average,p2.Average,p3.Average,p4.Average,p5.Average,p6.Average};
Stu soure[6]={p1,p2,p3,p4,p5,p6};
char *s1,s2[8];
double *p;
int n;
double mat;
cout<<"\t\t主菜单"<<endl;
cout<<"\t1.查询平均分排名;"<<endl;
cout<<"\t2.查询个人情况;"<<endl;
cout<<"\t3.查询各科平均成绩;"<<endl;
cout<<"\t4.输出班级成绩;"<<endl;
cout<<"\t5.修改各人成绩;"<<endl;
cout<<"\t6.查询不及格成绩;"<<endl;
cout<<"\t0.退出;"<<endl;
int q;
cout<<"请选择你要进行的操作:";
cin>>q;
if(q==1)
{
p=Average;
cout<<"\t**********以平均成绩进行排名**********"<<endl;
strcpy(s2,"均分");
for(int i1=1;i1<6;i1++)
{
for(int j1=0;j1<6-i1;j1++)
if(p[j1]<=p[j1+1])
{
mat=p[j1],p[j1]=p[j1+1],p[j1+1]=mat;
s1=name[j1],name[j1]=name[j1+1],name[j1+1]=s1;
n=number[j1],number[j1]=number[j1+1],number[j1+1]=n;
}
}
cout<<"\t\t名次\t姓名\t学号\t"<<s2<<"\n";
for(i1=0;i1<6;i1++)
cout<<"\t\t"<<i1+1<<"\t"<<name[i1]<<"\t"<<number[i1]<<"\t"<<p[i1]<<endl;
cout<<endl;
goto sheji;
}
if(q==2)
{
int w;
cout<<"请输入你要查询的同学的学号:";
cin>>w;
cout<<"\t姓名\t学号\t英语\t数学\tC++\t均分\t总分"<<"\n";
for(int i=0;i<6;i++)
{
if(w==number[i])
output2(soure[i]);
}
goto sheji;
}
else if(q==3)
{
cout<<"\t**********各科平均成绩**********"<<endl;
double a1=0,b=0,d=0,e=0,h=0;
for(int j=0;j<6;j++)
{
a1+=English[j];
}
cout<<"\t英语的平均分为\t"<<(double(a1/5.0))<<endl;
for(int i=0;i<6;i++)
{
b+=Math[i];
}
cout<<"\t数学的平均分为\t"<<(double(b/5.0))<<endl;
for(int k=0;k<6;k++)
{
e+=Cjj[k];
}
cout<<"\tC++的平均分为\t"<<(double(e/5.0))<<endl;
goto sheji;
}
else if(q==4)
{
ofstream file("d:\\student.txt");
if(!file)
{
cout<<"student.txt can't open.\n";
abort();
}
file<<"\t姓名\t学号\t英语\t数学\tC++\t均分\t总分"<<"\n";
for(int i=0;i<6;i++)
{
file<<"\t"<<name[i]<<"\t"<<number[i]<<"\t"<<English[i]<<"\t"<<Math[i]<<"\t"<<Cjj[i]<<"\t"<<Average[i]<<"\t"<<Total[i]<<"\n";
}
file.close();
cout<<"计算机-1的成绩单已输入到了D:\\student.txt中。希望你查看!"<<endl;
goto sheji;
}
else if(q==5)
{
cout<<"\t**********在这里对学生成绩进行修改**********"<<endl;
int b1;
cout<<"请输入你要修改学生的学号:"<<endl;
cin>>b1;
if(b1==p1.number)
{
p1=Stu();
input(p1);
cout<<"\t修改成功!!"<<endl;
}
else if(b1==p2.number)
{
p2=Stu();
input(p2);
cout<<"\t修改成功!!"<<endl;
}
else if(b1==p3.number)
{
p3=Stu();
input(p3);
cout<<"\t修改成功!!"<<endl;
}
else if(b1==p4.number)
{
p4=Stu();
input(p4);
cout<<"\t修改成功!!"<<endl;
}
else if(b1==p5.number)
{
p5=Stu();
input(p5);
cout<<"\t修改成功!!"<<endl;
}
else if(b1==p1.number)
{
p1=Stu();
input(p1);
cout<<"\t修改成功!!"<<endl;
}
else if(b1!=p1.number||b1!=p2.number||b1!=p3.number||b1!=p4.number||b1!=p5.number||b1!=p6.number)
{
cout<<"对不起!该学号不存在!请确认后在输入!"<<endl;
}
goto sheji;
}
else if(q==6)
{
cout<<"**********统计有不及格科目的同学***********"<<endl;
for(int i=0;i<6;i++)
{
if(English[i]<60||Math[i]<60||Cjj[i]<60)
{
cout<<"\t姓名\t学号\t英语\t数学\tC++\t均分\t总分"<<"\n";
output2(soure[i]);
}
}
goto sheji;
}
else if(q==0)
{
cout<<"谢谢你的支持!"<<endl;
exit(1);
}
}
void main()
{
Stu m1,m2,m3,m4,m5,m6;
void Stu::getname();
{
cout<<" ****************欢迎来到成绩管理系统***************"<<endl;
cout<<"请对各学生的成绩进行输入:"<<endl;
input(m1);
input(m2);
input(m3);
input(m4);
input(m5);
input(m6);
cout<<"你输入的是:"<<endl;
cout<<"\t\t姓名\t学号\t英语\t数学\tC++"<<"\n";
output1(m1);
output1(m2);
output1(m3);
output1(m4);
output1(m5);
output1(m6);
order(m1,m2,m3,m4,m5,m6);
}
}
本回答被提问者和网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询