演讲比赛流程管理系统
比赛规则
- 学校举行一场演讲比赛,共有12个人参加。比赛共两轮,第一轮为淘汰赛,第二轮为决赛。
- 比赛方式:分组比赛,每组6个人;选手每次要随机分组,进行比赛
- 每名选手都有对应的编号,如 10001 ~ 10012
- 第一轮分为两个小组,每组6个人。 整体按照选手编号进行抽签后顺序演讲。
- 当小组演讲完后,淘汰组内排名最后的三个选手,前三名晋级,进入下一轮的比赛。
- 第二轮为决赛,前三名胜出
- 每轮比赛过后需要显示晋级选手的信息
程序功能
- 开始演讲比赛:完成整届比赛的流程,每个比赛阶段需要给用户一个提示,用户按任意键后继续下一个阶段
- 查看往届记录:查看之前比赛前三名结果,每次比赛都会记录到文件中,文件用.csv后缀名保存
- 清空比赛记录:将文件中数据清空
- 退出比赛程序:可以退出当前程序
- 代码: speaker.h :
#pragma once #include using namespace std; //选手类 class Speaker { public: string m_Name; //姓名 double m_Score[2]; //分数 最多有两轮得分 };
speechManager.h :#pragma once #include using namespace std; #include #include
speechManager.cpp :
#include "speechManager.h" //构造函数 SpeechManager::SpeechManager() { //初始化容器和属性 this->initSpeech(); //创建12名选手 this->createSpeaker(); //加载往届记录 this->loadRecord(); } //菜单功能 void SpeechManager::show_Menu() { cout << "********************************************" << endl; cout << "************* 欢迎参加演讲比赛 ************" << endl; cout << "************* 1.开始演讲比赛 *************" << endl; cout << "************* 2.查看往届记录 *************" << endl; cout << "************* 3.清空比赛记录 *************" << endl; cout << "************* 0.退出比赛程序 *************" << endl; cout << "********************************************" << endl; cout << endl; } //退出系统 void SpeechManager::exitSystem() { cout << "欢迎下次使用" << endl; system("pause"); exit(0); } void SpeechManager::initSpeech() { //容器都置空 this->v1.clear(); this->v2.clear(); this->vVictory.clear(); this->m_Speaker.clear(); //初始化比赛轮数 this->m_Index = 1; //将记录的容器 也清空 this->m_Record.clear(); } //创建12名选手 void SpeechManager::createSpeaker() { string nameSeed = "ABCDEFGHIJKL"; for (int i = 0; i < nameSeed.size(); i++) { string name = "选手"; name += nameSeed[i]; //创建具体选手 Speaker sp; sp.m_Name = name; for (int j = 0; j < 2; j++) { sp.m_Score[j] = 0; } //创建选手编号 并且放入到v1容器中 this->v1.push_back(i + 10001); //选手编号以及对应选手 放入到map容器中 this->m_Speaker.insert(make_pair(i + 10001, sp)); } } //开始比赛 比赛整个流程控制函数 void SpeechManager::startSpeech() { //第一轮开始比赛 //1、抽签 this->speechDraw(); //2、比赛 this->speechContest(); //3、显示晋级结果 this->showScore(); //第二轮开始比赛 this->m_Index++; //1、抽签 this->speechDraw(); //2、比赛 speechContest(); //3、显示最终结果 this->showScore(); //4、保存分数到文件中 this->saveRecord(); //重置比赛 ,获取记录 //初始化容器和属性 this->initSpeech(); //创建12名选手 this->createSpeaker(); //加载往届记录 this->loadRecord(); cout << "本届比赛完毕!" << endl; system("pause"); system("cls"); } //抽签 void SpeechManager::speechDraw() { cout << "第 << " << this->m_Index << " >> 轮比赛选手正在抽签" << endl; cout << "--------------------------" << endl; cout << "抽签后演讲顺序如下: " << endl; if (this->m_Index == 1) { //第一轮比赛 random_shuffle(v1.begin(), v1.end()); for (vector::iterator it = v1.begin(); it != v1.end(); it++) { cout << *it << " "; } cout << endl; } else { //第二轮比赛 random_shuffle(v2.begin(), v2.end()); for (vector::iterator it = v2.begin(); it != v2.end(); it++) { cout << *it << " "; } cout << endl; } cout << "--------------------------" << endl; system("pause"); cout << endl; } //比赛 void SpeechManager::speechContest() { cout << "----------- 第" << this->m_Index << " 轮比赛正式开始 --------------" << endl; //准备临时容器 存放小组成绩 multimap
演讲比赛流程管理系统.cpp :
#include using namespace std; #include "speechManager.h" #include #include int main() { //随机数种子 srand((unsigned int)time(NULL)); //创建管理类对象 SpeechManager sm; //测试12名选手创建 //for (map
运行效果:
最后欢迎大家访问我的个人博客青蛙听禅的个人博客