0.前言
1.系统自动生成的评委评分代码:
# include <iostream>
using namespace std;
# include <deque>
# include <vector>
# include <algorithm>
# include <string>
class Player
{
public :
Player ( string name, float score)
{
m_Name = name;
m_Score = score;
}
string m_Name;
float m_Score;
} ;
void createPlayer ( vector< Player> & player)
{
string Sname = "ABCDE" ;
for ( int i = 0 ; i < 5 ; i++ )
{
string name = "选手" ;
name += Sname[ i] ;
float score = 0 ;
Player p ( name, score) ;
player. push_back ( p) ;
}
}
void setScore ( vector< Player> & player)
{
srand ( ( unsigned int ) time ( NULL ) ) ;
for ( vector< Player> :: iterator it = player. begin ( ) ; it != player. end ( ) ; it++ )
{
deque< int > d;
for ( int i = 0 ; i < 10 ; i++ )
{
float score = rand ( ) % 41 + 60 ;
d. push_back ( score) ;
}
sort ( d. begin ( ) , d. end ( ) ) ;
d. pop_back ( ) ;
d. pop_front ( ) ;
float sum = 0 ;
for ( deque< int > :: iterator dit = d. begin ( ) ; dit != d. end ( ) ; dit++ )
{
sum += * dit;
}
float avg = sum / d. size ( ) ;
it-> m_Score = avg;
}
}
void showScore ( vector< Player> & player)
{
for ( vector< Player> :: iterator it = player. begin ( ) ; it != player. end ( ) ; it++ )
{
cout << it-> m_Name << "\t\t" << "平均分为:" << it-> m_Score << endl;
}
cout << "选手评分结束!" << endl;
}
int main ( )
{
vector< Player> player;
createPlayer ( player) ;
setScore ( player) ;
showScore ( player) ;
system ( "pause" ) ;
return 0 ;
}
2.用户手动输入评委评分代码:
# include <iostream>
using namespace std;
# include <deque>
# include <vector>
# include <algorithm>
# include <string>
class Player
{
public :
Player ( string name, float score)
{
m_Name = name;
m_Score = score;
}
string m_Name;
float m_Score;
} ;
void createPlayer ( vector< Player> & player)
{
string Sname = "ABCDE" ;
for ( int i = 0 ; i < 5 ; i++ )
{
string name = "选手" ;
name += Sname[ i] ;
float score = 0 ;
Player p ( name, score) ;
player. push_back ( p) ;
}
}
void setScore ( vector< Player> & player)
{
cout << "请在场的十位评委们给选手们打分:" << endl;
for ( vector< Player> :: iterator it = player. begin ( ) ; it != player. end ( ) ; it++ )
{
cout << it-> m_Name << " 的十个分数分别为:" << endl;
deque< int > d;
for ( int i = 0 ; i < 10 ; i++ )
{
float score;
cin >> score;
d. push_back ( score) ;
}
sort ( d. begin ( ) , d. end ( ) ) ;
d. pop_back ( ) ;
d. pop_front ( ) ;
float sum = 0 ;
for ( deque< int > :: iterator dit = d. begin ( ) ; dit != d. end ( ) ; dit++ )
{
sum += * dit;
}
float avg = sum / d. size ( ) ;
it-> m_Score = avg;
}
}
void showScore ( vector< Player> & player)
{
cout << "各选手的得分情况如下:" << endl;
for ( vector< Player> :: iterator it = player. begin ( ) ; it != player. end ( ) ; it++ )
{
cout << it-> m_Name << "\t\t" << "平均分为:" << it-> m_Score << endl;
}
cout << "选手评分结束!" << endl;
}
int main ( )
{
vector< Player> player;
createPlayer ( player) ;
setScore ( player) ;
showScore ( player) ;
system ( "pause" ) ;
return 0 ;
}