[求助]高手哥哥们,帮帮小弟的忙啊!
偶有一题,总是调试出错,但是偶却找不到错误在哪里,请高手们帮帮小弟的忙!!!!
题目是这样的:计算某一批参赛选手最后得分的类实现:某地举办歌舞大赛,参赛选手共n人,有九位评委,给每一选手打一个分数score(score为小于等于10的一个正实数).选手的最后的得分lastScore为去掉一个最高分以及一个最低分后另7个分数的平均值.
例如,假设常数n=3,程序执行后在屏幕上显示如下的结果:
Input 3 person’s information(1 number, 9 score):
person1:1 8.2 8.5 9.1 8.0 7.9 9.3 8.8 8.9 8.4
person2:2 7.8 7.9 7.6 8.4 8.1 8.8 8.4 8.1 9.0
person3:3 8.3 8.6 8.9 7.8 9.1 9.0 8.9 8.7 8.5
number maxScore minScore sum lastScore
1 1 9.3 7.9 59.9 8.55714
2 2 9.0 7.6 57.5 8.21429
3 3 9.1 7.8 60.9 8.7
我得程序的源代码如下:
#include <iomanip.h>
struct person{
int number;
double score[9],maxScore,minScore,sum,lastScore;
};
class myClass
{
private:
int n;
person *per;
public:
myClass(int n0);
void init();
void input();
void processing();
void outResult();
};
myClass::myClass(int n0)
{
n=n0;
per=new person[n];
}
void myClass::init()
{
for (int i=0;i<n;i++)
{
per[i].maxScore=0;
per[i].minScore=10.1;
per[i].sum=0;
}
}
void myClass::input()
{
cout<<"Input "<<n<<" person's information (1 number, 9 score):"<<endl;
cout<<"-----------------------------------------------------"<<endl;
for (int i=0;i<n;i++)
{
cout<<"person"<<i+1<<":";
cin>>per[i].number;
for (int j=0;j<9;j++)
cin>>per[i].score[j];
}
}
void myClass::processing()
{
for (int i=0;i<n;i++)
{
for (int j=0;j<9;j++)
{
double tmp=per[i].score[j];
per[i].sum+=tmp;
if (tmp>per[i].maxScore)
per[i].maxScore=tmp;
if (tmp<per[i].minScore)
per[i].minScore=tmp;
}
per[i].sum=per[i].sum-per[i].maxScore-per[i].minScore;
per[i].lastScore=per[i].sum/7;
}
}
void myClass::outResult()
{
cout<<"----------------------------------------------------"<<endl;
cout<<"number maxScore minScore sum lastScore"<<endl;
cout<<"----------------------------------------------------"<<endl;
for (int i=0;i<n;i++)
{
cout<<setw(6)<<per[i].number<<setw(10)<<per[i].maxScore;
cout<<setw(10)<<per[i].minScore<<setw(10)<<per[i].sum;
cout<<setw(12)<<per[i].lastScore<<endl;
}
}
void main()
{
myClass obj1(3);
obj1.init();
obj1.input();
obj1.processing();
obj1.outResult();
}
输出的结果是错误的,希望版主和大虾们帮帮我啊!!!!!!!!!
先谢谢了