#include <iostream>
#include <vector>
#include"speech_manage_sys.h"
#include <algorithm>
int main()
{
while (1)
{
speech_manage_sys sms;
sms.showmaue();
int select;
cout << "请输入您的选择" << endl;
cin >> select;
cout << "您的选择是:" << select << endl;
switch (select)
{
case 1:
sms.start_speech();
break;
case 2:
sms.show_record();
break;
case 3:
sms.clear_record();
break;
case 4:
cout << "退出系统,欢迎下次使用!" << endl;
return 0;
break;
default:
system("cls");
cout << "您的选择是无效的!请您重新输入。" << select << endl;
break;
}
}
system("pause");
return 0;
}
#pragma once
#include<iostream>
#include<vector>
#include<map>
#include"speaker.h"
using namespace std;
class speech_manage_sys {
public:
vector<int> v1;
vector<int> v2;
vector<int> v_Victor;
map<int, speaker> m_speaker;
int m_index;
speech_manage_sys();
~speech_manage_sys();
void showmaue();
void init_speech();
void create_speaker();
void start_speech();
void draw_speech();
void contest_speech();
void showscore();
void save_record();
void read_record();
map<int, vector<string>> msp;
void show_record();
void clear_record();
};
#include<iostream>
#include<algorithm>
#include"speech_manage_sys.h"
#include<vector>
#include<deque>
#include<numeric>
#include<functional>
#include<fstream>
#include<map>
using namespace std;
speech_manage_sys::speech_manage_sys()
{
this->init_speech();
create_speaker();
}
speech_manage_sys::~speech_manage_sys()
{
}
void speech_manage_sys::init_speech()
{
v1.clear();
v2.clear();
v_Victor.clear();
m_speaker.clear();
m_index=1;
}
void speech_manage_sys::showmaue()
{
cout<< " **************" << endl
<< " ***欢迎您参加比赛***" <<endl;
cout<< " ****1.开始演讲比赛****" << endl
<< "*****2.查看往届记录*****" << endl
<< " ****3.清空比赛记录****" << endl
<< " ***4.退出演讲比赛***" << endl;
cout<< " **************" << endl;
}
void speech_manage_sys::create_speaker()
{
string nameseed = "ABCDEFGHIJKL";
for (int i = 0; i < 12; i++)
{
string name = "选手";
name += nameseed[i];
speaker sp;
sp.name = name;
int speakerid = 10001 + i;
v1.push_back(speakerid);
m_speaker.insert(make_pair(speakerid, sp));
}
}
void speech_manage_sys::contest_speech()
{
cout << "第"<<this->m_index <<"轮比赛正式开始!" << endl;
cout << endl;
multimap<double, int, greater<double>> groupscore;
int num=0;
vector<int> vec;
if (this->m_index == 1)
{
vec = v1;
}
else
{
vec = v2;
}
for (vector<int> ::iterator it = vec.begin(); it != vec.end(); it++)
{
num++;
deque<int> d_score;
for (int i = 0; i < 10; i++)
{
double score = (rand() % 401 + 600) / 10.f;
d_score.push_back(score);
}
sort(d_score.begin(), d_score.end(),greater<double>());
d_score.pop_back();
d_score.pop_front();
double total_score = accumulate(d_score.begin(), d_score.end(),0.0f);
double everage_score = total_score/(double)d_score.size();
this->m_speaker[*it].secore[this->m_index - 1] = everage_score;
groupscore.insert(make_pair(everage_score, *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_speaker[it->second].name
<< "分数:"<< this->m_speaker[it->second].secore[this->m_index - 1 ]<<endl;
}
int count = 0;
for (multimap<double, int, greater<double>>::iterator it = groupscore.begin();
it != groupscore.end()&&count<3; it++, count++)
{
if (this->m_index == 1)
{
v2.push_back((*it).second);
}
else
{
v_Victor.push_back((*it).second);
}
}
groupscore.clear();
cout << endl;
}
}
cout << endl;
}
void printspeak(int val)
{
cout << val<<" ";
}
void speech_manage_sys::draw_speech()
{
cout << "第" << this->m_index << "轮比赛的选手正在抽签" << endl;
cout << "----------------------------------------------" << endl;
if (this->m_index == 1)
{
random_shuffle(v1.begin(),v1.end());
cout << "抽签后的比赛次序为:" << " ";
for_each(v1.begin(), v1.end(),printspeak);
}
else
{
random_shuffle(v2.begin(), v2.end());
for_each(v2.begin(), v2.end(), printspeak);
}
cout << endl;
cout << "----------------------------------------------" << endl;
cout << endl;
}
void speech_manage_sys::showscore()
{
cout << "第" <<this->m_index<< "轮晋级的选手如下:" << endl;
vector<int> v;
if (this->m_index == 1)
{
v = this->v2;
}
else
{
v = this->v_Victor;
}
for (vector<int>::iterator it = v.begin(); it != v.end(); it++)
{
cout << "选手编号为:" << *it << "选手姓名为:" << this->m_speaker[*it].name<< "选手得分为:"
<< this->m_speaker[*it].secore[this->m_index-1] << endl;
}
cout << endl;
system("pause");
system("cls");
this->showmaue();
}
void speech_manage_sys::start_speech()
{
cout << "开始第一轮比赛" << endl;
this->draw_speech();
this->contest_speech();
this->showscore();
this->m_index++;
cout << "开始第二轮比赛" << endl;
this->draw_speech();
this->contest_speech();
this->showscore();
this->save_record();
}
void speech_manage_sys::save_record()
{
ofstream ofs;
ofs.open("contest_record.csv", ios::out | ios::app);
for (vector<int>::iterator v_it = this->v_Victor.begin(); v_it != this->v_Victor.end(); v_it++)
{
ofs << *v_it << ","
<< this->m_speaker[*v_it].secore[1] << ",";
}
ofs << endl;
ofs.close();
}
void speech_manage_sys::read_record()
{
ifstream ifs;
ifs.open("contest_record.csv", ios::in);
if (ifs.is_open())
{
char ch;
ifs >> ch;
if (ifs.eof())
{
cout << "比赛记录文件为空!" << endl;
ifs.close();
}
else
{
ifs.putback(ch);
string data;
int index = 0;
while (ifs >> data)
{
vector<string> v;
int pos = -1;
int start = 0;
while (1)
{
pos = data.find(",", start);
if (pos == -1)
{
break;
}
string temp = data.substr(start, pos - start);
v.push_back(temp);
start = pos + 1;
}
this->msp.insert(make_pair(index, v));
index++;
}
ifs.close();
}
}
else
{
cout << "无比赛记录文件!" << endl;
ifs.close();
}
}
void speech_manage_sys::show_record()
{
this->read_record();
for (map<int, vector<string>>::iterator m_it = msp.begin(); m_it != msp.end(); m_it++)
{
cout << (*m_it).first <<" "
<< (*m_it).second[0] <<" "<< (*m_it).second[1] << " " << (*m_it).second[2] << " "
<<(*m_it).second[3] << " " << (*m_it).second[4] << " " << (*m_it).second[5] << " "
<<endl;
}
}
void speech_manage_sys::clear_record()
{
ofstream ofs;
ofs.open("contest_record.csv", ios::out);
ofs << " ";
ofs.close();
}
#pragma once
#include <iostream>
#include <string>
using namespace std;
class speaker
{
public:
string name;
double secore[2];
speaker();
~speaker();
};
#include "speaker.h"
#include <iostream>
speaker::speaker()
{
this->name = "*";
secore[0] = secore[1] = 0;
}
speaker::~speaker()
{
}