演讲比赛系统
1.需求分析
- 学校举行一场比赛,共有12人参加。比赛共两轮,第一轮为淘汰赛,第二轮为决赛。
- 每名选手都有对应的编号:如10001~10012。
- 比赛方式:分组比赛,每组6个人。
- 第一轮分为两个小组,整体按照选手的编号进行抽签后顺序演讲。
- 十个评委分别给每名选手打分,去除最高分和最低分,求的平均分为本轮选手的成绩。
- 当小组演讲完后,淘汰组内排名最后的三名选手,前三名晋级,进入下一轮的比赛。
- 第二轮为决赛,前三名胜出。
- 每轮比赛过后需要显示晋级选手的信息。
2.程序和功能
程序 | 功能 |
---|---|
开始演讲比赛 | 完成整届比赛的流程,每个比赛阶段需要给用户一个提示,用户按任意键进入下一个阶段。 |
查看往届记录 | 查看之前比赛的前三名,每次比赛都会记录到文件中,文件用.csv后缀名保存。 |
清空比赛记录 | 将文件中的数据清空。 |
退出比赛程序 | 可以退出程序。 |
3.程序逻辑
3.1建立演讲比赛管理类
void SaveRecord();
//初始化
void InitSpeech();
//判断文件是否为空
bool File_Is_Empty;
//往届数据的容器
map<int, vector<string>>M_Record;
~Speech_Manager();
void CreatSpeaker();
string CreatName(int a);
void ShowScore();
void Wait_Revolution();
//往届记录
void ShowRecord();
//清空记录
void ClearRecord();
//读取记录
void LoadRecod();
//创建轮数
int Revolution;
//第一轮比赛人员编号
vector<int>v1;
//第二轮比赛人数编号
vector<int>v2;
//获胜人编号
vector<int>vVictory;
//存放编号和对应具体选手的容器
map<int, Speaker>M_Speker;
//存放届数
};
3.2开始演讲比赛程序
比赛流程分析:
抽签—>开始第一轮演讲比赛—>显示第一轮比赛结果—>抽签—>开始第二论比赛—>
显示前三名结果—>保存分数。
void Speech_Manager::SpeechConst()
{
cout << "----------------第" << this->Revolution << "轮比赛开始-----------------" << endl;
multimap<double, int, greater<double>>GroupScore;
int num = 0;
vector<int>V_src;//参赛容器
if (this->Revolution == 1)
{
V_src = v1;
}
else
{
V_src = v2;
}
//遍历选手
for (vector<int>::iterator it = V_src.begin(); it != V_src.end(); it++)
{
num++;
deque<double>d;
for (int i = 0; i < 10; i++)
{
double score = (rand() % 401 + 600) / 10.f;
d.push_back(score);
}
sort(d.begin(), d.end(), greater<double>());//降序排列
d.pop_front();
d.pop_back();
double sum = accumulate(d.begin(), d.end(), 0.0f);
double average = sum / (double)d.size();//平均分
//将平均分放入到map容器当中
this->M_Speker[*it].M_Score[this->Revolution - 1] = average;
GroupScore.insert(make_pair(average, *it));
if (num % 6 == 0)
{
cout << "第" << num / 6 << "小组比赛名次如下:" << endl;
for (multimap<double, int, greater<double>>::iterator it = GroupScore.begin(); it != GroupScore.end(); it++)
{
cout << "编号:" << it->second << "姓名:" << this->M_Speker[it->second].M_Name
<< "成绩:" << this->M_Speker[it->second].M_Score[this->Revolution - 1] << endl;
}
int count = 0;
for (multimap<double, int, greater<double>>::iterator it = GroupScore.begin(); it != GroupScore.end()&&count<3; it++,count++)
{
if (this->Revolution == 1)
{
v2.push_back((*it).second);
}
else
{
vVictory.push_back((*it).second);
}
}
GroupScore.clear();
cout << endl;
}
}
cout << "-------------第" << this->Revolution << "轮比赛结束-------------" << endl;
system("pause");
}
void Speech_Manager::ShowScore()
{
cout << "-------------第" << this->Revolution << "轮晋级选手信息如下:----------" << endl;
vector<int>v;
if (this->Revolution == 1)
{
v = v2;
}
else
{
v = vVictory;
}
for (vector<int>::iterator it = v.begin(); it != v.end(); it++)
{
cout << "选手编号:" << *it << "性别:" << this->M_Speker[*it].M_Sex << "姓名:" << this->M_Speker[*it].M_Name
<< "得分:" << this->M_Speker[*it].M_Score[this->Revolution - 1] << endl;
}
cout << endl;
system("pause");
system("cls");
this->ShowmMenu();
}
3.3查看往届比赛结果程序
void Speech_Manager::ShowRecord()
{
if (this->File_Is_Empty)
{
cout << "显示失败!文件为空或者不存在!";
}
else
{
for (int i = 0; i < this->M_Record.size(); i++)
{
//cout << this->M_Record.size();
cout << "第" << i + 1 << "届比赛结果如下:" << endl;
cout << "冠军编号:" << this->M_Record[i][0] << "\t"<<" 姓名:" << this->M_Record[i][1]
<< "\t" <<"性别:" <<this->M_Record[i][2] << "\t" <<"得分:"<< this->M_Record[i][3] <<endl;
cout << "亚军编号:" << this->M_Record[i][4] << "\t" << " 姓名:" << this->M_Record[i][5]
<< "\t" << "性别:" << this->M_Record[i][6] << "\t" << "得分:" << this->M_Record[i][7] << endl;
cout << "季军编号:" << this->M_Record[i][8] << "\t" << " 姓名:" << this->M_Record[i][9]
<< "\t" << "性别:" << this->M_Record[i][10] << "\t" << "得分:" << this->M_Record[i][11] << endl;
}
}
system("pause");
system("cls");
}
3.4清空记录
void Speech_Manager::ClearRecord()
{
cout << "是否清空文件记录" << endl;
cout << "1.确定" << endl;
cout << "2.否认" << endl;
int select = 0;
cin >> select;
if (select == 1)
{
//确认清空
ofstream ofs("File_Name.txt",ios::trunc);
ofs.close();
this->InitSpeech();
this->CreatSpeaker();
//加载往届记录
this->LoadRecod();
cout << "清空成功" << endl;
}
system("pause");
system("cls");
}
3.5等待程序和随机产生姓名程序
oid Speech_Manager::Wait_Revolution()
{
for (int i = 0; i < 3; i++)
{
cout << "Wait ";
for (int j = 0; j < 3; j++)
{
Sleep(1500);
cout << " * ";
}
system("cls");
cout << "正在抽签,请等待" << endl;
}
}
string Speech_Manager::CreatName(int a)//a随机次数,a不同导致不同结果。
{
string name;
string NA1[] = { "赵", "钱", "孙", "李", "周", "吴", "郑", "王", "冯", "陈", "褚", "卫", "蒋" };
string NA2[] = { "伟", "刚", "勇", "毅", "俊", "峰","秀", "娟", "英", "华", "慧" };
srand((unsigned int)(time)(NULL));
for (int i = 0; i < a; i++)
{
name = NA1[rand() % (sizeof(NA1) / sizeof(NA1[0]))];
name += NA2[rand() % (sizeof(NA2) / sizeof(NA2[0]))];
}
return name;
}
4.程序下载
链接: https://pan.baidu.com/s/1f-43Ne9MWCU1kYstJfU5Xg?pwd=nswe
提取码: nswe
到此这篇关于C++演讲比赛管理系统实现流程实例的文章就介绍到这了,更多相关C++演讲比赛管理内容请搜索编程网以前的文章或继续浏览下面的相关文章希望大家以后多多支持编程网!