该代码是此项目的初步实现,仍然存在很多不妥之处,欢迎各位读者提供自己的改进意见!
我会结合大家的已经对项目进行改进,做出更好的项目!
- 引言
演讲比赛作为一种常见的学术或社交活动,对于管理和组织流程有着严格的要求。为了提高演讲比赛的效率和准确性,我们设计了一个基于C++的演讲比赛流程管理系统。该系统能够实现参赛者报名、随机抽题、计时和评分等功能,简化了比赛流程并提高了管理效率。
- 背景和需求分析
在传统的演讲比赛中,存在以下问题:
- 报名和抽题过程繁琐,工作量大。
- 计时和评分需要人工实时操作,有时容易出错。
- 数据统计和比赛结果生成耗时。
因此,我们的演讲比赛流程管理系统有以下主要需求:
- 参赛者能够通过系统进行报名和查询个人信息。
- 系统能够实现随机抽题、计时和评分等功能。
- 管理员能够对比赛流程进行管理和结果统计。
- 系统设计
基于以上需求,我们设计了如下系统模块:
- 参赛者模块:负责参赛者的报名和个人信息管理,包括注册、登录和查看个人成绩等功能。
- 比赛模块:负责比赛流程的管理,包括抽题、计时、评分和显示成绩等功能。
- 管理模块:负责管理员登录和对比赛流程进行管理和结果统计。
- 系统实现
我们使用C++语言进行系统开发,主要采用以下技术和方法:
- 面向对象编程思想:使用类和对象进行模块封装和功能实现。
- 随机数生成:通过C++的随机数库实现抽题功能。
- 文件读写操作:使用文件存储参赛者和成绩信息,实现数据的持久化。
- 用户界面设计:通过C++的图形库或命令行界面,实现用户友好的交互操作。
- 实验结果与分析
经过实际测试,我们的演讲比赛流程管理系统成功地实现了参赛者的报名、抽题、计时、评分和成绩展示等功能。系统操作简便,界面友好,大大提高了比赛流程的效率和准确性。通过结果统计功能,管理员能够方便地获取比赛数据和生成相关报告,便于管理和决策。
首先,程序会加载上次的比赛数据,还可以选择开始演讲比赛,查看往届记录或者清空比赛记录
比赛开始后,先抽签,决定演讲顺序并分组
然后每6人一组进行演讲,得到的分数由评委给出并计算平均分
第一轮的晋级选手再次抽签后得到下一轮的比赛选手
第二轮比赛后,取前三名为获胜者
在往届记录中可以查看
6. 总结与展望
本次开发了一个基于C++的演讲比赛流程管理系统,提高了比赛流程的管理效率和准确性。然而,系统仍然可以进一步改进,比如增加更多的功能模块,提供更多的统计和分析功能等。后续也希望读者提出宝贵的意见,我会进一步改进系统的用户界面,增加更多的功能模块,提高系统的稳定性和可扩展性。
总之,基于C++的演讲比赛流程管理系统是一项具有实际意义和应用前景的工作。通过不断优化和改进,该系统将在实际比赛中发挥更大的作用,提高比赛效率和管理水平。
项目代码:
speechmanager.h
#pragma once
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<deque>
#include<algorithm>
#include<functional>
#include<numeric>
#include<fstream>
#include"speaker.h"
using namespace std;
#define FILENAME "speech.csv"
//比较大小
//class Compare {
//public:
// bool operator()(double a, double b) {
// return a < b;
// }
//};
class SpeechManager {
public:
//成员属性
vector<int> v1; //保存第一轮比赛选手编号
vector<int> v2; //保存第二轮比赛选手编号
vector<int> vVectory; //保存前三名选手编号
map<int, Speaker> mSpeaker; //保存编号和选手的对应关系
map<int, vector<string>> mRecord; //存放往届记录的map
bool isFileEmpty; //判断文件是否为空
SpeechManager();
//菜单
void showMenu();
//初始化属性
void initSpeech();
//创建选手
void createSpeaker();
//开始比赛
void startSpeech();
//抽签
void speechDraw();
//比赛
void speechContest();
//显示得分
void showScore();
//保存文件
void saveScore();
//读取记录
void loadRecord();
//显示记录
void showRecord();
//清空记录
void clearRecord();
~SpeechManager();
private:
int roundIndex;
};
speechmanager.cpp
#include "speechmanager.h"
SpeechManager::SpeechManager() {
initSpeech(); //初始化容器属性
createSpeaker(); //创建12名选手
loadRecord(); //加载文件信息
}
void SpeechManager::showMenu() {
cout << "***********************************************************************" << endl;
cout << "************************ 演讲比赛管理系统 v1.0 *********************" << endl;
cout << "**************************** 1.开始演讲比赛 *************************" << endl;
cout << "**************************** 2.查看往届记录 *************************" << endl;
cout << "**************************** 3.清空比赛记录 *************************" << endl;
cout << "**************************** 0.退出管理系统 *************************" << endl;
cout << "***********************************************************************" << endl << endl;
cout << " 请输入选择[ ]\b\b";
}
void SpeechManager::initSpeech() {
this->v1.clear();
this->v2.clear();
this->vVectory.clear();
this->mSpeaker.clear();
this->mRecord.clear();
this->roundIndex = 1;
}
void SpeechManager::createSpeaker() {
string nameSeed = "ABCDEFGHIJKL";
for (int i = 0; i < nameSeed.size(); i++) {
string name = "选手";
name += nameSeed[i];
//创建具体选手
Speaker sp;
sp.speakerName = name;
sp.speakerScore[0] = sp.speakerScore[1] = 0;
this->v1.push_back(i + 10001);
this->mSpeaker.insert(make_pair(i + 10001, sp));
}
}
void SpeechManager::startSpeech() {
//1.第一轮开始比赛
//1.抽签
this->speechDraw();
//2.比赛
this->speechContest();
//3.显示晋级结果
this->showScore();
//第二轮比赛
this->roundIndex++;
//1.抽签
this->speechDraw();
//2.比赛
this->speechContest();
//3.显示最终结果
this->showScore();
//4.保存到文件中
this->saveScore();
cout << "本届比赛结束!" << endl;
//重置
initSpeech(); //初始化容器属性
createSpeaker(); //创建12名选手
loadRecord();
this->roundIndex = 1;
this->v2.clear();
this->vVectory.clear();
system("pause");
}
void SpeechManager::speechDraw(){
cout << "第" << this->roundIndex << "轮比赛选手正在抽签" << endl;
cout << "------------------" << endl;
cout << "抽签后演讲顺序如下:" << endl;
//打乱顺序
if (this->roundIndex == 1) {
//第一轮
random_shuffle(v1.begin(), v1.end());
for (vector<int>::iterator it = v1.begin(); it != v1.end(); it++)
cout << *it << " ";
} else {
//第二轮
random_shuffle(v2.begin(), v2.end());
for (vector<int>::iterator it = v2.begin(); it != v2.end(); it++)
cout << *it << " ";
}
cout << endl;
cout << "------------------" << endl << endl;
system("pause");
cout << endl;
}
void SpeechManager::speechContest() {
cout << "------------第 " << this->roundIndex << " 轮比赛正式开始------------" << endl;
//准备临时容器,存小组成绩,mutimap可以存放重复值
multimap<double, int, greater<double>> groupScore;
int num = 0; //记录人员个数
vector<int> vContest;
if (this->roundIndex == 1) vContest = v1;
else vContest = v2;
//遍历所有选手进行比赛
for (vector<int>::iterator it = vContest.begin(); it != vContest.end(); it++) {
//对每个选手,10个评委打分
deque<double> d;
for (int i = 0; i < 10; i++) {
double score = (rand() % 401 + 600) / 10.f; //600-1000
//cout << score << " ";
d.push_back(score);
}
//对评委的打分进行排序
//sort(d.begin(), d.end(), Compare()); //第三个参数是一个谓词
sort(d.begin(), d.end(), greater<double>()); //这里使用的是内建函数,需要引用头文件function
d.pop_front(); //去除最高分
d.pop_back(); //去除最低分
double sum = accumulate(d.begin(), d.end(), 0.f); //累加得到总分
//cout << sum << endl << endl;
double avg = sum / (double)d.size(); //平均分
//将平均分放到map容器中
this->mSpeaker[*it].speakerScore[this->roundIndex - 1] = avg;
//将打分数据放到临时小组容器中
groupScore.insert(make_pair(avg, *it)); //key是得分,value是选手编号
num++;
//每6人取出前三名
if (num % 6 == 0) {
cout << "第 " << num / 6 << " 小组比赛名次:" << endl;
for (multimap<double, int, greater<double>>::iterator it1 = groupScore.begin(); it1 != groupScore.end(); it1++) {
cout << "编号:" << it1->second << " 姓名:" << this->mSpeaker[it1->second].speakerName
<< " 分数:" << this->mSpeaker[it1->second].speakerScore[this->roundIndex - 1] << endl;
}
//取走前三名
int cnt = 0;
for (multimap<double, int, greater<double>>::iterator it2 = groupScore.begin(); it2 != groupScore.end() && cnt < 3; it2++, cnt++) {
if (this->roundIndex == 1) v2.push_back((*it2).second);
else vVectory.push_back((*it2).second);
}
groupScore.clear();
cout << endl;
}
}
cout << "------------第" << this->roundIndex << "轮比赛结束------------" << endl;
system("pause");
cout << endl;
}
void SpeechManager::showScore() {
cout << "------------第" << this->roundIndex << "轮晋级选手成绩如下:" << endl;
vector<int> vTemp;
if (this->roundIndex == 1) vTemp = v2;
else vTemp = vVectory;
//迭代输出信息
for (vector<int>::iterator it = vTemp.begin(); it != vTemp.end(); it++) {
cout << "选手编号:" << *it << " 姓名:" << this->mSpeaker[*it].speakerName
<< " 得分:" << this->mSpeaker[*it].speakerScore[this->roundIndex - 1] << endl;
}
system("pause");
cout << endl;
}
void SpeechManager::saveScore() {
ofstream ofs("speech.csv", ios::out | ios::app);
//遍历打印每个选手的数据到文件中
for (vector<int>::iterator it = vVectory.begin(); it != vVectory.end(); it++) {
ofs << *it << "," << this->mSpeaker[*it].speakerScore[this->roundIndex - 1] << ",";
}
ofs << endl;
cout << "本届比赛已保存" << endl;
}
void SpeechManager::loadRecord() {
ifstream ifs("speech.csv", ios::in);
//若文件不存在
if (!ifs.is_open()) {
this->isFileEmpty = true;
cout << "文件不存在" << endl;
ifs.close();
return;
}
//判断文件是否为空
char ch;
ifs >> ch;
if (ifs.eof()) {
cout << "文件为空" << endl;
this->isFileEmpty = true;
ifs.close();
return;
}
//若文件不为空
this->isFileEmpty = false;
ifs.putback(ch); //将上面读取的字符再放回来
string data;
//读取每一行的数据
int index = 0; //记录第几届
while (ifs >> data) {
vector<string> v; //获取每一届比赛的数据
//利用字符串的截取
int pos = -1, 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;
}
//将获取到的这一届的数据放到map中
this->mRecord.insert(make_pair(index, v));
v.clear();
index++;
}
ifs.close();
this->isFileEmpty = false;
遍历冠军信息
//for (map<int, vector<string>>::iterator it = mRecord.begin(); it != mRecord.end(); it++) {
// cout << it->first + 1 << " 冠军编号:" << it->second[0] << " 分数:" << it->second[1] << endl;
//}
}
void SpeechManager::showRecord() {
loadRecord();
for (map<int, vector<string>>::iterator it = mRecord.begin(); it != mRecord.end(); it++) {
cout << "第" << it->first + 1 << "届 冠军编号:" << it->second[0]
<< " 分数:" << it->second[1]
<< " 亚军编号:" << it->second[2] << " 分数:" << it->second[3]
<< " 季军编号:" << it->second[4] << " 分数:" << it->second[5] << endl;
}
system("pause");
}
void SpeechManager::clearRecord() {
cout << "确定清空吗?" << endl;
cout << "1.确定" << endl;
cout << "2.返回" << endl;
int choice;
cin >> choice;
if (choice == 1) {
ofstream ofs(FILENAME, ios::trunc);
ofs.close();
initSpeech(); //初始化容器属性
createSpeaker(); //创建12名选手
loadRecord(); //加载文件信息
cout << "清空成功!" << endl;
}
system("pause");
}
SpeechManager::~SpeechManager() {
}
speaker.h
#pragma once
#include<iostream>
#include<string>
using namespace std;
class Speaker {
public:
string speakerName; //选手姓名
double speakerScore[2]; //选手成绩
Speaker();
~Speaker();
private:
};
main.cpp
#include<iostream>
#include<time.h>
#include"speechmanager.h"
using namespace std;
int main() {
srand((unsigned int)time(NULL));
int choice = 0; //存储用户的选择项
SpeechManager sm;
//for (map<int, Speaker>::iterator it = sm.mSpeaker.begin(); it != sm.mSpeaker.end(); it++) {
// cout << "选手编号:" << it->first << "姓名:" << it->second.speakerName << "分数" << it->second.speakerScore[0] << endl;
//}
while (1) {
sm.showMenu();
cin >> choice; //接收用户的选择
switch (choice) {
case 0: //退出系统
cout << "欢迎下次使用!" << endl;
system("pause");
exit(0);
break;
case 1: //开始演讲比赛
sm.startSpeech();
break;
case 2: //查看往届记录
sm.showRecord();
break;
case 3: //清空比赛记录
sm.clearRecord();
break;
default:
break;
}
system("cls");
}
return 0;
}