STL案例-评委打分

STL案例-评委打分_第1张图片

#include
using namespace std;
#include
#include
#include

class Person
{
public:
	Person(string name,int score)
	{
		this->m_Name = name;
		this->m_Score = score;
	}

	string m_Name;
	int m_Score;
};

//创建五名选手
void createPerson(vector& v)
{
	string name = "选手";
	string nameSeed = "ABCDE";
	for (int i = 0; i < 5; i++)
	{
		name += nameSeed[i];
		v.push_back(Person(name, 0));
	}
}

//给选手打分
void setScore(vector& v)
{
	for (vector::iterator it = v.begin(); it != v.end(); it++)
	{
		dequed;
		for (int i = 0; i < 10; i++)
		{
			d.push_back(rand()%41 + 60);
		}

		cout << it->m_Name << "具体得分为:  " << endl;
		for (deque::iterator dit = d.begin(); dit != d.end(); dit++)
		{
			cout << *dit << " ";
		}
		cout << endl;

		sort(d.begin(),d.end());
		d.pop_back();
		d.pop_front();

//计算平均分
		int sum = 0;

		for (deque::iterator dit = d.begin(); dit != d.end(); dit++)
		{
			sum+=*dit;
		}

		it->m_Score = sum / d.size();

		cout << "其最终平均分为: " << it->m_Score << endl << endl;
	}
}

void test01()
{
	vector v;
	createPerson(v);
	setScore(v);
}

int main() {
	test01();
}

结果:

STL案例-评委打分_第2张图片

你可能感兴趣的:(c++,c++,算法,开发语言)