c++實驗2.2
#include
#include<string.h>
using namespace std;
class student
{
private:
char name[20];
int number;
float score;
static int total_num;
static float total_score;
public:
static int calnum(){cout<<total_num<<endl;return total_num;}
static float calscore(){cout<<total_score<<endl;return total_score;}
friend void sort_score(student s[]);
student();
};
int student::total_num=0;
float student::total_score=0;
void sort_score(student s[])
{
int len,i,j;
float x;
len=s[0].total_num;
for(i=0;i<len;i++)
{
for(j=i+1;j<len;j++)
{
if(s[i].score<s[j].score)
{
x=s[i].score; s[i].score=s[j].score;s[j].score=x;
}
}
}
for(i=0;i<len;i++) cout<<s[i].score<<endl;
}
int main()
{
int n;
student *s;
cout<<“請輸入學生數量”<<endl;
cin>>n;
s=new student[n];
student::calnum();
student::calscore();
sort_score(s);
return 0;
}
student::student()
{
cout<<“請輸入名字,學號,分數”<<endl;
cin>>name>>number>>score;
total_num+=1;
total_score+=score;
}