演讲比赛流程管理系统

#pragma once
#include<iostream>
#include<string>
using namespace std;

class Speaker {
public:
	string name;

	double score[2];
};
#pragma once
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<algorithm>
#include<deque>
#include<numeric>
#include<fstream>
#include"Speaker.h"
using namespace std;

class Manager {
public:
	vector<int> v1;
	vector<int> v2;
	vector<int> v3;
	map<int, Speaker>mp;
	int index;
	bool failIsEmpty;
	map<int, vector<string>>mpRecord;

	Manager();
	void showMenu();
	void exitSystem();
	void Init();
	void createSpeaker();
	void speechDraw();
	void startSpeech();
	void speechContest();
	void showScore();
	void saveRecord();
	void loadRecord();
	void showRecord();
	void clearRecord();



	~Manager();
};
#pragma once
#include"Manager.h"

Manager::Manager() {
	Init();
	createSpeaker();
	loadRecord();
}
Manager::~Manager() {

}
void Manager::showMenu() {
	cout << "********************************" << endl;
	cout << "*       欢迎参加演讲比赛       *" << endl;
	cout << "*       1.开始演讲比赛         *" << endl;
	cout << "*       2.查看往届记录         *" << endl;
	cout << "*       3.清空比赛记录         *" << endl;
	cout << "*       0.退出比赛程序         *" << endl;
	cout << "********************************" << endl;
	cout << endl;
	
}
void Manager::exitSystem() {
	cout << "您确认退出吗?" << endl;
	cout << "1.确认    2.取消" << endl;
	int select;
	cin >> select;
	if (select == 2) {
		system("cls");
	}
	if (select == 1)
	{
		cout << "退出成功,感谢使用!!!" << endl;
		exit(0);
	}
}
void Manager::Init() {
	this->v1.clear();
	this->v2.clear();
	this->v3.clear();
	this->mp.clear();
	this->index = 1;
}

void Manager::createSpeaker() {
	string nameSeed = "ABCDEFGHIJKL";
	for (int i = 0; i < nameSeed.size(); i++) {
		string name = "选手";
		name += nameSeed[i];
		Speaker sp;
		sp.name = name;
		for (int j = 0; j < 2; j++) {
			sp.score[j] = 0;
		}
		this->v1.push_back(i+1001);
		this->mp.insert(make_pair(i + 1001, sp));
	}
}

void Manager::speechDraw() {
	cout << "              第<<" << this->index << ">>轮比赛选手正在抽签" << endl;
	cout << "------------------------------------------------------------" << endl;
	cout << "                  抽签演讲顺序如下:" << endl;
	if (this->index == 1) {
		random_shuffle(v1.begin(), v1.end());
		for (vector<int>::iterator it = v1.begin(); it != v1.end(); it++) {
			cout << *it << " ";
		}
		cout << endl;
	}
	else {
		random_shuffle(v2.begin(), v2.end());
		for (vector<int>::iterator it = v2.begin(); it != v2.end(); it++) {
			cout << *it << " ";
		}
		cout << endl;
	}
	cout << "------------------------------------------------------------" << endl;
	system("pause");
	cout << endl;

}

void Manager::startSpeech() {
	speechDraw();
	speechContest();
	showScore();
	this->index++;
	speechDraw();
	speechContest();
	showScore();
	saveRecord();
	cout << "本届比赛完毕!!!" << endl;
	system("pause");
	system("cls");
}

