高手请进~~~谢谢(全部代码)
- 提问者网友:战皆罪
- 2021-04-22 15:22
- 五星知识达人网友:第幾種人
- 2021-04-22 16:45
#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;
}
- 1楼网友:一叶十三刺
- 2021-04-22 19:37
由于不知道你要哪种语言实现的,我现在给你用的是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; }
- 2楼网友:行雁书
- 2021-04-22 18:34
#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(); }
- 3楼网友:我住北渡口
- 2021-04-22 17:58
==============================
#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); }
- 4楼网友:山有枢
- 2021-04-22 17:02
这个程序我没有调试,楼主先试下看行不行,除了问题再来问我
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;
}