c++ 容器案例--评委打分

#include <iostream>
#include <string>
#include <fstream>
#include <vector>
#include <algorithm>
#include <deque>
using namespace std;
class Person
{
public:
string name;
int score;
Person(string name, int score)
{
this->name = name;
this->score = score;
}
};
void createPerson(vector<Person> &v)
{
string nameSeed="ABCDE";
for(int i = 0; i < 5; i++)
{
string name="person";
name+=nameSeed[i];
int score=0;
Person p(name,score);
v.push_back(p);
}
}
void setScore(vector<Person> &v)
{
for(vector<Person>::iterator it = v.begin(); it != v.end(); it++)
{
deque<int> d;
for(int i = 0; i < 10; i++)
{
int score = rand()%41+60;
d.push_back(score);
}
cout<<"name:"<<it->name<<" score:"<<endl;
for(deque<int>::iterator dit = d.begin(); dit != d.end(); dit++)
{
cout<<*dit<<" ";
}
cout<<endl;
sort(d.begin(),d.end());
d.pop_front();
d.pop_back();
int sum = 0;
for(deque<int>::iterator dit = d.begin(); dit != d.end(); dit++)
{
sum += *dit;
}
it->score = sum/8;
}
}
void show(vector<Person> &v)
{
for(vector<Person>::iterator it = v.begin(); it != v.end(); it++)
{
cout<<"name:"<<it->name<<" score:"<<it->score<<endl;
}
}
int main()
{
vector<Person> v;
createPerson(v);
for(vector<Person>::iterator it = v.begin(); it != v.end(); it++)
{
cout<<"name:"<<it->name<<" score:"<<it->score<<endl;
}
setScore(v);
show(v);
system("pause");
}

更多推荐
所有评论(0)