文章目录

  • speaker.h
  • speechManager.h
  • main.cpp
  • speechManager.cpp

speaker.h

#pragma once
#include<iostream>using namespace std;class Speaker
{
public:string m_Name;double m_Score[2];
};

speechManager.h

#pragma once
#include<iostream>using namespace std;
#include<vector>
#include<map>
#include"speaker.h"
#include<algorithm>
#include<deque>
#include<numeric>
#include<functional>
#include<fstream>class SpeechManager
{
public:// constructionSpeechManager();// show menuvoid showMenu();// init speechvoid initSpeech();// create speakervoid createSpeaker();// start speechvoid startSpeech();// speech drawvoid speechDraw();// speech contestvoid speechContest();// show scorevoid showScore();// save recordvoid saveRecord();// load recordvoid loadRecord();// show recordvoid showRecord();// clear recordvoid clearRecord();// file flagbool fileIsEmpty;// mapmap<int, vector<string>> m_Record;// exit systemvoid exitProcedure();// deconstruction~SpeechManager();// member property// 12vector<int> v1;// 6vector<int> v2;// 3vector<int> vVictory;// mapmap<int,Speaker> mSpeaker;// countint m_Index;
};

main.cpp

#include<iostream>using namespace std;
#include"speechManager.h"int main()
{SpeechManager sm;demo code//for (map<int,Speaker>::iterator it = sm.mSpeaker.begin(); it != sm.mSpeaker.end(); it++)//{//    cout << "id: " << it->first << " name: " << it->second.m_Name << " score: " << it->second.m_Score[0] << endl;//}int choice = 0;while (true){sm.showMenu();cin >> choice;switch (choice){case 1: // start a speech contestsm.startSpeech();break;case 2: // view record of contestsm.showRecord();break;case 3: // clear the contest recordsm.clearRecord();break;case 0: // exit the speech proceduresm.exitProcedure();break;default:system("cls");break;}}system("pause");return 0;
}

speechManager.cpp

