永发信息网

高手请进~~~谢谢(全部代码)

答案:5  悬赏:0  手机版
解决时间 2021-04-23 14:56
在歌星大奖赛中,有10个评委为参赛的选手打分,分数为1-100分。选手最后得分为;去掉一个最高分个一个最低分后其余8个分数的平均值。请编写一个程序实现。
最佳答案

#include<iostream>


using namespase std;


void main()


{


int a[10]


int i,max,min;


int avg=0;


int sum=0;


for(i=0;i<10;i++)


{cout<<"请输入"<<i+1<<"号评委分数:"<<end;


cin>>a[i];}


max=a[0];


min=a[0];


for(i=0;i<10;i++)


{if(a[i]>max)


max=a[i];


if(a[i]<min)


min=a[i]}


for(i=0;i<10;i++)


sum+=a[i];


avg=(sum-(min+max))/8;


cout<<"平均分:"<<avg<<endl;


}

全部回答

由于不知道你要哪种语言实现的,我现在给你用的是C++类实现的。

本人这个程序代码是在VS 2008上实现的没有问题的,如有疑问联系我,QQ:444511220

#ifndef JUDGE_H_ #define JUDGE_H_

#include<iostream> #include<string> using std::string;

//定义评委类 class TJudge { public: TJudge(string const aJudgeName = "Judge",float const aJudgeScore = 0); virtual ~TJudge(); bool setJudgeScore(float aJudgeScore); //设置评委评分 float getJudgeScore() const; //获得评委评给分数 bool setJudgeName(string const aJudgeName); string getJudgeName() const; private: string m_strJudgeName; //评委姓名 float m_fJudgeScore; //评委所评分数 };

#endif

judge.cpp文件

#include"judge.h"

TJudge::TJudge(string const aJudgeName, float const aJudgeScore) { m_strJudgeName = aJudgeName; m_fJudgeScore = aJudgeScore; }

TJudge::~TJudge() {

}

bool TJudge::setJudgeScore(float aJudgeScore) { if(aJudgeScore) { m_fJudgeScore = aJudgeScore; return true; } else { return false; } }

float TJudge::getJudgeScore() const { return m_fJudgeScore; }

bool TJudge::setJudgeName(string const aJudgeName) { if(!aJudgeName.empty()) { m_strJudgeName = aJudgeName; return true; } else return false;

}

string TJudge::getJudgeName() const { return m_strJudgeName; }

competitor.h文件

#ifndef COMPETITOR_H_ #define COMPETITOR_H_ #include<iostream> #include<string>

using std::string; //定义比赛选手类 class TCompetitor { public: TCompetitor(string const aCompetitorName = "competitor", float const aCompetitorScore = 0); virtual ~TCompetitor(); float getCompetitorScore() const; //比赛选手得分 bool setCompetitorName(string const aCompetitorName); //设置选手姓名 string getCompetitorName() const; //获得选手姓名 private: string m_strCompetitorName; //比赛选手的姓名 float m_fCompetitorScore; //比赛选手的分数

};

#endif

competitor.cpp文件

#include"competitor.h"

TCompetitor::TCompetitor(string const aCompetitorName, float const aCompetitorScore) { m_strCompetitorName = aCompetitorName; m_fCompetitorScore = aCompetitorScore; }

TCompetitor::~TCompetitor() {

}

float TCompetitor::getCompetitorScore() const { return m_fCompetitorScore; }

bool TCompetitor::setCompetitorName(string const aCompetitorName) { if(!aCompetitorName.empty()) { m_strCompetitorName = aCompetitorName; return true; } else return false; }

string TCompetitor::getCompetitorName() const { return m_strCompetitorName; }

demo.cpp文件

#include"judge.h" #include"competitor.h" #include<ctime> #include<cstdlib> //#include<iostream>

using std::cout; using std::endl;

