9_78.cpp
上传用户:zipjojo
上传日期:2009-07-20
资源大小:70k
文件大小:2k
- #include<iostream.h>
- #include<iomanip.h>
- #define Max 20
- class English
- {
- int ptr;
- int score[Max];
- public:
- void getdata(int val,int ptr) {score[ptr]=val;}
- int disp(int ptr){return score[ptr];}
- };
- class Computer
- {
- int ptr;
- int score[Max];
- public:
- void getdata(int val,int ptr) {score[ptr]=val;}
- int disp(int ptr){return score[ptr];}
- };
- class Chinese
- {
- int ptr;
- int score[Max];
- public:
- void getdata(int val,int ptr) {score[ptr]=val;}
- int disp(int ptr){return score[ptr];}
- };
- class Student:private English,private Computer,private Chinese
- {
- char name[Max][10];
- double average[Max];
- static int rank;
- public:
- void getdata(int index)
- {
- int score1,score2,score3;
- for(int i=0;i<index;i++)
- {
- average[i]=0;
- cout<<"学生姓名:";
- cin>>name[i];
- cout<<"英语 计算机 中文成绩:";
- cin>>score1>>score2>>score3;
- average[i]+=score1;
- average[i]+=score2;
- average[i]+=score3;
- English::getdata(score1,i);
- Computer::getdata(score2,i);
- Chinese::getdata(score3,i);
- average[i]/=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[j]==-1 && j<index) j++;
- if(j<index && average[j]>average[pick])
- pick=j;
- }
- cout<<setw(3)<<rank++<<" ";
- cout<<setw(6)<<name[pick]<<" ";
- cout<<setw(5)<<English::disp(pick)<<" ";
- cout<<setw(7)<<Computer::disp(pick)<<" ";
- cout<<setw(5)<<Chinese::disp(pick)<<" ";
- cout<<setw(10)<<setprecision(4)<<average[pick]<<endl;
- average[pick]=-1;
- }
- }
- };
- int Student::rank=1;
- void main()
- {
- Student A;
- int num;
- cout<<"学生人数:";
- cin>>num;
- A.getdata(num);
- cout<<"输出结果:"<<endl;
- cout<<setw(4)<<"名次"<<setw(6)<<"姓名"<<setw(6)<<"英语"<<setw(9)
- <<"计算机"<<setw(6)<<"中文"<<setw(10)<<"平均分"<<endl;
- A.sort(num);
- }