Private Sub Command1_Click()
Dim s, i, j, arr(1 To 10), t, sum
For i = 1 To 10
s = InputBox("输入评分(0-10分):", "第" &i &"个分数")
If IsNumeric(s) Then
s = Val(s)
If s <0 Or s >10 Then
i = i - 1
Else
arr(i) = s
End If
Else
i = i - 1
End If
Next
For i = 1 To 9
For j = i + 1 To 10
If arr(i) >arr(j) Then
t = arr(i): arr(i) = arr(j): arr(j) = t
End If
Next
Next
For i = 2 To 9
sum = sum + arr(i)
Next
Label1.Caption = "最高分亩亏侍为:" &arr(10)
Label2.Caption = "最低分为:" &arr(1)
Label3.Caption = "选手最后得分:"迅吵 &Round(sum / 8, 1)
End Sub
Private Sub Command2_Click()
Unload Me
End Sub
Private Sub Form_Load()
Command1.Caption = "评分"
Command2.Caption = "结束"空铅
With Label1
.Caption = ""
.AutoSize = True
End With
With Label2
.Caption = ""
.AutoSize = True
End With
With Label3
.Caption = ""
.AutoSize = True
End With
End Sub
#include "州余stdio.h"void main()
{
int i,Max=-1,Min=999,Score,x,y
double Sum=0,a[10],Max2=-1,Min2=999,z
printf("练习30题_6:歌星比赛评分:\n")
for(i=1i<=10i++)
{
printf("第%d位评委打分:\n",i)
scanf("%d",&Score)
a[i]=Score
Sum+=Score
if(Score>Max)Max=Score
if(Score<Min)Min=Score
}
printf("%s%d\n%s%d\n%s%f\n","去掉一个最高分",Max,"去掉一个最低分",Min,"得出的分数为:",(Sum-Min-Max)/8)
z=(Sum-Min-Max)/8
for(i=1i<=10i++)
{
if(a[i]-z>0)//等闭迹弯于0就是差距最小的了所以不用在max上
if(a[i]-z>Max2)
{
Max2=a[i]-z
x=i
}
else if (z-a[i]>0)
if(z-a[i]>Max2)
{
Max2=z-a[i]
x=i
}
if(a[i]-z>=0)
if(a[i]-z<Min2)
{
Min2=a[i]-z
y=i
}
else if (z-a[i]>=0)
if(z-a[i]<Min2)
{
Min2=z-a[i]
y=i
}
}
printf("思维延伸:最公平的裁判是:第%d位。\n最轿闷不公平的裁判是:第%d位。\n",y,x)//以上代码没写并列情况
}
//我的是用C++做的。//SetScore.h
#ifndef SETSCORE_H_
#define SETSCORE_H_
#include <string>
using namespace std
class Umpire
{
public:
Umpire()
~Umpire()
bool SetScore()
void GetName()
int GetScore()
private:
int m_Score
string m_szName_Umpire
}
struct Singer
{
string szName_Singer
int MaxScore
int MinScore
double AveScore
int Grade
}
#endif//SETSCORE_H_
//SetScore.cpp---类与结构的实现文件。
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include "SetScore.h"
using namespace std
//------------------------裁判类的实现---------------------
Umpire::Umpire()
:m_szName_Umpire("No Name"),m_Score(0)
{}
void Umpire::GetName()
{
string name
cin>>name
m_szName_Umpire=name
}
bool Umpire::SetScore()
{
//cout<<"Please Set Scores for Singer:[60,100]."<<endl
int score
cin>>score
if(score<60||score>100)
{
cout<<"你输入了一个非法值。请输入在[60,100]中的一个整数值。"<<endl
return false
}
m_Score=score
return true
}
int Umpire::GetScore()
{
return m_Score
}
Umpire::~Umpire()
{}
//------------------------歌手类的实现---------------------
//本想好哗也做一个类的,但考虑到顺便练习一下结构的使用,
//就没做类了。这里的成员第一次使用时都将是左值,因此就不初始化了。
//Singer.AveScore=0
//-------------------全局函谈世数声明--------------------------
int main()
{
//--------------裁判和歌手的信息初始化---=-------------
const int nUmpireNum=4//最少要有3名裁判。否则不能去掉最高与最低分。
const int nSingerNum=2
//------------------- 构造一个容器,用来将得分排含袜肢序-----
vector<double>vec
//-------------------裁判------------------------------
cout<<"\n=====================裁判======================\n"
Umpire *pUmpire=new Umpire[nUmpireNum]
//Umpire umpire[nUmpireNum]
for(int i=0i<nUmpireNum++i)
{
cout<<"Please Input a name for The ("<<i+1<<"/"<<nUmpireNum<<") Umpire :"<<endl
pUmpire[i].GetName()
}
//-------------------歌手------------------------------
cout<<"\n=====================歌手======================\n"
Singer singer[nSingerNum]
Singer* pSinger=singer
for(int j=0j<nSingerNum++j)
{
cout<<"Please Input a name for The ("<<j+1<<"/"<<nSingerNum<<") Singer :"<<endl
string name
cin>>name
pSinger[j].szName_Singer=name
}
//-------------------打分过程----------------------
int nGetScorePerson(0)
while(nGetScorePerson<nSingerNum)
{
cout<<"现在请给第 "<<nGetScorePerson+1<<"位歌手打分[60,100](共"<<nSingerNum<<"位):"<<endl
int nScore[nUmpireNum],nMin(0),nMax(0),nSum(0)
//------------------打分-----------------------------
for(int i=0i<nUmpireNum++i)
{
cout<<"请第"<<i+1<<"位裁判打分(共"<<nUmpireNum<<"位)"<<endl
bool bValid=pUmpire[i].SetScore()
while(!bValid)
{//直到输入正确才结束循环。
bValid=pUmpire[i].SetScore()
}
nScore[i]=pUmpire[i].GetScore()//记下每个裁判的打分。
}
//--------------找到最低分,最高分。------------------
nMin=nMax=nScore[0]
for(int j=0j<nUmpireNum++j)
{
if(nMin>nScore[j])
nMin=nScore[j]
if(nMax<nScore[j])
nMax=nScore[j]
nSum+=nScore[j]
}
pSinger[nGetScorePerson].MaxScore=nMax
pSinger[nGetScorePerson].MinScore=nMin
//---------------算出平均值得分-----------------------
pSinger[nGetScorePerson].AveScore=(double)(nSum-nMin-nMax)/(nUmpireNum-2)
//-------------将平均值放入容器中,用来排名次---------
vec.push_back(pSinger[nGetScorePerson].AveScore)
//------------------输出格式(四项内容)--------------
cout<<"歌手姓名---最终得分---最高得分---最低得分---\n "
cout<<pSinger[nGetScorePerson].szName_Singer<<"-----"
<<pSinger[nGetScorePerson].AveScore<<"--------------"
<<pSinger[nGetScorePerson].MaxScore<<"--------------"
<<pSinger[nGetScorePerson].MinScore<<"---\n"
//------------------循环到下一位singer----------------
++nGetScorePerson
}
sort(vec.begin(),vec.end())//排序,从小到大。
//================================================================
//==============下面就是输出所有歌手排名信息的处理了==============
//================================================================
cout<<"\n=======排=================行===============榜========\n"<<endl
cout<<"\n----歌手姓名---------------排--名----\n "
int nGrade(1)//用来排名次的。
for(int k=vec.size()-1k>=0--k)
{
for(int i=0i<nSingerNum++i)
{
if(pSinger[i].AveScore==vec[k])
{
cout<<"------"<<pSinger[i].szName_Singer
<<"------------------"<<"第"<<nGrade++<<"名"<<endl
break
}
}
}
delete [] pUmpire
return 0
}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)