请高手帮我改个程序~
能运行,可就是运行出来的结果是不对的~求高手帮我改下:)//编写一个程序,已有若干个学生数据,包括学号、姓名、成绩,要求输出学生数据,计算平均分,并按平均分的高低排序。
#include <iostream.h>
#include <string.h>
#include <iomanip.h>
class Student
{
private:
int number;
char *name;
int score1,score2,score3;
public:
Student() {}
void get(int,char *,int,int,int);
int average();
void show();
~Student(){}
};
void Student::get(int xnumber,char *xname,int xscore1,int xscore2,int xscore3)
{
number=xnumber;
name=new char(strlen(xname)+1);
*name=*xname;
score1=xscore1;
score2=xscore2;
score3=xscore3;
}
int Student::average()
{return ((score1+score2+score3)/3);
}
void Student::show()
{cout<<"学号:"<<number<<setw(10)<<"姓名:"<<name<<endl;
cout<<"语文成绩:"<<score1<<setw(15)<<"数学成绩:"<<score2<<setw(15)<<"英语成绩:"<<score3<<setw(15)<<"平均分:"<<average()<<endl;
cout<<endl;
}
void main()
{
int i,j;
Student S[3];
Student Temp;
S[0].get(1,"唐门",90,88,89);
S[1].get(2,"贾思乐",99,90,95);
S[2].get(3,"蒋小花",78,80,69);
for(i=0;i<3;i++)
{for(j=0;j<3;j++)
if((S[j].average())<(S[j+1].average()))
{Temp=S[j];
S[j]=S[j+1];
S[j+1]=Temp;
}
}
cout<<"按平均分从高到低排序后:"<<endl;
S[0].show();
S[1].show();
S[2].show();
}
[[it] 本帖最后由 xtusr 于 2008-10-28 17:05 编辑 [/it]]