#include<iostream.h> #include<fstream.h> #include<string.h> class student { public: char name[10],sex[10],stu_no[20]; char age[10]; float English,maths,computer,matlab,VC,total,average; student() {} student(char *m_stu_no,char*m_name,char *m_sex,char* m_age); float getscore() {total=English+maths+computer+matlab+VC; average=total/5; cout<<" 总成绩:"<<total<<endl; cout<<" 平均成绩:"<<average<<endl; return total;} }; student::student( char *m_stu_no,char*m_name,char *m_sex,char* m_age) {strcpy(stu_no,m_stu_no); strcpy(name,m_name); strcpy(sex,m_sex); strcpy(age,m_age); }
#define MAX 10 void main(void) {int j; float tem; student A[MAX],C[10],D[10]; float B[10],eng[10],math[10],com[10],V[10],mat[10],aver[10]; char m_name[10],m_sex[10],m_stu_no[20],m_age[10]; ofstream fout("stud.tex");
if(!fout) {cout<<"cannot open output file\n"; }
for (int i=0;i<10;i++) { cout<<"依次输入学生"<<i+1<<"的信息:学号,姓名,性别,年龄"<<endl; cin>>m_stu_no>>m_name>>m_sex>>m_age; fout<<" 学号:"<<m_stu_no<<" 姓名:"<<m_name<<" 性别:"<<m_sex<<" 年龄:"<<m_age<<endl; cout<<"请再输入该生的英语、高数、计算机、数学实验、VC的成绩"<<endl; cin>>A[i].English>>A[i].maths>>A[i].computer>>A[i].matlab>>A[i].VC; fout<<" 英语:"<<A[i].English<<" 数学:"<<A[i].maths<<" 计算机:"<<A[i].computer<<" 数学实验:"<<A[i].matlab<<" VC语言:"<<A[i].VC<<endl; C[i]=student(m_stu_no,m_name,m_sex,m_age); B[i]=A[i].getscore(); eng[i]=A[i].English; math[i]=A[i].maths; com[i]=A[i].computer; mat[i]=A[i].matlab; V[i]=A[i].VC; aver[i]=A[i].average; }
fout.close(); ofstream outf("stud1.tex");
if(!outf) {cout<<" cannot open file"<<endl;
}
for ( i=0;i<9;i++) for( j=0;j<9;j++) if(B[j]<=B[j+1]) { tem=B[j]; B[j]=B[j+1]; B[j+1]=tem; tem=eng[j]; eng[j]=eng[j+1]; eng[j+1]=tem;
tem=math[j]; math[j]=mat[j+1]; math[j+1]=tem;
tem=com[j]; com[j]=com[j+1]; com[j+1]=tem; tem=mat[j]; mat[j]=mat[j+1]; mat[j+1]=tem;
tem=V[j]; V[j]=V[j+1]; V[j+1]=tem;
tem=aver[j]; aver[j]=aver[j+1]; aver[j+1]=tem;
D[i]=C[j]; C[j]=C[j+1]; C[j+1]=D[i];
} cout<<"总成绩高到低的排列:"<<endl; for(i=0;i<10;i++)
{ cout<<B[i]<<endl; outf<<" 学号:"<<C[i].stu_no<<" 性别:"<<C[i].sex<<" 姓名:"<<C[i].name<<" 年龄:"<<C[i].age<<endl; outf<<" 英语:"<<eng[i]<<" 数学:"<<math[i]<<" 计算机:"<<com[i]<<" 数学实验:"<<mat[i]<<" VC语言:"<<V[i]<<endl; outf<<" 总成绩:"<<B[i]<<" 平均成绩:"<<aver[i]<<endl;}
outf.close();
} 其他功能自己修改去 大体的框价就是这样的