// 学生成绩排序类.cpp : 定义控制台应用程序的入口点。
//
#include "stdafx.h"
#include<iostream>
#include<string>
using namespace std;
class S
{
public:
S(int num,char *name,float score);
void print(){cout<<NUM<<" "<<NAME<<" "<<SCORE<<endl;}
friend void sort(S a[],int n);
private:
int NUM;
char NAME[7];
float SCORE;
};
S::S(int num,char *name,float score)
{
NUM=num;
strcpy(NAME,name);
SCORE=score;
}
void sort(S a[],int n)
{
for(int i=0;i<n-1;i++)
for(int j=0;j<n-i-1;j++)
if(a[j+1].SCORE>a[j].SCORE)
{
a[6]=a[j+1];
a[j+1]=a[j];
a[j]=a[6];
};
}
void main()
{
using namespace std;
S str[7]={S(1000,"z",65.5),S(1001,"zh",91),
S(1002,"p",88),S(1003,"d",89),
S(1004,"w",99), S(1006,"k",86),S(0,'\0',0)
};
for(int i=0;i<6;i++)
str[i].print();
cout<<endl;
sort(str,6);
for(int j=0;j<6;j++)
str[j].print();
}