int main() { int t; srand(time(NULL)); //t = rand()%100 + 1; int MIN = 0; int MAX = 0; int SUM = 0; TJudge judge[10]; //十个评委

//评委打分 for(int i = 0; i < 10; i++) { t = rand()%100 + 1; //这里用于产生1~100之间的随机数,相当于评委评分 judge[i].setJudgeScore(t); } //输出评委打的分数 MIN = judge[0].getJudgeScore(); MAX = judge[0].getJudgeScore(); for(int j = 1; j <= 10; j++) { cout << "评委" << j << "的评分:" << judge[j-1].getJudgeScore() << endl;

//为节省时间效率,在输出评委分数的同时将最小分数和最高分数及和值算出 if(judge[j-1].getJudgeScore() < MIN) { MIN = judge[j-1].getJudgeScore(); //计算出最低分 } else { if(judge[j-1].getJudgeScore() > MAX) MAX = judge[j-1].getJudgeScore(); //计算出最高分 } SUM += judge[j-1].getJudgeScore(); }

cout << endl; cout << "去掉一个最低分:" << MIN << endl; cout << "去掉一个最高分:" << MAX << endl; cout << endl; cout << "最后得分:" << (SUM - MIN - MAX)/8 << endl; //最后得分 system("pause"); return 0; }

#include "stdio.h" float Max(float a[10]) { int i=0; float t=a[0]; for(i=1;i<10;i++) if(t<a[i])t=a[i]; return t; }

float Min(float a[10]) { int i=0; float t=a[0]; for(i=1;i<10;i++) if(t>a[i])t=a[i]; return t; }

void main() { float a[10],max,min,sum,avg; int i; printf("Please Scoring:"); for(i=0;i<10;i++) scanf("%f",&a[i]); max=Max(a); min=Min(a); for(i=0;i<10;i++) sum+=a[i]; avg=(sum-max-min)/8; printf("The final Score is %f",avg); getch(); }

==============================

#include<stdio.h> int main() { int integer,i,max,min,sum; max=-32768; min=32767; sum=0; for(i=1;i<=10;i++) { printf("Input number %d=",i); scanf("%d",&integer); sum+=integer; if(integer>max)max=integer; if(integer<min)min=integer; } printf("Canceled max score:%d\nCanceled min score:%d\n",max,min); printf("Average score:%d\n",(sum-max-min)/8); }

这个程序我没有调试,楼主先试下看行不行,除了问题再来问我

int main()

{

int i,j,k;

float m,a[10],sum=0,min=0;

for(i=0;i<10;i++)

{

do{

printf("请输入第%d个评委的打分:"i+1);

scanf("%f\n",m);

if(m>100||m<1)

{

printf("该分数超出范围,请从新输入!");

break;

}

}while(m>100||m<1);

}

min=a[0];

for(i=0;i<10;i++)

if(min>a[i])

{ k=min; min=a[i]; a[i]=k;}

for(j=1;j<9;j++)

sum+=a[j];

printf("该选手的最终得分为:%f",sum/8.0);

return 0;

}

我要举报
如以上问答信息为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
十二星座中哪个是全天第一大星座?
卖保健品需要什么证件,你好!卖保健食品需要
响水到徐州市的汽车有没有,急!
2000仟块钱可以配个怎么样的机箱
父母与孩子的诗歌朗诵,我需要有关感恩和孝心
想申请曼彻斯特大学
那里才能分到元宝
关于一篇好的教案怎么写?
两弹一心是什么原理?
网赚可信么????
阿坝乡村旅游标语,改革强军对联口号
怎么能恢复视力?
赖子山庄账号密码保护如何更换
爱情励志语句段落,励志激励朋友重新开始奋斗
天空网游QQ4280250 说GT劲舞团2点卡100元=600
推荐资讯
康达石材在什么地方啊,我要过去处理事情
你最在乎对方什么?
CF在游戏时如果来了扣扣信息,怎么在不退出前
半空中骑马的歇后语,牛耕田,马食谷,莫非马
斯柯达明锐换挡风玻璃需要多少钱?
怎么控制FLASH不超过10MB?
河南新乡辉县腊月玉米价钱会上涨吗?
人去世了以后会去哪呢?
德春堂药店地址在哪,我要去那里办事
超市怎么画图片,cd画图软件n项前进和向后退的
《七步诗》中,曹植巧比妙喻,诗中用“豆”比喻
求高人解梦:梦见捞鲤鱼
正方形一边上任一点到这个正方形两条对角线的
阴历怎么看 ?