需要包含的头文件
speechManager.h
代码如下:
#pragma once
#include <iostream>
#include <vector>
#include <map>
#include "speaker.h"
#include <algorithm>
#include <deque>
#include <functional>
#include <numeric>
#include <string>
#include <fstream>
using namespace std;
//设计演讲管理类
class SpeechManager {
public:
//构造函数
SpeechManager();
//开始比赛 比赛整个流程控制函数
void startSpeech();
//抽签
void speechDraw();
//比赛
void speechContest();
//显示比赛结果
void showScore();
//保存记录
void saveRecord();
//读取记录
void loadRecord();
//判断文件是否为空
bool fileIsEmpty;
//存放往届记录的容器
map<int, vector<string>> m_Record;
//显示往届记录
void showRecord();
//清空记录
void clearRecord();
//菜单功能
void show_Menu();
//退出系统
void exitSystem();
//析构函数
~SpeechManager();
//初始化容器和属性
void initSpeech();
//创建12名选手
void createSpeaker();
//成员属性
//保存第一轮比赛选手编号容器
vector<int> v1;
//第一轮晋级选手编号容器
vector<int> v2;
//胜出前三名选手编号容器
vector<int> vVictory;
//存放编号以及对应具体选手容器
map<int, Speaker> m_Speaker;
//存放比赛轮数
int m_Index;
};
speaker.h
代码如下:
#pragma once
#include <iostream>
#include <string>
using namespace std;
class Speaker {
public:
string m_Name; //姓名
double m_Score[2]; //分数,最多有两轮得分
};
需要的源文件
speechManager.cpp
代码如下:
#include "speechManager.h"
//构造函数
SpeechManager::SpeechManager() {
//初始化容器和属性
this->initSpeech();
//创建12名选手
this->createSpeaker();
//加载往届记录
this->loadRecord();
}
//开始比赛 比赛整个流程控制函数
void SpeechManager::startSpeech() {
//第一轮比赛开始
//1.抽签
this->speechDraw();
//2.比赛
this->speechContest();
//3.显示晋级结果
this->showScore();
//第二轮比赛开始
this->m_Index++;
//1.抽签
this->speechDraw();
//2.比赛
this->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