//选手信息头文件,ginforn.h
#include <iostream>
#include <string>
#include <vector>
#include <deque>
#include <algorithm>
using namespace std;
class GPersonInfor
{
public:
GPersonInfor(string name, int score);
~GPersonInfor();
public:
string mName;
int mScore;
};
void CretePerInfor(vector<GPersonInfor>& v);
void GetTeachScore(vector<GPersonInfor>& v);
void ShowResult(vector<GPersonInfor>& v);
------------------------------------------------------分割线------------------------------------------------------------------
//选手信息的实现,ginforn.cpp
#include "ginforn.h"
GPersonInfor::GPersonInfor(string name, int score)
{
mName = name;
mScore = score;
}
GPersonInfor::~GPersonInfor()
{
}
void CretePerInfor(vector<GPersonInfor>& v)
{
string namespeed = "abcde";
int score = 0;
for (int i = 0; i < 5; i++)
{
string name = "选手";
name += namespeed[i];
GPersonInfor person(name, score);
v.push_back(person);
cout << "参赛选手姓名: " << name << endl;
}
cout << "--------------------" << endl;
}
void GetTeachScore(vector<GPersonInfor>& v)
{
for (vector<GPersonInfor> ::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 << "姓名:" << it->mName << " 得分如下: " << endl;
for (deque<int> ::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<int>::iterator dit = d.begin(); dit != d.end(); dit++)
{
sum += *dit;
}
int avg = sum / d.size();
//如何将分数传到score中
it->mScore = avg;
}
cout << "--------------------" << endl;
}
void ShowResult(vector<GPersonInfor>& v)
{
for (vector<GPersonInfor> ::iterator it = v.begin(); it != v.end(); it++)
{
cout << "获奖姓名: " << it->mName << " 平均分: " << it->mScore << endl;
}
}
------------------------------------------------------分割线------------------------------------------------------------------
//main函数
#include <iostream>
#include "ginforn.h"
int main()
{
//随机数种子
srand((unsigned int)time(NULL));
vector<GPersonInfor> v;
CretePerInfor(v);
GetTeachScore(v);
ShowResult(v);
system("pause");
return 0;
}
------------------------------------------------------分割线------------------------------------------------------------------
2022.7.9 ,第一次记录自己写过的代码,小白,刚看完C++视频,开始记录的第一天!