当前位置:网站首页>A Small Case About Containers
A Small Case About Containers
2022-07-30 14:30:00 【old fish 37】

#include<iostream>
using namespace std;
#include<string>
#include<vector>
#include<deque>
#include<algorithm>
//创建一个类
class Person
{
public:
Person(string name, int score)
{
m_name = name;
m_score = score;
}
string m_name;
int m_score;
};
//创建选手
void CreatPerson(vector<Person>& v)
{
string name = "ABCDE";
for (int i = 0; i < 5; i++)
{
string name2 = "选手";
name2 += name[i];
int score = 0;
Person p(name2, score);
//Then put the created object into the container
v.push_back(p);
}
}
//打分 10名评委打分
void MarkScore(vector<Person>& v)
{
for (vector<Person>::iterator it = v.begin(); it != v.end(); it++)
{
int score = 0;
//创建一个duqueContainers hold scores
deque<int>d;
for (int i = 0; i < 10; i++)
{
score = rand() % 40 + 60;//Control the score in60-99
d.push_back(score);
}
//169-175code for display,可要可不要
//打印dequeFractions in the container
for (deque<int>::iterator dit = d.begin(); dit != d.end(); dit++)
{
cout << *dit << " ";
}
cout << endl;
//对dequeSort by the scores 默认从小到大,If you want to modify it, reload it directly
sort(d.begin(), d.end());
//Then remove the largest and smallest
d.pop_back();
d.pop_front();
//取平均数
int sum = 0;
for (deque<int>::iterator dit = d.begin(); dit != d.end(); dit++)
{
sum = sum + *dit;
}
int agv = sum / d.size();//原来10个,After removing the head and tail, there are still eight left
//Assign the mean to vector中的score
it->m_score = agv;//It's still in the loop at the moment 所以是it
}
}
//展示
void ShowPerson(vector<Person>& v)
{
for (vector<Person>::iterator it = v.begin(); it != v.end(); it++)
{
cout << (*it).m_name << " " <<"平均分为:" <<(*it).m_score << endl;
//You can also use pointers it->m_name it->m_score
}
}
int main()
{
//随机数种子
srand((unsigned int)time(NULL));
//创建一个容器 put players
vector<Person> v;
//创建选手
CreatPerson(v);
//打分
MarkScore(v);
//Show players
ShowPerson(v);
return 0;
}

如有错误,多多指教!
边栏推荐
- 我为何从开发人员转做测试,3年软件测试工程师,带你聊聊这其中的秘辛
- CF603E Pastoral Oddities
- 高性能数据访问中间件 OBProxy(三):问题排查和服务运维
- Still saying software testing doesn't have a midlife crisis?9 years of test engineers were eliminated
- CF1320E Treeland and Viruses
- [C# 循环跳转]-C# 中的 while/do-while/for/foreach 循环结构以及 break/continue 跳转语句
- 获取Google Advertising ID作为唯一识别码
- LeetCode二叉树系列——199二叉树的右视图
- 接口自动化框架,lm-easytest内测版发布,赶紧用起来~
- Shell变量与赋值、变量运算、特殊变量、重定向与管渠
猜你喜欢

LoRaWAN网关源码分析(V1.0.2)

内容产品进化三板斧:流量、技术、产品形态

Flask框架——Flask-Mail邮件

新时代背景下智慧城市的建设与5G技术有何关联

(一)Multisim安装与入门

(HR面试)最常见的面试问题和技巧性答复

MQTT网关读取西门子PLC数据传输到阿里云平台案例教程

Why do software testing have to learn automation?Talk about the value of automated testing in my eyes

为什么做软件测试一定要学自动化?谈谈我眼中自动化测试的价值

吃透Chisel语言.28.Chisel进阶之有限状态机(二)——Mealy状态机及与Moore状态机的对比
随机推荐
Synology system installation related file sharing
BI-SQL丨WHILE
ESP32 反复重启问题 Arduino屏蔽断电探测器
Simple understanding of Precision, Recall, Accuracy, TP, TN, FP, FN
Digital signal processing course lab report (what foundation is needed for digital signal processing)
pytorch学习记录(五):卷积神经网络的实现
LeetCode二叉树系列——144.二叉树的最大深度
A new generation of open source free terminal tools, so cool
No-code development platform application visible permission setting introductory tutorial
EasyV数字孪生流域|宁波智慧水利整体智治综合应用
sql server安装失败怎么办(sql server安装不了怎么办)
机器学习在竞赛和工业界应用区别
地形分析的主要内容(流浪地球的特效水平)
DocuWare 文件管理与工作流程自动化案例研究——DocuWare 工作流程功能使在家工作的员工能够保持沟通和高效工作,支持混合环境
NFTScan 与 PANews 联合发布多链 NFT 数据分析报告
二手手机销量突破3亿部,与降价的iPhone夹击国产手机
Eight years of testing experience, why was the leader criticized: the test documents you wrote are not as good as those of fresh graduates
The main content of terrain analysis (the special effect level of the wandering earth)
我为何从开发人员转做测试,3年软件测试工程师,带你聊聊这其中的秘辛
ARC115F Migration