#include <iostream>
using namespace std;
const int y=4; //列数
const int x=10; //行数
class Student
{
public:
void Display(int n);
void StuNum_Sort(int n);
void StuAve_Sort(int n);
void Normal_Sort(int n);
private:
static unsigned int StuNum[x][y] ;
};
void Student::Display(int n)
{
Normal_Sort(n);
cout<<"按学号排列如下:"<<endl;
StuNum_Sort(n);
cout<<"按平均成绩排列如下:"<<endl;
StuAve_Sort(n);
return;
}
void Student::Normal_Sort(int n) //第一方阵
{
for(int i=0;i<n;++i)
{
for(int j=0;j<y;++j)
{
cout<<StuNum[n-i-1][j]<<' ';
}
cout<<endl;
}
return;
}
void Student::StuNum_Sort(int n) //第二方阵,按学号从小到大排列,附加平均成绩
{
unsigned int temp;
unsigned int T[x][y+1],tx=0;
for(int i=0;i<n;++i)
{
for(int j=0;j<4;++j)
{
T[i][j]=StuNum[i][j]; //复制原来数组并扩增一列
if(j>0)
{
tx=T[i][j]+tx;
}
}
T[i][j]=tx/3; //平均成绩在最后一列
tx=0;
}
for(i=0;i<n-1;++i) //根据学号升序排序
{
for(int k=i+1;k<n;++k)
{
int L=0;
if(T[i][L]>T[k][L])
{
for(;L<y+1;++L)
{
temp=T[k][L];
T[k][L]=T[i][L];
T[i][L]=temp;
}
}
}
}
for(i=0;i<n;++i) //显示第二方阵结果
{
for(int j=0;j<y+1;++j)
{
cout<<T[i][j]<<' ';
}
cout<<endl;
}
return;
}
void Student::StuAve_Sort(int n) //第三方阵,按平均成绩从小到大排列
{
unsigned int temp;
unsigned int T[x][y+1],tx=0;
for(int i=0;i<n;++i)
{
for(int j=0;j<4;++j)
{
T[i][j]=StuNum[i][j]; //复制原来数组并扩增一列
if(j>0)
{
tx=T[i][j]+tx;
}
}
T[i][j]=tx/3; //平均成绩在最后一列
tx=0;
}
for(i=0;i<n-1;++i) //根据平均成绩升序排序
{
for(int k=i+1;k<n;++k)
{
int L=y;
if(T[i][L]>T[k][L])
{
for(;L>0;--L)
{
temp=T[k][L];
T[k][L]=T[i][L];
T[i][L]=temp;
}
}
}
}
for(i=0;i<n;++i) //显示第三方阵结果
{
for(int j=0;j<y+1;++j)
{
cout<<T[i][j]<<' ';
}
cout<<endl;
}
return;
}
//静态对象初始化
unsigned int Student::StuNum[x][y]={
{2009425342,33,71,100},
{2010345782,50,20,80},
{2011123458,80,77,90},
{2009190190,64,39,65},
{2009182198,50,78,82},
{2009190111,90,100,99},
{2010132938,49,59,69},
{2010291832,99,89,79},
{2011293817,88,46,81},
{2012928173,78,85,94},
};
void main()
{
Student c;
int n;
cout<<"请问要查看几个学生的成绩:"<<endl;
cin>>n;
c.Display(n);
return;
}