//运动会分数统计 ////////
//时间:2005-7-4
//程序: 张建波
#include <iostream.h>
#include <string.h>
#include "menu.h"
#include "Key.h"
typedef struct xm_table{
int item;// 项目编号
char name[20];
int count; //该项目得分人的数量
}XM_TABLE;
struct STUDENT{
char name[20]; //姓名
int score; //得分成绩
int range; //得分名次
int item; //得分项目
int sex; //性别
};
typedef struct SchoolStruct //参赛学校
{
int count; //计算实际运动员个数
int serial; //学校编号
char Name[20];
int menscore; //男子团体总分
int womenscore; //女子团体总分
int totalscore; //团体总分
int jifeng; //学校积分
struct STUDENT students[10]; //参赛运动员
struct SchoolStruct *next; //参赛学校
}SCHOOLSTRUCT;
void Creat_Shool_Link(SCHOOLSTRUCT * &head); //建立链表
void Add_Student_link(SCHOOLSTRUCT * &head); //添加获奖学生
void Tj_FX(SCHOOLSTRUCT * &head); //成绩统计
void Find_Xm_ID(SCHOOLSTRUCT * &head,int xm_ID); //按项目编号查询取得前三或前五名的学校。
void Find_School_Xm(SCHOOLSTRUCT * &head,int School_ID,int XM_ID);//按学校编号查询学校某个项目
void OutPut_Link(SCHOOLSTRUCT *head); //向屏幕输出数据
void _SetArgs(); //参数设置
void _SetXmInfor(); //项目 资料
void AddStudent(SCHOOLSTRUCT *&SchoolTable); //添加学生数据
int SchoolCount=0;//学校总数
int boyCount=0;//男生项目 总数
int girlCount=0;//女生项目 总数
int xm_Count=0; //项目 总数
XM_TABLE xm_T[41];//项目表
int _f1_main(){ //函数入口
Menu m[9];
m[1].Name="参数设置";
m[2].Name="添加学生";
m[3].Name="统计 ";
m[4].Name="学校查询";
m[5].Name="项目查询";
m[6].Name="返回 ";
SCHOOLSTRUCT *h,*head,*SchoolTable;//=new SCHOOLSTRUCT;
int ID=1;
while(1)
{
ShowMenu("数据结构--运动会成绩统计",m,6); //显示菜单
ID=SelectMenuID(); //获取选中的菜单ID
switch(ID){
case 1:{
_SetArgs();
_SetXmInfor();
Creat_Shool_Link(SchoolTable);
h=head=SchoolTable;
InitKey();
break;
}
case 2:{AddStudent(SchoolTable);InitKey();break;}
case 3:{Tj_FX(h);OutPut_Link(h);InitKey();break;}
case 4:{
int m_school_id;
int m_xm_id;
cout<<"\n请输入学校编号(1--"<<SchoolCount<<") School ID=";
cin>>m_school_id;
cout<<"\n请输入项目编号(1--"<<xm_Count<<") XM ID=";
cin>>m_xm_id;
Find_School_Xm(h,m_school_id,m_xm_id);
InitKey();
break;
}
case 5:{
int m_xm_i;
cout<<"\n请输入项目编号 ID=";
cin>>m_xm_i;
Find_Xm_ID(h,1);
InitKey();
}
case 6:return 0;
}
}
return 0;
}
void Creat_Shool_Link(SCHOOLSTRUCT * &head){ //建立链表
//创建链表
SCHOOLSTRUCT *p;
p=new SCHOOLSTRUCT;
head=p;
for(int i=1;i<=SchoolCount;i++)
{
p=p->next=new SCHOOLSTRUCT;
cout<<"请输入学校名称\n";
cout<<"学校编号School ID="<<i<<endl;
cout<<"School Name=";
p->serial=i;
p->jifeng=0; //设置积分为 0
p->totalscore=0;
p->womenscore=0;
p->menscore=0;
cin>>p->Name;
p->count=0; //置运动员数为0;
}
p->next=NULL;
head=head->next;
}
void Add_Student_link(SCHOOLSTRUCT * &head){//添加获奖学生
SCHOOLSTRUCT *h,*p;
int School_ID; //学校ID
char Student_name[20]; //学生姓名
int sex;//性别
int XM_ID;
int score;
int range; //得分名次
cout<<"请输入学生学校ID(1<--->"<<SchoolCount<<")ID=";
cin>>School_ID;
cout<<"请输入学生姓名Name=";
cin>>Student_name;
cout<<"请选择学生性别[0=女 1=男]sex=";
cin>>sex;
if(sex==0)
cout<<"\n请输入项目编号ID(1<--->"<<girlCount<<")ID=";
if(sex==1)
cout<<"\n请输入项目编号ID(1<--->"<<boyCount<<")ID=";
cin>>XM_ID;
cout<<"\n请输入该项目得分score=";
cin>>score;
cout<<"\n请输入得分名次range=";
cin>>range;
//查找学校ID
h=head;
while(h)
{
if(h->serial==School_ID)
{
p=h;
p->count=p->count+1; //运动员数+1
strcpy(p->students[p->count].name,Student_name); //学生姓名
p->students[p->count].item=XM_ID ;//得分项目
xm_T[XM_ID].count=xm_T[XM_ID].count+1; //该项目得分人数+1
p->students[p->count].range=range;//得分名次
p->students[p->count].score=score;//得分
p->students[p->count].sex=sex; //性别
break;
}
else h=h->next;
}
}
void Tj_FX(SCHOOLSTRUCT * &head){//成绩统计
SCHOOLSTRUCT *h,*p;
p=h=head; //保存链表头指针
int menscore=0; //男子团体总分
int womenscore=0; //女子团体总分
int totalscore=0; //团体总分
int i;
int item_i=0;
int jf=0;//积分
while(p){
for(i=1;i<=p->count;i++)
{
//计算分数
totalscore=totalscore+p->students[i].score; //计算总分
if(p->students[i].sex==0)womenscore=womenscore+p->students[i].score;////女子团体总分
else menscore=menscore+p->students[i].score;//男子团体总分
//计算积分
item_i=p->students[i].item;
if(xm_T[item_i].count>=5){
//取前5名
if(p->students[i].range==1)jf=jf+7;
else if(p->students[i].range==2)jf=jf+5;
else if(p->students[i].range==3)jf=jf+3;
else if(p->students[i].range==4)jf=jf+2;
else if(p->students[i].range==5)jf=jf+1;
}
if(xm_T[item_i].count<5){
//取前3名
if(p->students[i].range==1)jf=jf+5;
else if(p->students[i].range==2)jf=jf+3;
else if(p->students[i].range==3)jf=jf+2;
}
// cout<<"\nDEBUG:jf="<<jf<<endl;
// cout<<"\nDEBUG p->students[i].range:"<<p->students[i].range<<endl;
}
p->jifeng=jf; //计算积分
p->womenscore=womenscore;//保存 女子总分
p->menscore=menscore;//保存 男子总分
p->totalscore=totalscore;//保存总分
jf=0;
menscore=0; //男子团体总分
womenscore=0; //女子团体总分
totalscore=0; //总分
p=p->next; //向后移动指针
}
}
void Find_Xm_ID(SCHOOLSTRUCT * &head,int xm_ID){ //按项目编号查询取得前三或前五名的学校。
SCHOOLSTRUCT *h,*p;
p=h=head; //保存链表头指针
int i;
cout<<"\n按项目编号查询取得前三或前五名的学校\n";
cout<<"查询结果如下:\n";
while(h){
//
for(i=1;i<=h->count;i++)
{
if(h->students[i].item==xm_ID)
{
cout<<"学校:"<<h->Name<<" 姓名:"<<h->students[i].name<<" 名次:"<<h->students[i].range<<endl;
}
}
h=h->next;
}
}
void Find_School_Xm(SCHOOLSTRUCT * &head,int School_ID,int XM_ID){//按学校编号查询学校某个项目
SCHOOLSTRUCT *h,*p;
p=h=head; //保存链表头指针
while(h){
if(h->serial==School_ID){p=h;break;}
h=h->next;
}
cout<<"\n按学校编号查询学校某个项目\n";
int xm_i=0;
for(int i=1;i<=p->count;i++){
if(p->students[i].item==XM_ID){
cout<<"查询结果如下:"<<endl;
cout<<"姓名:"<<p->students[i].name<<" ";
xm_i=p->students[i].item;
if(p->students[i].sex==0){
cout<<"性别:女\n";
xm_i=xm_i+20;
}
else {
cout<<"性别: 男\n";
}
cout<<"项目编号:"<<p->students[i].item<<" 项目名称:"<<xm_T[xm_i].name;
cout<<"该项目得分:"<<p->students[i].score<<" 名次:"<<p->students[i].range<<endl;
}
}
}
void OutPut_Link(SCHOOLSTRUCT *head){ //向屏幕输出数据
SCHOOLSTRUCT *h;
h=head;
int i;
int xm_item;
while(h){ //遍历学校
cout<<"学校ID:\n"<<h->serial<<" ";
cout<<"学校名称:"<<h->Name<<" ";
cout<<"本次运动会积分:"<<h->jifeng<<"\n";
cout<<"男子团体总分:"<<h->menscore<<" ";
cout<<"女子团体总分:"<<h->womenscore<<" ";
cout<<"总分:"<<h->totalscore<<"\n";
cout<<"运动员数:"<<h->count<<endl;
cout<<"\n---------------------------------------\n";
for(i=1;i<=h->count;i++){//输出该校学生运动员情况
cout<<"运动员名称"<<h->students[i].name<<" ";
cout<<"性别"<<h->students[i].sex<<"\n";
xm_item=h->students[i].item;
if(h->students[i].sex==0)xm_item=xm_item+20; //如果是女生则项目表向后移动20
cout<<"得分项目"<<xm_T[xm_item].name<<" ";
cout<<"得分"<<h->students[i].score<<" ";
cout<<"得分名次"<<h->students[i].range<<"\n";
}
cout<<"\n--------------------------------------\n";
h=h->next; //指针向后移动
}
cout<<"\n--本次运动会的项目清单--\n";
int xm_count_i;
for(xm_count_i=1;xm_count_i<=boyCount;xm_count_i++)
{
cout<<"编号 "<<xm_T[xm_count_i].item<<" 名称 "<<xm_T[xm_count_i].name<<" 参与人数 "<<xm_T[xm_count_i].count<<endl;
}
for(xm_count_i=1;xm_count_i<=girlCount;xm_count_i++)
{
cout<<"编号 "<<xm_T[xm_count_i+20].item<<" 名称 "<<xm_T[xm_count_i+20].name<<" 参与人数 "<<xm_T[xm_count_i+20].count<<endl;
}
cout<<"\n-------------------------\n";
}
void _SetArgs(){ //参数设置
//// 设置参赛学校
loop_1:
cout<<"请输入参赛学校(n>=2)\nn=";
cin>>SchoolCount;
if(SchoolCount<2){cout<<"\n数据输入有误";goto loop_1;}
////////////////////////////
loop_2:
cout<<"\n请输男生 项目总数0<n<=20\nm=";
cin>>boyCount;
if(boyCount<0 || boyCount>20){cout<<"\n数据输入有误";goto loop_2;}
/////////////////////////////
loop_3:
cout<<"\n请输女生 项目总数0<n<=20\nw=";
cin>>girlCount;
if(girlCount<0 || girlCount>20){cout<<"\n数据输入有误";goto loop_3;}
/////////////////////////////
xm_Count=boyCount+girlCount; //项目总数
}
void _SetXmInfor(){ //项目 资料
int i;
cout<<"\n请输入男生项目信息"<<endl;
for(i=1;i<=boyCount;i++){
cout<<"项目 "<<i<<" 名称 name=";
xm_T[i].item=i; //项目编号
xm_T[i].count=0; //该项目的参与人数
cin>>xm_T[i].name; //项目名称
}
cout<<"\n请输入女生项目信息"<<endl;
for(i=1;i<=girlCount;i++){
cout<<"项目 "<<i<<" 名称 name=";
xm_T[20+i].item=i; //项目编号
cin>>xm_T[20+i].name; //项目名称
}
}
void AddStudent(SCHOOLSTRUCT *&SchoolTable){ //添加学生数据
int ANW;
Loop_4:
Add_Student_link(SchoolTable); //添加学生数据
cout<<"\n是否继续添加学生数据?[0=No 1=Yes]\n";
cin>>ANW;
if(ANW==1)goto Loop_4;
}
分享到:
评论