首页 > 代码库 > 打印总分与各科成绩单

打印总分与各科成绩单

 

图片

 #include<iostream>
using namespace std;
zong(float sum[100],int i,int m,int j,float max[100],float x[100],float X[100],int g,int k);
zong1(float score[100][100],int i,int m,int j,float max[100],float x[100],float X[100],int l,int g,int k);
struct subject
{
 char a[100];
}sub[52];
struct student
{
 int num;
 char name[100];
 float score;
}stu[52];
int main()
{
 int i,n,j,m,l,g,k=0;
 float score[100][100],sum[100],x[100],X[100],max[100];
 cout<<"输入这次考试的总科目及考生的人数:"<<endl;
 cin>>n>>m;
 for(i=1;i<=n;i++)
 {
  cout<<"输入这次考试第"<<i<<"场科目的名字:";
  cin>>sub[i].a;
 }
 for(i=1;i<=m;i++)
 {
  sum[i]=0;
  if(i<10)
  {
   cout<<"输入学号为201122110812000"<<i<<"姓名:";
  }
  else if(i<100)
  {
   cout<<"输入学号为20112211081200"<<i<<"姓名:";
  }
  else if(i<1000)
  {
   cout<<"输入学号为20112211081200"<<i<<"姓名:";
  }
  cin>>stu[i].name;
  for(j=1;j<=n;j++)
  {
   cout<<"                                                                                    "<<sub[j].a<<"成绩:";
   cin>>score[i][j];
  }
  for(j=1;j<=n;j++)
  {
   sum[i]=sum[i]+score[i][j];
  }
  cout<<"                                                                                        "<<stu[i].name<<"的总分为:"<<sum[i]<<"分"<<endl;
 }
 do
 {
  cout<<"选择你要查看的排次类型:"<<endl<<"1:总分排名";
     for(i=1;i<=n;i++)
  {
   cout<<i+1<<":"<<sub[i].a<<"排名";
  }
  cout<<n+2<<":结束查询"<<endl;
  cin>>l;
  if(l==1)
  {
   cout<<"                                                    "<<"总分成绩的排名表如下:"<<endl;
   zong(sum,i,m,j,max,x,X,g,k);
  }
  for(i=1;i<=n;i++)
  {
   if(l==i+1)
   {
    cout<<"                                                  "<<sub[i].a<<"成绩的排名表如下:"<<endl;
    zong1(score,i,m,j,max,x,X,l,g,k);
   }
  }
 }
 while(l!=n+2);
 return 0;
}
zong(float sum[100],int i,int m,int j,float max[100],float x[100],float X[100],int g,int k)
{
 for(i=1;i<=m;i++)
 {
  g=0;
  max[i]=-1;
  for(j=1;j<=m;j++)
  {
   max[i]=(sum[j]>max[i])?sum[j]:max[i];
  }
  x[i]=max[i];
  for(j=1;j<=m;j++)
  {
   if(x[i]==sum[j])
   {
    g++;
    X[i]=j;
    sum[j]=0;
    if(g==1)
     break;
   }
  }
 }
 k=0;
 for(i=1;i<=m;i++)
 {
  j=X[i];
        if(x[i]==x[i-1])
  {
   k++;
   if(i<10)
   {
    cout<<"                                                               "<<"201122110812000"<<j<<"     "<<"第"<<i-k<<"名"<<"    "<<stu[j].name<<"    "<<x[i]<<endl;
   }
   else if(i<100)
   {
    cout<<"                                                               "<<"201122110812000"<<j<<"     "<<"第"<<i-k<<"名"<<"    "<<stu[j].name<<"    "<<x[i]<<endl;
   }
  }
  else
  {
   if(i<10)
   {
    cout<<"                                                               "<<"201122110812000"<<j<<"     "<<"第"<<i<<"名"<<"    "<<stu[j].name<<"    "<<x[i]<<endl;
   }
   else if(i<100)
   {
    cout<<"                                                               "<<"201122110812000"<<j<<"     "<<"第"<<i<<"名"<<"    "<<stu[j].name<<"    "<<x[i]<<endl;
   }
      k=0;
  }
 }
 return 0;
}
zong1(float score[100][100],int i,int m,int j,float max[100],float x[100],float X[100],int l,int g,int k)
{
 for(i=1;i<=m;i++)
 {
  g=0;
  max[i]=-1;
  for(j=1;j<=m;j++)
  {
   max[i]=(score[j][l-1]>max[i])?score[j][l-1]:max[i];
  }
  x[i]=max[i];
  for(j=1;j<=m;j++)
  {
   if(x[i]==score[j][l-1])
   {
    g++;
    X[i]=j;
    score[j][l-1]=0;
    if(g==1)
     break;
   }
  }
 }
 k=0;
 for(i=1;i<=m;i++)
 {
  j=X[i];
  if(x[i]==x[i-1])
  {
   k++;
   if(i<10)
   {
    cout<<"                                                       "<<"201122110812000"<<j<<"     "<<"第"<<i-k<<"名"<<"    "<<stu[j].name<<"    "<<x[i]<<endl;
   }
   else if(i<100)
   {
    cout<<"                                                               "<<"201122110812000"<<j<<"     "<<"第"<<i-k<<"名"<<"    "<<stu[j].name<<"    "<<x[i]<<endl;
   }
  }
  else
  {
   if(i<10)
   {
    cout<<"                                                       "<<"201122110812000"<<j<<"     "<<"第"<<i<<"名"<<"    "<<stu[j].name<<"    "<<x[i]<<endl;
   }
   else if(i<100)
   {
    cout<<"                                                               "<<"201122110812000"<<j<<"     "<<"第"<<i<<"名"<<"    "<<stu[j].name<<"    "<<x[i]<<endl;
   }
      k=0;
  }
 }
 return 0;
}