9_78.cpp
上传用户:zipjojo
上传日期:2009-07-20
资源大小:70k
文件大小:2k
源码类别:

文章/文档

开发平台:

C/C++

  1. #include<iostream.h>
  2. #include<iomanip.h>
  3. #define Max 20
  4. class English
  5. {
  6. int ptr;
  7. int score[Max];
  8. public:
  9. void getdata(int val,int ptr) {score[ptr]=val;}
  10. int disp(int ptr){return score[ptr];}
  11. };
  12. class Computer
  13. {
  14. int ptr;
  15. int score[Max];
  16. public:
  17. void getdata(int val,int ptr) {score[ptr]=val;}
  18. int disp(int ptr){return score[ptr];}
  19. };
  20. class Chinese
  21. {
  22. int ptr;
  23. int score[Max];
  24. public:
  25. void getdata(int val,int ptr) {score[ptr]=val;}
  26. int disp(int ptr){return score[ptr];}
  27. };
  28. class Student:private English,private Computer,private Chinese
  29. {
  30. char name[Max][10];
  31. double average[Max];
  32. static int rank;
  33. public:
  34. void getdata(int index)
  35. {
  36. int score1,score2,score3;
  37. for(int i=0;i<index;i++)
  38. {
  39. average[i]=0;
  40. cout<<"学生姓名:";
  41. cin>>name[i];
  42. cout<<"英语 计算机 中文成绩:";
  43. cin>>score1>>score2>>score3;
  44. average[i]+=score1;
  45. average[i]+=score2;
  46. average[i]+=score3;
  47. English::getdata(score1,i);
  48. Computer::getdata(score2,i);
  49. Chinese::getdata(score3,i);
  50. average[i]/=3;
  51. }
  52. }
  53. void sort(int index)  //直接选择排序
  54. {
  55.     int i,j,pick;
  56.      for(i=0;i<index;i++)
  57. {
  58.      pick=0;
  59.      while(average[pick]==-1 && pick<index) pick++;
  60.      for(j=1;j<index;j++)
  61. {
  62.      while(average[j]==-1 && j<index) j++;
  63.      if(j<index && average[j]>average[pick])
  64. pick=j;
  65. }
  66.      cout<<setw(3)<<rank++<<" ";
  67.             cout<<setw(6)<<name[pick]<<" ";
  68.      cout<<setw(5)<<English::disp(pick)<<" ";
  69.      cout<<setw(7)<<Computer::disp(pick)<<" ";
  70.      cout<<setw(5)<<Chinese::disp(pick)<<" ";
  71.     cout<<setw(10)<<setprecision(4)<<average[pick]<<endl;
  72.      average[pick]=-1;
  73. }
  74. }
  75. };
  76. int Student::rank=1;
  77. void main()
  78. {
  79. Student A;
  80. int num;
  81. cout<<"学生人数:";
  82. cin>>num;
  83. A.getdata(num);
  84.     cout<<"输出结果:"<<endl;
  85. cout<<setw(4)<<"名次"<<setw(6)<<"姓名"<<setw(6)<<"英语"<<setw(9)
  86. <<"计算机"<<setw(6)<<"中文"<<setw(10)<<"平均分"<<endl;
  87. A.sort(num);
  88. }