c++学生成绩管理代码,运行是乱码,求高手指正
// Note:Your choice is C++ IDE#include <iostream>
#include<iomanip>
using namespace std;
class English{
int ptr;
int score[20];
public:
void getdata(int val,int ptr) {score[ptr]=val;}
int disp(int ptr) {return score[ptr];}
};
class Chinese{
int ptr;
int score[20];
public:
void getdata(int val,int ptr) {score[ptr]=val;}
int disp(int ptr) {return score[ptr];}
};
class Computer{
int ptr;
int score[20];
public:
void getdata(int val,int ptr) {score[ptr]=val;}
int disp(int ptr) {return score[ptr];}
};
class student:private English,private Chinese,private Computer{
char name[20][10];
double average[20];
static int rank;
public:
void getdata(int index)
{
int score1,score2,score3;
for(int i=0;i<index;i++)
{
average[i]=0;
cout<<"student's name:";
cin>>name[i];
cout<<"The score of English Chinese Computer:";
cin>>score1>>score2>>score3;
English::getdata(score1,i);
Chinese::getdata(score2,i);
Computer::getdata(score3,i);
average[i]=(score1+score2+score3)/3;
}
}
void sort(int index)
{
int i,j,pick;
for(i=0;i<index;i++)
{
pick=0;
while(average[pick]=-1&&pick<index) {pick++;}
for(j=1;j<index;j++)
{
while(average[pick]=-1&&j<index) {j++;}
if(j<index&&average[j]>average[pick])
pick=j;
}
cout<<setw(3)<<rank++<<" ";
cout<<name[pick]<<endl;
/*cout<<setw(6)<<name[pick];
cout<<setw(5)<<English::disp(pick)<<" ";
cout<<setw(7)<<Chinese::disp(pick)<<" ";
cout<<setw(5)<<Computer::disp(pick)<<" ";
cout<<setw(10)<<setprecision(4)<<average<<endl;*/
average[pick]=-1;
}
}
};
int student::rank=1;
int main()
{
student A;
int num;
cout<<"enter the number:";
cin>>num;
A.getdata(num);
cout<<"the result is\n";
cout<<setw(4)<<"rank"<<setw(6)<<"name"<<setw(6)<<"English"
<<setw(6)<<"Chinese"<<setw(6)<<"Computer"<<setw(10)<<"average"<<endl;
A.sort(num);
return 0;
}