void Manager::speechContest() {
	cout << "------------------------------------------第" << this->index << "轮比赛开始------------------------------------------" << endl;
	cout << "---------------------------------------------得分如下--------------------------------------------" << endl;
	vector<int>v;
	multimap<double, int, greater<double>> groupMp;
	int numPer = 0;
	if (this->index == 1) {
		v = v1;
	}
	else
	{
		v = v2;
	}
	for (vector<int>::iterator it = v.begin(); it != v.end(); it++) {
		numPer++;
		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_back();
			d.pop_front();
			double sum = accumulate(d.begin(), d.end(), 0.0f);
			double avg = sum / (double)d.size();
			this->mp[*it].score[this->index - 1] = avg;
			groupMp.insert(make_pair(avg, *it));
			if (numPer % 6 == 0) {
				cout << "第" << numPer / 6 << "小组比赛名次:" << endl;
				for (multimap<double, int, greater<double>>::iterator it = groupMp.begin(); it != groupMp.end(); it++) {
					cout << "编号: " << it->second << "  姓名: " << mp[it->second].name << "  成绩: " << mp[it->second].score[index-1] << endl;
				}
				int count = 0;
				for (multimap<double, int, greater<double>>::iterator it = groupMp.begin(); it != groupMp.end()&&count<3; it++,count++) {
					if (this->index == 1) {
						v2.push_back((*it).second);
					}
					else {
						v3.push_back((*it).second);
					}
				}
				groupMp.clear();
			}
	}
	cout << "第" << this->index << "轮比赛完毕" << endl;
	cout << endl;
	system("pause");
}

void Manager::showScore() {
	cout << "第" << this->index << "轮晋级选手信息如下:" << endl;
	vector<int>v;
	if (this->index == 1) {
		v = v2;
	}
	else
		v = v3;
	for (vector<int>::iterator it = v.begin(); it != v.end(); it++) {
		cout << "编号:" << *it << "\t" << "姓名:" << this->mp[*it].name << "\t" << "得分:" << this->mp[*it].score[this->index] << endl;
	}
	system("pause");
	system("cls");
	this->showMenu();

}

void Manager::saveRecord() {
	ofstream ofs;
	ofs.open("speech.csv", ios::out | ios::app);
	for (vector<int>::iterator it = v3.begin(); it != v3.end(); it++) {
		ofs << *it << "," << this->mp[*it].score[1] << ",";
	}
	ofs << endl;
	ofs.close();
	cout << "文件保存成功!!!" << endl;
}

void Manager::loadRecord() {
	ifstream ifs("speech.csv", ios::in);
	if (!ifs.is_open()) {
		this->failIsEmpty = true;
		cout << "文件不存在" << endl;
		ifs.close();
		return;
	}
	char ch;
	ifs >> ch;
	if (ifs.eof()) {
		cout << "文件为空" << endl;
		this->failIsEmpty = true;
		ifs.close();
		return;
	}
	this->failIsEmpty = false;
	ifs.putback(ch);
	string data;
	int index = 0;
	while (ifs >> data) {
		vector<string>v;
		int pos = -1;
		int 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;
		}
		this->mpRecord.insert(make_pair(index, v));
		index++;
	}
	cout << endl;
	ifs.close();
}

void Manager::showRecord() {
	for (int i = 0; i < this->mpRecord.size(); i++) {
		cout << "第" << i + 1 << "届" << "冠军编号: " << this->mpRecord[i][0] << "  得分:" << this->mpRecord[i][1] << endl;
		cout << "第" << i + 1 << "届" << "亚军编号: " << this->mpRecord[i][2] << "  得分:" << this->mpRecord[i][3] << endl;
		cout << "第" << i + 1 << "届" << "季军编号: " << this->mpRecord[i][4] << "  得分:" << this->mpRecord[i][5] << endl;
	}
	system("pause");
	system("cls");
}
void Manager::clearRecord() {
	cout << "确定清空文件?" << endl;
	cout << "1.确认    2.取消" << endl;
	int select;
	cin >> select;
	if (select == 1) {
		ofstream ofs("speech.csv", ios::trunc);
		ofs.close();
		Init();
		createSpeaker();
		loadRecord();
		cout << "清空成功!!!!" << endl;
	}
	system("pause");
	system("cls");
}
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<list>
#include<stack>
#include<queue>
#include<queue>
#include<deque>
#include<algorithm>
#include"Manager.h"

using namespace std;

int main() {
	Manager m;
	int choice;
	while (true) {
		m.showMenu();
		cout << "输入选项:";
		cin >> choice;
		switch (choice) {
		case 0:
			m.exitSystem();
			break;
		case 1:
			m.startSpeech();
			break;
		case 2:
			m.showRecord();
			break;
		case 3:
			m.clearRecord();
			break;
		default:
			system("cls");
			break;
		}
	}

	system("pause");
	return 0;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值