当前位置:网站首页>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;
}

如有错误,多多指教!
边栏推荐
- LeetCode二叉树系列——144.二叉树的最小深度
- 吃透Chisel语言.29.Chisel进阶之通信状态机(一)——通信状态机:以闪光灯为例
- BI-SQL丨WHILE
- [C# 循环跳转]-C# 中的 while/do-while/for/foreach 循环结构以及 break/continue 跳转语句
- Study Notes - Becoming a Data Analyst in Seven Weeks "Week 2: Business": Business Analysis Metrics
- 数字信号处理课程实验报告(数字信号处理需要什么基础)
- The truth of the industry: I will only test those that have no future, and I panic...
- ARC117E Zero-Sum Ranges 2
- Hello,World
- 使用bat脚本以json格式导出mongo数据库中指定表数据
猜你喜欢

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

2022年,目前大环境下还适合转行软件测试吗?

数据中台建设(五):打破企业数据孤岛和提取数据价值

DocuWare 文件管理与工作流程自动化案例研究——DocuWare 工作流程功能使在家工作的员工能够保持沟通和高效工作,支持混合环境

The truth of the industry: I will only test those that have no future, and I panic...

华为7年经验的软件测试总监,给所有想转行学软件测试的朋友几点建议

5. DOM

【VMware虚拟机安装mysql5.7教程】

Still saying software testing doesn't have a midlife crisis?9 years of test engineers were eliminated

LeetCode二叉树系列——144.二叉树的最小深度
随机推荐
无代码开发平台应用可见权限设置入门教程
pytorch学习记录(五):卷积神经网络的实现
BI-SQL丨WHILE
(HR面试)最常见的面试问题和技巧性答复
UPC2022暑期个人训练赛第19场(B,P)
The main content of terrain analysis (the special effect level of the wandering earth)
Why did I switch from developer to testing, 3 years software testing engineer, tell you the secret of this
VLAN实验
eclipse连接SQL server数据库「建议收藏」
A new generation of open source free terminal tools, so cool
sql中ddl和dml(sql与access的区别)
[ARC092B] Two Sequences
时序数据库在船舶风险管理领域的应用
CF338E Optimize!
八年测试经验,为何惨遭领导痛批:你写的测试文档还不如刚来的应届生
CF780G Andryusha and Nervous Barriers
Recommended open source tools: MegPeak, a high-performance computing tool
手把手教你写让人眼前一亮的软件测试简历,收不到面试邀请算我输
Study Notes - Becoming a Data Analyst in Seven Weeks "Week 2: Business": Business Analysis Metrics
Cookie simulation login "recommended collection"