C++演講比賽管理系統(tǒng)實(shí)現(xiàn)流程實(shí)例
演講比賽系統(tǒng)
1.需求分析
- 學(xué)校舉行一場(chǎng)比賽,共有12人參加。比賽共兩輪,第一輪為淘汰賽,第二輪為決賽。
- 每名選手都有對(duì)應(yīng)的編號(hào):如10001~10012。
- 比賽方式:分組比賽,每組6個(gè)人。
- 第一輪分為兩個(gè)小組,整體按照選手的編號(hào)進(jìn)行抽簽后順序演講。
- 十個(gè)評(píng)委分別給每名選手打分,去除最高分和最低分,求的平均分為本輪選手的成績(jī)。
- 當(dāng)小組演講完后,淘汰組內(nèi)排名最后的三名選手,前三名晉級(jí),進(jìn)入下一輪的比賽。
- 第二輪為決賽,前三名勝出。
- 每輪比賽過后需要顯示晉級(jí)選手的信息。
2.程序和功能
| 程序 | 功能 |
|---|---|
| 開始演講比賽 | 完成整屆比賽的流程,每個(gè)比賽階段需要給用戶一個(gè)提示,用戶按任意鍵進(jìn)入下一個(gè)階段。 |
| 查看往屆記錄 | 查看之前比賽的前三名,每次比賽都會(huì)記錄到文件中,文件用.csv后綴名保存。 |
| 清空比賽記錄 | 將文件中的數(shù)據(jù)清空。 |
| 退出比賽程序 | 可以退出程序。 |
3.程序邏輯
3.1建立演講比賽管理類
void SaveRecord(); //初始化 void InitSpeech(); //判斷文件是否為空 bool File_Is_Empty; //往屆數(shù)據(jù)的容器 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(); //創(chuàng)建輪數(shù) int Revolution; //第一輪比賽人員編號(hào) vector<int>v1; //第二輪比賽人數(shù)編號(hào) vector<int>v2; //獲勝人編號(hào) vector<int>vVictory; //存放編號(hào)和對(duì)應(yīng)具體選手的容器 map<int, Speaker>M_Speker; //存放屆數(shù) };
3.2開始演講比賽程序
比賽流程分析:
抽簽—>開始第一輪演講比賽—>顯示第一輪比賽結(jié)果—>抽簽—>開始第二論比賽—>
顯示前三名結(jié)果—>保存分?jǐn)?shù)。
void Speech_Manager::SpeechConst()
{
/*srand((unsigned int)time(NULL));*/
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容器當(dāng)中
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 << "編號(hào):" << it->second << "姓名:" << this->M_Speker[it->second].M_Name
<< "成績(jī):" << 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 << "輪比賽結(jié)束-------------" << endl;
system("pause");
}
void Speech_Manager::ShowScore()
{
cout << "-------------第" << this->Revolution << "輪晉級(jí)選手信息如下:----------" << 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 << "選手編號(hào):" << *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查看往屆比賽結(jié)果程序
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 << "屆比賽結(jié)果如下:" << endl;
cout << "冠軍編號(hào):" << 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 << "亞軍編號(hào):" << 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 << "季軍編號(hào):" << 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.否認(rèn)" << endl;
int select = 0;
cin >> select;
if (select == 1)
{
//確認(rèn)清空
ofstream ofs("File_Name.txt",ios::trunc);
ofs.close();
this->InitSpeech();
this->CreatSpeaker();
//加載往屆記錄
this->LoadRecod();
cout << "清空成功" << endl;
}
system("pause");
system("cls");
}3.5等待程序和隨機(jī)產(chǎn)生姓名程序
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 << "正在抽簽,請(qǐng)等待" << endl;
}
}
string Speech_Manager::CreatName(int a)//a隨機(jī)次數(shù),a不同導(dǎo)致不同結(jié)果。
{
string name;
string NA1[] = { "趙", "錢", "孫", "李", "周", "吳", "鄭", "王", "馮", "陳", "褚", "衛(wèi)", "蔣" };
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
到此這篇關(guān)于C++演講比賽管理系統(tǒng)實(shí)現(xiàn)流程實(shí)例的文章就介紹到這了,更多相關(guān)C++演講比賽管理內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
詳解C語(yǔ)言結(jié)構(gòu)體中的char數(shù)組如何賦值
這篇文章主要給大家介紹了關(guān)于C語(yǔ)言結(jié)構(gòu)體中的char數(shù)組如何賦值的相關(guān)資料,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下2022-03-03
C++通過共享內(nèi)存ShellCode實(shí)現(xiàn)跨進(jìn)程傳輸
在計(jì)算機(jī)安全領(lǐng)域,ShellCode是一段用于利用系統(tǒng)漏洞或執(zhí)行特定任務(wù)的機(jī)器碼,本文主要為大家介紹了C++如何通過共享內(nèi)存ShellCode實(shí)現(xiàn)跨進(jìn)程傳輸,需要的可以參考下2023-12-12
圖文詳解C語(yǔ)言位運(yùn)算基礎(chǔ)知識(shí)
這篇文章主要以圖文結(jié)合的方式為大家詳細(xì)介紹了C語(yǔ)言位運(yùn)算基礎(chǔ)知識(shí),感興趣的小伙伴們可以參考一下2016-07-07
關(guān)于VS2022不能使用<bits/stdc++.h>的解決方案(萬(wàn)能頭文件)
#include<bits/stdc++.h>包含了目前 C++ 所包含的所有頭文件,又稱萬(wàn)能頭文件,那么如何在VS2022中使用萬(wàn)能頭呢?下面小編給大家代理了關(guān)于VS2022不能使用<bits/stdc++.h>的解決方案(萬(wàn)能頭文件),感興趣的朋友一起看看吧2022-03-03
使用C語(yǔ)言編寫一個(gè)關(guān)機(jī)惡搞小程序
system函數(shù)的參數(shù)是"shutdown"時(shí),它將會(huì)執(zhí)行系統(tǒng)的關(guān)機(jī)命令,所以本文將利用這一特點(diǎn)制作一個(gè)關(guān)機(jī)惡搞小程序,感興趣的小伙伴可以跟隨小編一起學(xué)習(xí)一下2024-02-02
C++類與對(duì)象及構(gòu)造函數(shù)析構(gòu)函數(shù)基礎(chǔ)詳解
這篇文章主要為大家介紹了C++類與對(duì)象及構(gòu)造函數(shù)析構(gòu)函數(shù)基礎(chǔ)詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2023-04-04
在Visual Studio Code中使用CSSComb格式化CSS文件的教程
這篇文章主要介紹了在Visual Studio Code中使用CSSComb格式化CSS文件,本文通過實(shí)例代碼給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2020-03-03

