请好心的师傅帮帮忙,急求一个运动会的C++程序,每个模块要有详细的注释,我的分全给你了
要求:运动会分数统计【问题描述】:参加运动会的n个学校编号为1~n。比赛分成m个男子项目和w个女子项目,项目编号内分别为1~m和m+1~m+w。由于各项目参加人数差别较大...
要求:运动会分数统计
【问题描述】:参加运动会的n个学校编号为1~n。比赛分成m个男子项目和w个女子项目,项目编号内分别为1~m和m+1~m+w。由于各项目参加人数差别较大,有些项目取前五名,得分顺序为7,5,3,2,1;还有些项目只取前三名,得分顺序为5,3,2。写一个统计程序产生各种成绩单和得分报表。
【基本要求】:产生各学校的成绩单,内容包括各校所取得的各项成绩的项目号、名次(成绩)、姓名和得分;产生团体总分报表,内容包括校号、男子团体总分、女子团体总分和团体总分。
师傅,头文件有错呀 ....怎么修改一下,还有能不能解释一下模块,我是个笨蛋,师傅帮帮吗,好吗? 展开
【问题描述】:参加运动会的n个学校编号为1~n。比赛分成m个男子项目和w个女子项目,项目编号内分别为1~m和m+1~m+w。由于各项目参加人数差别较大,有些项目取前五名,得分顺序为7,5,3,2,1;还有些项目只取前三名,得分顺序为5,3,2。写一个统计程序产生各种成绩单和得分报表。
【基本要求】:产生各学校的成绩单,内容包括各校所取得的各项成绩的项目号、名次(成绩)、姓名和得分;产生团体总分报表,内容包括校号、男子团体总分、女子团体总分和团体总分。
师傅,头文件有错呀 ....怎么修改一下,还有能不能解释一下模块,我是个笨蛋,师傅帮帮吗,好吗? 展开
1个回答
展开全部
现在可以了, 你再试试吧
/*学校运动会管理系统
问题描述:
(1) 初始化输入:N-参赛院系总数,M-男子竞赛项目数,W-女子竞赛项目数;
(2) 各项目名次取法有如下几种:
取前5名:第1名得分 7,第2名得分 5,第3名得分3,第4名得分2,第5名得分 1;
(3) 由程序提醒用户填写比赛结果,输入各项目获奖运动员的信息。
(4) 所有信息记录完毕后,用户可以查询各个院系或个人的比赛成绩,生成团体总分报表,查看参赛院系信息、获奖运动员、比赛项目信息等。
(5) 原始数据需保存到磁盘文件中。
*/
#include <iostream>
#include <fstream>
#include <vector>
#include <string>
#include <algorithm>
using namespace std;
#define N 4
#define M 3
#define W 3
struct Student
{
Student(){}
Student(vector<string>* departments):depars(departments){}
void Input();
void Print();
friend ofstream& operator<<(ofstream& ofs, Student& stu);
friend ifstream& operator>>(ifstream& ifs, Student& stu);
string name;
string department;
int points;
private:
vector<string>* depars;
};
ofstream& operator<<(ofstream& ofs, Student& stu)
{
ofs << stu.name <<"\t"<< stu.department<<"\t" << stu.points;
return ofs;
}
ifstream& operator>>(ifstream& ifs, Student& stu)
{
ifs >> stu.name >> stu.department >> stu.points;
return ifs;
}
void Student::Input()
{
cout<<"输入名字:"<<endl;
cin >> name;
bool invalid(true);
do
{
string d;
cout<<"输入院系名称:"<<endl;
cin >> d;
vector<string>::iterator found=find(depars->begin(),depars->end(),d);
if(found != depars->end())
{
invalid = false;
department = d;
} else {
cout<<"无效院系名称,请重新输入。"<<endl;
}
} while(invalid);
}
void Student::Print()
{
cout<< name <<"\t"<<department<<endl;
}
// Forward declaration
class GameInfo;
class SportEvent
{
public:
static int GetPoint(int ranking);
void InputWinners(GameInfo& g);
void Print();
friend ofstream& operator<<(ofstream& ofs, SportEvent& se);
friend ifstream& operator>>(ifstream& ifs, SportEvent& se);
public:
vector<Student> winners;
string name;
};
ofstream& operator<<(ofstream& ofs, SportEvent& se)
{
ofs << se.name << endl;
ofs << se.winners.size() << endl;
for(unsigned int i(0);i<se.winners.size();i++)
{
ofs << se.winners.at(i) <<"\t";
}
return ofs;
}
ifstream& operator>>(ifstream& ifs, SportEvent& se)
{
ifs >> se.name;
unsigned int count(0);
ifs >> count;
se.winners.clear();
for(unsigned int i(0);i<count;i++)
{
Student student;
ifs >> student;
se.winners.push_back(student);
}
return ifs;
}
int SportEvent::GetPoint(int ranking)
{
switch(ranking)
{
case 1:
return 7;
break;
case 2:
return 5;
break;
case 3:
return 3;
break;
case 4:
return 2;
break;
case 5:
return 1;
break;
}
return 0;
}
void SportEvent::Print()
{
// #1 student_name department_name
for(int i(0);i<5;i++)
{
cout <<"#"<<(i+1)<<"\t";
winners.at(i).Print();
}
}
class GameInfo
{
public:
void Init();
void InputResult();
void QueryDep(string depart);
void QueryStu(string student);
void QueryEve(string eventname);
void Save(ofstream&);
void Load(ifstream&);
public:
vector<string> departments;
vector<SportEvent> mevents;
vector<SportEvent> wevents;
};
void SportEvent::InputWinners(GameInfo& g)
{
for(int i(0);i<5;i++)
{
Student s(&g.departments);
cout<<"输入第"<<(i+1)<<"个获奖者"<<endl;
s.Input();
winners.push_back(s);
}
}
void GameInfo::Save(ofstream& fout)
{
//保存院系名称
fout << departments.size() << endl;
for(unsigned int i(0);i<departments.size();i++)
{
fout << departments.at(i) <<"\t";
}
fout << endl;
//保存男子项目
fout << mevents.size() << endl;
for(unsigned int i(0);i<mevents.size();i++)
{
fout << mevents.at(i) <<"\t";
}
fout << endl;
//保存女子项目
fout << wevents.size() << endl;
for(unsigned int i(0);i<wevents.size();i++)
{
fout << wevents.at(i) <<"\t";
}
fout << endl;
}
void GameInfo::Load(ifstream& fin)
{
}
void GameInfo::Init()
{
for(int i(0);i<N;i++)
{
string dname;
cout<<"输入第"<<(i+1)<<"个参赛院系名称:";
cin >> dname;
departments.push_back(dname);
}
cout <<endl;
for(int i(0);i<M;i++)
{
SportEvent mevent;
cout<<"输入第"<<(i+1)<<"个男子项目名称:";
cin >> mevent.name;
mevents.push_back(mevent);
}
cout <<endl;
for(int i(0);i<W;i++)
{
SportEvent wevent;
cout<<"输入第"<<(i+1)<<"个女子项目名称:";
cin >> wevent.name;
wevents.push_back(wevent);
}
cout <<endl;
}
void GameInfo::InputResult()
{
for(int i(0);i<M;i++)
{
cout<<"输入第"<<(i+1)<<"个男子项目\"" << mevents.at(i).name<<"\""<<endl;
mevents.at(i).InputWinners(*this);
}
for(int i(0);i<W;i++)
{
cout<<"输入第"<<(i+1)<<"个女子项目\"" << wevents.at(i).name<<"\""<<endl;
wevents.at(i).InputWinners(*this);
}
}
void GameInfo::QueryDep(string depart)
{
cout << depart << endl;
int points(0);
for(int i(0);i<M;i++)
{
vector<Student> w = mevents.at(i).winners;
for(unsigned int n(0);n<w.size();n++)
{
if(w.at(n).department==depart)
{
cout << (w.at(n).name) << "\t";
cout << (mevents.at(i).name);
cout << "\t#" << (n+1); // ranking
int p(SportEvent::GetPoint(n+1));
cout << "\t" << p << "分"<< endl; // point
points+=p;
}
}
}
for(unsigned int i(0);i<W;i++)
{
vector<Student> w = wevents.at(i).winners;
for(unsigned int n(0);n<w.size();n++)
{
if(w.at(n).department==depart)
{
cout << w.at(n).name << "\t";
cout << wevents.at(i).name;
cout << "\t#" << (n+1); // ranking
int p(SportEvent::GetPoint(n+1));
cout << "\t" << p << "分"<< endl; // point
points+=p;
}
}
}
if(points)
cout << "团体总分(男女混合):" << points << "分"<<endl;
}
void GameInfo::QueryStu(string student)
{
cout << student << endl;
int points(0);
string d;
for(int i(0);i<M;i++)
{
vector<Student> w = mevents.at(i).winners;
for(unsigned int n(0);n<w.size();n++)
{
if(w.at(n).name==student)
{
cout << mevents.at(i).name;
cout << "\t#" << (n+1); // ranking
int p(SportEvent::GetPoint(n+1));
cout << "\t" << p << "分"<< endl; // point
points+=p;
d = w.at(n).department;
}
}
}
if(points)
cout <<"隶属于:"<< d <<endl<< "个人总分:" << points << "分"<<endl;
cout << endl;
points =0;
for(int i(0);i<W;i++)
{
vector<Student> w = wevents.at(i).winners;
for(unsigned int n(0);n<w.size();n++)
{
if(w.at(n).name==student)
{
cout << wevents.at(i).name;
cout << "\t#" << (n+1); // ranking
int p(SportEvent::GetPoint(n+1));
cout << "\t" << p << "分"<< endl; // point
points+=p;
d =w.at(n).department;
}
}
}
if(points)
cout <<"隶属于:"<< d <<endl<< "个人总分:" << points << "分"<<endl;
}
void GameInfo::QueryEve(string eventname)
{
for(int i(0);i<M;i++)
{
if(mevents.at(i).name == eventname)
{
mevents.at(i).Print();
}
}
for(int i(0);i<W;i++)
{
if(wevents.at(i).name == eventname)
{
wevents.at(i).Print();
}
}
}
int main()
{
const char* filename= "data.txt";
GameInfo gi;
//读取
ifstream ifs(filename);
gi.Load(ifs);
ifs.close();
//录入
gi.Init();
gi.InputResult();
int opt(0);
string name;
while(opt!=4)
{
cout << "1.按院系名称查询"<<endl;
cout << "2.按比赛项目查询"<<endl;
cout << "3.按运动员姓名查询"<<endl;
cout << "4.退出"<<endl;
cin >> opt;
switch(opt)
{
case 1:
cout << "请输入院系名称:" << endl;
cin >> name;
gi.QueryDep(name);
break;
case 2:
cout << "请输入比赛项目:" << endl;
cin >> name;
gi.QueryEve(name);
break;
case 3:
cout << "请输入运动员姓名:" << endl;
cin >> name;
gi.QueryStu(name);
break;
}
}
//保存
ofstream ofs(filename, ios::out | ios::app);
gi.Save(ofs);
ofs.close();
return 0;
}
/*学校运动会管理系统
问题描述:
(1) 初始化输入:N-参赛院系总数,M-男子竞赛项目数,W-女子竞赛项目数;
(2) 各项目名次取法有如下几种:
取前5名:第1名得分 7,第2名得分 5,第3名得分3,第4名得分2,第5名得分 1;
(3) 由程序提醒用户填写比赛结果,输入各项目获奖运动员的信息。
(4) 所有信息记录完毕后,用户可以查询各个院系或个人的比赛成绩,生成团体总分报表,查看参赛院系信息、获奖运动员、比赛项目信息等。
(5) 原始数据需保存到磁盘文件中。
*/
#include <iostream>
#include <fstream>
#include <vector>
#include <string>
#include <algorithm>
using namespace std;
#define N 4
#define M 3
#define W 3
struct Student
{
Student(){}
Student(vector<string>* departments):depars(departments){}
void Input();
void Print();
friend ofstream& operator<<(ofstream& ofs, Student& stu);
friend ifstream& operator>>(ifstream& ifs, Student& stu);
string name;
string department;
int points;
private:
vector<string>* depars;
};
ofstream& operator<<(ofstream& ofs, Student& stu)
{
ofs << stu.name <<"\t"<< stu.department<<"\t" << stu.points;
return ofs;
}
ifstream& operator>>(ifstream& ifs, Student& stu)
{
ifs >> stu.name >> stu.department >> stu.points;
return ifs;
}
void Student::Input()
{
cout<<"输入名字:"<<endl;
cin >> name;
bool invalid(true);
do
{
string d;
cout<<"输入院系名称:"<<endl;
cin >> d;
vector<string>::iterator found=find(depars->begin(),depars->end(),d);
if(found != depars->end())
{
invalid = false;
department = d;
} else {
cout<<"无效院系名称,请重新输入。"<<endl;
}
} while(invalid);
}
void Student::Print()
{
cout<< name <<"\t"<<department<<endl;
}
// Forward declaration
class GameInfo;
class SportEvent
{
public:
static int GetPoint(int ranking);
void InputWinners(GameInfo& g);
void Print();
friend ofstream& operator<<(ofstream& ofs, SportEvent& se);
friend ifstream& operator>>(ifstream& ifs, SportEvent& se);
public:
vector<Student> winners;
string name;
};
ofstream& operator<<(ofstream& ofs, SportEvent& se)
{
ofs << se.name << endl;
ofs << se.winners.size() << endl;
for(unsigned int i(0);i<se.winners.size();i++)
{
ofs << se.winners.at(i) <<"\t";
}
return ofs;
}
ifstream& operator>>(ifstream& ifs, SportEvent& se)
{
ifs >> se.name;
unsigned int count(0);
ifs >> count;
se.winners.clear();
for(unsigned int i(0);i<count;i++)
{
Student student;
ifs >> student;
se.winners.push_back(student);
}
return ifs;
}
int SportEvent::GetPoint(int ranking)
{
switch(ranking)
{
case 1:
return 7;
break;
case 2:
return 5;
break;
case 3:
return 3;
break;
case 4:
return 2;
break;
case 5:
return 1;
break;
}
return 0;
}
void SportEvent::Print()
{
// #1 student_name department_name
for(int i(0);i<5;i++)
{
cout <<"#"<<(i+1)<<"\t";
winners.at(i).Print();
}
}
class GameInfo
{
public:
void Init();
void InputResult();
void QueryDep(string depart);
void QueryStu(string student);
void QueryEve(string eventname);
void Save(ofstream&);
void Load(ifstream&);
public:
vector<string> departments;
vector<SportEvent> mevents;
vector<SportEvent> wevents;
};
void SportEvent::InputWinners(GameInfo& g)
{
for(int i(0);i<5;i++)
{
Student s(&g.departments);
cout<<"输入第"<<(i+1)<<"个获奖者"<<endl;
s.Input();
winners.push_back(s);
}
}
void GameInfo::Save(ofstream& fout)
{
//保存院系名称
fout << departments.size() << endl;
for(unsigned int i(0);i<departments.size();i++)
{
fout << departments.at(i) <<"\t";
}
fout << endl;
//保存男子项目
fout << mevents.size() << endl;
for(unsigned int i(0);i<mevents.size();i++)
{
fout << mevents.at(i) <<"\t";
}
fout << endl;
//保存女子项目
fout << wevents.size() << endl;
for(unsigned int i(0);i<wevents.size();i++)
{
fout << wevents.at(i) <<"\t";
}
fout << endl;
}
void GameInfo::Load(ifstream& fin)
{
}
void GameInfo::Init()
{
for(int i(0);i<N;i++)
{
string dname;
cout<<"输入第"<<(i+1)<<"个参赛院系名称:";
cin >> dname;
departments.push_back(dname);
}
cout <<endl;
for(int i(0);i<M;i++)
{
SportEvent mevent;
cout<<"输入第"<<(i+1)<<"个男子项目名称:";
cin >> mevent.name;
mevents.push_back(mevent);
}
cout <<endl;
for(int i(0);i<W;i++)
{
SportEvent wevent;
cout<<"输入第"<<(i+1)<<"个女子项目名称:";
cin >> wevent.name;
wevents.push_back(wevent);
}
cout <<endl;
}
void GameInfo::InputResult()
{
for(int i(0);i<M;i++)
{
cout<<"输入第"<<(i+1)<<"个男子项目\"" << mevents.at(i).name<<"\""<<endl;
mevents.at(i).InputWinners(*this);
}
for(int i(0);i<W;i++)
{
cout<<"输入第"<<(i+1)<<"个女子项目\"" << wevents.at(i).name<<"\""<<endl;
wevents.at(i).InputWinners(*this);
}
}
void GameInfo::QueryDep(string depart)
{
cout << depart << endl;
int points(0);
for(int i(0);i<M;i++)
{
vector<Student> w = mevents.at(i).winners;
for(unsigned int n(0);n<w.size();n++)
{
if(w.at(n).department==depart)
{
cout << (w.at(n).name) << "\t";
cout << (mevents.at(i).name);
cout << "\t#" << (n+1); // ranking
int p(SportEvent::GetPoint(n+1));
cout << "\t" << p << "分"<< endl; // point
points+=p;
}
}
}
for(unsigned int i(0);i<W;i++)
{
vector<Student> w = wevents.at(i).winners;
for(unsigned int n(0);n<w.size();n++)
{
if(w.at(n).department==depart)
{
cout << w.at(n).name << "\t";
cout << wevents.at(i).name;
cout << "\t#" << (n+1); // ranking
int p(SportEvent::GetPoint(n+1));
cout << "\t" << p << "分"<< endl; // point
points+=p;
}
}
}
if(points)
cout << "团体总分(男女混合):" << points << "分"<<endl;
}
void GameInfo::QueryStu(string student)
{
cout << student << endl;
int points(0);
string d;
for(int i(0);i<M;i++)
{
vector<Student> w = mevents.at(i).winners;
for(unsigned int n(0);n<w.size();n++)
{
if(w.at(n).name==student)
{
cout << mevents.at(i).name;
cout << "\t#" << (n+1); // ranking
int p(SportEvent::GetPoint(n+1));
cout << "\t" << p << "分"<< endl; // point
points+=p;
d = w.at(n).department;
}
}
}
if(points)
cout <<"隶属于:"<< d <<endl<< "个人总分:" << points << "分"<<endl;
cout << endl;
points =0;
for(int i(0);i<W;i++)
{
vector<Student> w = wevents.at(i).winners;
for(unsigned int n(0);n<w.size();n++)
{
if(w.at(n).name==student)
{
cout << wevents.at(i).name;
cout << "\t#" << (n+1); // ranking
int p(SportEvent::GetPoint(n+1));
cout << "\t" << p << "分"<< endl; // point
points+=p;
d =w.at(n).department;
}
}
}
if(points)
cout <<"隶属于:"<< d <<endl<< "个人总分:" << points << "分"<<endl;
}
void GameInfo::QueryEve(string eventname)
{
for(int i(0);i<M;i++)
{
if(mevents.at(i).name == eventname)
{
mevents.at(i).Print();
}
}
for(int i(0);i<W;i++)
{
if(wevents.at(i).name == eventname)
{
wevents.at(i).Print();
}
}
}
int main()
{
const char* filename= "data.txt";
GameInfo gi;
//读取
ifstream ifs(filename);
gi.Load(ifs);
ifs.close();
//录入
gi.Init();
gi.InputResult();
int opt(0);
string name;
while(opt!=4)
{
cout << "1.按院系名称查询"<<endl;
cout << "2.按比赛项目查询"<<endl;
cout << "3.按运动员姓名查询"<<endl;
cout << "4.退出"<<endl;
cin >> opt;
switch(opt)
{
case 1:
cout << "请输入院系名称:" << endl;
cin >> name;
gi.QueryDep(name);
break;
case 2:
cout << "请输入比赛项目:" << endl;
cin >> name;
gi.QueryEve(name);
break;
case 3:
cout << "请输入运动员姓名:" << endl;
cin >> name;
gi.QueryStu(name);
break;
}
}
//保存
ofstream ofs(filename, ios::out | ios::app);
gi.Save(ofs);
ofs.close();
return 0;
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询