码迷,mamicode.com
首页 > 其他好文 > 详细

打印总分与各科成绩单

时间:2014-05-23 04:14:42      阅读:288      评论:0      收藏:0      [点我收藏+]

标签:class   blog   c   http   a   int   

 

bubuko.com,布布扣

 #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;
}

打印总分与各科成绩单,布布扣,bubuko.com

打印总分与各科成绩单

标签:class   blog   c   http   a   int   

原文地址:http://www.cnblogs.com/zzkgis/p/3742602.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!