/***************************student头文件***************************************/
#ifndef _STUDENT_H_
#define _STUDENT_H_
#include
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<
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
#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<
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
#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<
cout<
cout<
student1.SetChinese(56);
student1.SetEnglish(87);
student1.SetMath(87);
//计算不同学生学科的总成绩
CStudent General;
General=student1+student2+student3;
cout<
//查看多人各科目的平均成绩
cout<<"Average of Chinese :"<
<<"\nAverage of Math :"<
<<"\nAverage of English :"<
//查看个人平均成绩
cout<<"Average of students : \n";
cout<
cout<
cout<
//查看个人总成绩
cout<<"Total of students : \n";
cout<
cout<
cout<
cin.get();
return 0;
}
楼主给分吧
#include
#include
#include
#include
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"<
void output2(Stu &p)
{
cout<<"\t"<
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主菜单"<
cout<<"请选择你要进行的操作:";
cin>>q;
if(q==1)
{
p=Average;
cout<<"\t**********以平均成绩进行排名**********"<
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"<
cout<<"\t\t"<
}
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**********各科平均成绩**********"<
for(int j=0;j<6;j++)
{
a1+=English[j];
}
cout<<"\t英语的平均分为\t"<<(double(a1/5.0))<
{
b+=Math[i];
}
cout<<"\t数学的平均分为\t"<<(double(b/5.0))<
{
e+=Cjj[k];
}
cout<<"\tC++的平均分为\t"<<(double(e/5.0))<
}
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"<
file.close();
cout<<"计算机-1的成绩单已输入到了D:\\student.txt中。希望你查看!"<
}
else if(q==5)
{
cout<<"\t**********在这里对学生成绩进行修改**********"<
cout<<"请输入你要修改学生的学号:"<
if(b1==p1.number)
{
p1=Stu();
input(p1);
cout<<"\t修改成功!!"<
else if(b1==p2.number)
{
p2=Stu();
input(p2);
cout<<"\t修改成功!!"<
else if(b1==p3.number)
{
p3=Stu();
input(p3);
cout<<"\t修改成功!!"<
else if(b1==p4.number)
{
p4=Stu();
input(p4);
cout<<"\t修改成功!!"<
else if(b1==p5.number)
{
p5=Stu();
input(p5);
cout<<"\t修改成功!!"<
else if(b1==p1.number)
{
p1=Stu();
input(p1);
cout<<"\t修改成功!!"<
else if(b1!=p1.number||b1!=p2.number||b1!=p3.number||b1!=p4.number||b1!=p5.number||b1!=p6.number)
{
cout<<"对不起!该学号不存在!请确认后在输入!"<
goto sheji;
}
else if(q==6)
{
cout<<"**********统计有不及格科目的同学***********"<
{
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<<"谢谢你的支持!"<
}
}
void main()
{
Stu m1,m2,m3,m4,m5,m6;
void Stu::getname();
{
cout<<" ****************欢迎来到成绩管理系统***************"<
input(m2);
input(m3);
input(m4);
input(m5);
input(m6);
cout<<"你输入的是:"<
output1(m1);
output1(m2);
output1(m3);
output1(m4);
output1(m5);
output1(m6);
order(m1,m2,m3,m4,m5,m6);
}
}