#include"speechManager.h"// construction
SpeechManager::SpeechManager()
{// init initSpeech();// create speakercreateSpeaker();//load recordloadRecord();
}// show menu
void SpeechManager::showMenu()
{cout << "**********************************************************" << endl;cout << "***************welcom to the speech contest***************" << endl;cout << "***************1.start a speech contest    ***************" << endl;cout << "***************2.view record of contest    ***************" << endl;cout << "***************3.clear the contest record  ***************" << endl;cout << "***************0.exit the speech procedure ***************" << endl;cout << "**********************************************************" << endl;
}// init speech
void SpeechManager::initSpeech()
{this->v1.clear();this->v2.clear();this->vVictory.clear();this->mSpeaker.clear();this->m_Index=1;
}// create speaker
void SpeechManager::createSpeaker()
{string nameSeed = "ABCDEFGHIJKL";for (int i = 0; i < nameSeed.size(); i++){string name = "player_";name += nameSeed[i];Speaker sp;sp.m_Name = name;for (int j = 0; j < 2; j++){sp.m_Score[j] = 0;}this->v1.push_back(i + 10001);this->mSpeaker.insert(make_pair(i + 10001, sp));}
}// start speech
void SpeechManager::startSpeech()
{// round one// drawspeechDraw();// contestspeechContest();// scoreshowScore();// round twom_Index++;// drawspeechDraw();// contestspeechContest();// scoreshowScore();// savesaveRecord();// reset the record// init initSpeech();// create speakercreateSpeaker();//load recordloadRecord();
}// speech draw
void SpeechManager::speechDraw()
{cout << "----round <<" << m_Index << ">> draw----" << endl;cout << "^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^" << endl;if (m_Index == 1){cout << "draw result as follows" << endl;random_shuffle(v1.begin(), v1.end());for (vector<int>::iterator it = v1.begin(); it != v1.end(); it++){cout << *it << " ";}cout << endl;}else{cout << "draw result as follows" << endl;random_shuffle(v2.begin(), v2.end());for (vector<int>::iterator it = v2.begin(); it != v2.end(); it++){cout << *it << " ";}cout << endl;}cout << "^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^" << endl;system("pause");
}// speech contest
void SpeechManager::speechContest()
{srand((unsigned int)time(NULL));cout << "round " << m_Index << " contest" << endl;vector<int> vSrc;int num = 0;// temp containermultimap<double,int,greater<double>> groupScore;if (m_Index == 1){vSrc = v1;}else{vSrc = v2;}for (vector<int>::iterator it = vSrc.begin(); it != vSrc.end(); it++){num++;// scoredeque<double> d;for (int i = 0; i < 10; i++){double score = (double)(rand() % 401 + 600) / 10.f;//cout << score << " ";d.push_back(score);}//cout << endl;// sortsort(d.begin(), d.end(), greater<double>());// pop max score and min scored.pop_back();d.pop_front();// sumdouble sum = accumulate(d.begin(), d.end(), 0.0f);// avgdouble avg = sum / (double)d.size();groupScore.insert(make_pair(avg, *it));this->mSpeaker[*it].m_Score[m_Index-1] = avg;if (num % 6 == 0){cout << "group "<< num/6<<" rank" << endl;for (multimap<double, int, greater<double>>::iterator mit = groupScore.begin(); mit != groupScore.end(); mit++){cout << "id: " << mit->second << " name: " << this->mSpeaker[mit->second].m_Name << " score: " << this->mSpeaker[mit->second].m_Score[m_Index-1] << endl;}// take the top threeint count = 0;for (multimap<double, int, greater<double>>::iterator mit = groupScore.begin(); count<3; mit++,count++){if (m_Index == 1){v2.push_back(mit->second);}else{vVictory.push_back(mit->second);}}groupScore.clear();cout << "round " << num / 6 << "contest over" << endl;cout << endl;}}
}// show score
void SpeechManager::showScore()
{vector<int> v;if (m_Index == 1){v = v2;}else{v = vVictory;}cout << "$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$" << endl;cout << "round " << m_Index << " contest score" << endl;for (vector<int>::iterator it = v.begin(); it != v.end() ; it++){cout << "id: " << *it << " name: " << this->mSpeaker[*it].m_Name <<"score: "<<this->mSpeaker[*it].m_Score[m_Index - 1] << endl;}system("pause");
}// save record
void SpeechManager::saveRecord()
{ofstream ofs;ofs.open("speech.csv", ios::out | ios::app);for (vector<int>::iterator it = vVictory.begin(); it != vVictory.end(); it++){ofs << *it << "," <<this->mSpeaker[*it].m_Score[1]<<",";}ofs << endl;ofs.close();this->fileIsEmpty = false;cout << "the speech contest is over" << endl;system("pause");
}// load record
void SpeechManager::loadRecord()
{ifstream ifs;ifs.open("speech.csv", ios::in);if (!ifs.is_open()){//cout << "no such file" << endl;this->fileIsEmpty = true;ifs.close();return;}char ch = {};ifs >> ch;if (ifs.eof()){//cout << "the file is null" << endl;this->fileIsEmpty = true;ifs.close();return;}this->fileIsEmpty = false;ifs.putback(ch);string data;int index = 0;while (ifs >> data){vector<string> v;//cout << data << endl;int pos = -1;int start = 0;while (true){pos = data.find(",", start);if (pos == -1){break;}string temp = data.substr(start,pos-start);v.push_back(temp);start = pos + 1;}m_Record.insert(make_pair(index, v));index++;}ifs.close();//for (map<int, vector<string>>::iterator it = m_Record.begin(); it != m_Record.end(); it++)//{//   cout << "round: " << it->first + 1 << " champion: " << it->second[0] << " score: " << it->second[1] << endl;//}
}// show record
void SpeechManager::showRecord()
{if (fileIsEmpty){cout << "no such file or file  is null" << endl;}else{for (int i = 0; i < m_Record.size(); i++){cout << "round: " << i + 1 << " champion    name: " << m_Record[i][0] << " score: " << m_Record[i][1] << " "<< "round: " << i + 1 << " runner-up   name: " << m_Record[i][2] << " score: " << m_Record[i][3] << " "<< "round: " << i + 1 << " third-place name: " << m_Record[i][4] << " score: " << m_Record[i][5] << endl;}}system("pause");system("cls");
}// clear record
void SpeechManager::clearRecord()
{cout << "are you sure clear the file" << endl;cout << "1.yes" << endl;cout << "2.no" << endl;int select = 0;cin >> select;if (select == 1){ofstream ofs;ofs.open("speech.csv", ios::trunc);ofs.close();cout << "clear successfully" << endl;// init initSpeech();// create speakercreateSpeaker();//load recordloadRecord();}system("pause");system("cls");
}// exit system
void SpeechManager::exitProcedure()
{cout << "welcom to back" << endl;system("pause");exit(0);
}// deconstruction
SpeechManager::~SpeechManager()
{}

speech contest相关推荐

  1. find的用法_【同步练习】高一英语下册find+复合宾语用法

    点击上方蓝字关注我们一.填空题(每小题10分,共100分) 1.当我到达电影院时,我发现我的钱包被偷了.(find+宾语+宾语补足语) I         when I got to the cine ...

  2. 给机器人罗宾写一封英语回信_近10年高考英语书面表达真题及范文大汇总! 把握高考命题新趋势!...

    2020年的新高考试卷中,英语学科在试卷结构.命题趋向.题型设置.分值分布.考查侧重点等方面均呈现出了较大的变化. 英语试卷相关部分的题量和分值出现"两增一减"的变化.英语写作部分 ...

  3. 张莉python 玩转数据答案_中国大学MOOC(慕课)用Python玩转数据答案大全

    中国大学MOOC(慕课)用Python玩转数据答案大全 更多相关问题 All the neighbors admire the family _______ the parents are treat ...

  4. 2020年12月统考练习题

    词汇与语法B 1.He opened the letter and it contained ________. A.an important information B.some important ...

  5. 大学英语B116-2020年12月

    词汇与语法B 1.He opened the letter and it contained ________. A.an important information B.some important ...

  6. 计算机科学与技术学院老师颁奖词,各种颁奖词收集与各类奖学金、各种称号、各种职位中英文对照(个人简历用得上)合集.doc...

    各种颁奖词收集与各类奖学金.各种称号.各种职位中英文对照(个人简历用得上)合集 各种颁奖词收集与各类奖学金.各种称号.各种职位中英文对照(个人简历用得上)合集 各种颁奖词收集 各种颁奖词收集 优秀党员 ...

  7. 十天内提高单词量到20000! (Vocabulary 10000)

    转自http://www.cnblogs.com/chenjunbiao/archive/2008/10/30/1760166.html Lesson 1 A monument was built t ...

  8. 计算机大赛的英语怎么说,最全英语奖项 比赛名称翻译.doc

    最全英语奖项 比赛名称翻译 最全英语奖项 比赛名称翻译 [做英文简历,留着备用]各种奖学金.比赛.社团.组织.荣誉称号英文翻译 一. 国家及校级奖项.称号 国家奖学金 National Scholar ...

  9. 计算机大赛搞笑队名,电子设计大赛队名

    篇一:电子设计竞赛报告格式要求 附件3 电子设计竞赛报告格式要求 封面: 作品名称:(黑体,二号) 申报者信息:(宋体,四号) 队员1:姓名,性别,出生年月,所在学院.专业.年级,教学号,邮箱,电话 ...

最新文章

  1. Keras保存和载入训练好的模型和参数
  2. 【PP操作手册】计划订单转生产订单
  3. 从 6 篇顶会论文看「知识图谱」领域最新研究进展 | 解读 代码
  4. PyTorch基础(part5)--交叉熵
  5. 用js检测文本框中输入的是否符合条件并有错误和正确提醒
  6. 工作233:定义有对话框的按钮
  7. html盒子有哪些属性,盒子模型有哪些属性 在html5中哪些元素具有盒子模型
  8. ADB启动或关闭APP
  9. 第五套人民币是大众收藏的机会
  10. 两个文件行合并linux,linux 两个文件合并
  11. 首席新媒体运营黎想教程:海报裂变活动怎么做?4个必备技巧
  12. Python 计算思维训练——数组和曲线绘制练习(一)
  13. 六、入门python第六课
  14. 鸢尾花分类(主成分分析)
  15. RTSP/Onvif安防网络摄像头无插件直播流媒体服务EasyNVR如何实现网络摄像机Onvif/RTSP接入直播与云台控制
  16. web项目经理手册-项目经理需要铭记在心...
  17. NOIP2017初赛试题
  18. 神经网络的图像识别技术,神经网络如何识别图像
  19. 磊科路由器信号按键_磊科无线路由器设置方法图解
  20. JDK1.7和JDK1.8下载

热门文章

  1. 北美跨境电商平台Wish透露未来一年在华规划
  2. Caused by: java.sql.SQLException: Access denied for user ‘root‘@‘localhost‘ (using password: YES)
  3. 电脑桌面图标右上角出现计算机名称如何取消,电脑桌面图标上的箭头看着太闹心?一段代码轻松去除!-电脑桌面图标有蓝色阴影怎么去掉...
  4. 读《人人都是产品经理》有感
  5. TIM561激光雷达读取和修改配置参数
  6. 教你如何轻松打开玻璃瓶的金属盖
  7. 以商品超卖为例讲解Redis分布式锁
  8. 使用 ODT 部署 Office 2013-2021/365
  9. 湖南省中职文化课普测计算机基础,桃源县职业中等专业学校2021年文化普测顺利完成...
  10. PS教程:多边形套索工具