#include <stdlib.h>
#include <string.h>
#include <io.h>
#include <conio.h>/*屏幕操作函数*/
#define MAX 50
typedef struct node1{
int record/*项目成绩*/
struct node1 *next/*链域*/
}Schools
typedef struct {
int item/*项目编号*/
Schools *firstschool/*链域指向链表中第一个结点*/
}ITEM
typedef struct {
int z/* 项目总数 */
ITEM a[MAX]
}ALLitems
typedef struct node2 {
int item/*该学校获奖的项目*/
int record/*项目成绩*/
struct node2 *next/*链域*/
}Items
typedef struct {
int school/*学校编号*/
int score/*学校总分*/
int boys/*男团体总分*/
int girls/*女团体总分*/
Items *firstitem/*链域指向链表中第一个获奖项目的结点*/
}SCHNode
typedef struct {
int n/* 学校总数 */
SCHNode b[MAX]
}ALLNode
ALLitems *g1
ALLNode *g2
void funct1(ALLitems *g1,ALLNode *g2)
{
Schools *p1
Items *p2
int i,j,k,m,w,h,x
p1=(Schools *)malloc(sizeof(Schools))
p2=(Items *)malloc(sizeof(Items))
if(!p1||!p2)
exit(1)
printf("\n ******输入各个项目信息 ****** 13 \n\n")
printf(" 输入男子项目总数m:")scanf("%d",&m)
if(m<0||m>20)
{
printf(" 输入有误,m是20以内的整数,请重新输入:")scanf("%d",&m)
}
printf(" 输入女子项目总数w:")scanf("%d",&w)
if(w<0||w>20)
{
printf(" 输入有误,w是20以内的整数,请重新输入:")scanf("%d",&w)
}
printf(" 输入参加运动会的学校总数n:")scanf("%d",&g2->n)
if(g2->n<0||g2->n>20)
{
printf(" 输入有误,n是20以内的整数,请重新输入:")scanf("%d",&g2->n)
}
g1->z=m+w
printf(" 则项目编号为男子1-%d,女子%d-%d",m,m+1,g1->z)
printf("\n\n ****记录运动会成绩****")
printf("\n\n (输入0标志结束)\n")
for(k=1k<=g1->zk++)
{
g1->a[k].item=k
g1->a[k].firstschool=NULL
}
for(k=1k<=g2->nk++)
{
g2->b[k].school=k
g2->b[k].firstitem=0
g2->b[k].score=0
g2->b[k].boys=0
g2->b[k].girls=0
}
g2->b[0].score=0
g2->b[0].boys=0
g2->b[0].girls=0
while(i!=0)
{
printf("\n 项目:")
scanf("%d",&i)
if(i!=0)
{
printf(" 1.前三名 2.前五名\n")
printf(" 请选择:")
scanf("%d",&j)
if(j!=1&&j!=2)
{
printf(" 输入有误,请重新选择:")
scanf("%d",&j)
}
if(j==1)
{
h=3
do{ printf(" 第%d名:学校(学校编号为数字)",h)scanf("%d",&x)
p1=(Schools *)malloc(sizeof(Schools))
p1->school=x
p2=(Items *)malloc(sizeof(Items))
p2->item=i
if(h==3) p2->record=p1->record=2
if(h==2) p2->record=p1->record=3
if(h==1) p2->record=p1->record=5
p1->next=g1->a[i].firstschool
g1->a[i].firstschool=p1
p2->next=g2->b[x].firstitem
g2->b[x].firstitem=p2
g2->b[x].score=g2->b[x].score+p2->record/* 累计总分 */
if(i<=m) g2->b[x].boys=g2->b[x].boys+p2->record/* 累计男团体总分 */
else
g2->b[x].girls=g2->b[x].girls+p2->record/* 累计女团体总分 */
h--
}while(x!=0&&h!=0)
}
if(j==2)
{
h=5
do{
printf(" 第%d名:学校(学校编号为数字)",h)
scanf("%d",&x)
p1=(Schools *)malloc(sizeof(Schools))
p1->school=x
p2=(Items *)malloc(sizeof(Items))
p2->item=i
if(h==5) p2->record=p1->record=1
if(h==4) p2->record=p1->record=2
if(h==3) p2->record=p1->record=3
if(h==2) p2->record=p1->record=5
if(h==1) p2->record=p1->record=7
p1->next=g1->a[i].firstschool
g1->a[i].firstschool=p1
p2->next=g2->b[x].firstitem
g2->b[x].firstitem=p2
g2->b[x].score=g2->b[x].score+p2->record/* 累计总分 */
if(i<=m) g2->b[x].boys=g2->b[x].boys+p2->record/* 累计男团体总分 */ else g2->b[x].girls=g2->b[x].girls+p2->record/* 累计女团体总分 */ h--
}while(x!=0&&h!=0)
}
}
}
}
void save()
{
FILE *fp1,*fp2
fp1=(FILE *)malloc(sizeof(FILE))
fp2=(FILE *)malloc(sizeof(FILE))
if((fp1=fopen("sports1","wb"))==NULL)
{
printf("cannot open file.\n")
return
}
if(fwrite(g1,sizeof(ALLitems),1,fp1)!=1)
printf("file write error.\n")
fclose(fp1)
if((fp2=fopen("sports2","wb"))==NULL)
{ printf("cannot open file.\n")
return
}
if(fwrite(g2,sizeof(ALLNode),1,fp2)!=1)
printf("file write error.\n")
fclose(fp2)
}
void funct2(ALLNode *g2) /* 输出各学校总分 */
{
int k
printf("\n\n ****** 输出各学校总分 ******\n")
printf(" 学校编号\t 总分 \n")
for(k=1k<=g2->nk++)
printf(" %d\t\t\t %d\n",k,g2->b[k].score)
printf("\n")
system("pause")
printf(" 按任意键返回主菜单......")
getchar()
}
void funct3(ALLNode *g2) /* 按学校编号排序输出 */
{
int k
Items *p2
p2=(Items *)malloc(sizeof(Items))
printf("\n\n ****** 按学校编号排序输出 ******\n")
printf(" 学校编号\t\t\t获奖情况 \n")
scanf("%d",&k)
for(k=1k<=g2->nk++)
{
printf("\t\t\t\t\t\t%d\t",k)
p2=g2->b[k].firstitem
while(p2!=NULL)
{
printf("项目%d:得%d分 ",p2->item,p2->record)
p2=p2->next
}
printf("\n")
}
printf("\n")
system("pause")
printf("按任意键返回主菜单......")
getchar()
}
void funct4(ALLNode *g2) /* 按学校总分排序输出 */
{
int i,j,k
Items *p2
printf("\n\n ****** 按学校总分排序输出 ******\n")
printf(" 学校编号\t\t总分 \n")
scanf("%d",&k)
//printf("输入要查询的项目编号:")
for(i=2i<=g2->ni++)
{
printf("%d\t",k)
p2=g2->b[k].firstitem
while(p2!=NULL)
{
printf("%d \t\t%d\n",g2->b[k].school,g2->b[k].score)
p2=p2->next
}
printf("\n")
g2->b[0].score=g2->b[i].score
g2->b[0].boys=g2->b[i].boys
g2->b[0].girls=g2->b[i].girls
g2->b[0].school=g2->b[i].school
j=i-1
while(g2->b[0].score<g2->b[j].score&&j>0)
{
g2->b[j+1].score=g2->b[j].score
g2->b[j+1].boys=g2->b[j].boys
g2->b[j+1].girls=g2->b[j].girls
g2->b[j+1].school=g2->b[j].school
j--
}
g2->b[j+1].score=g2->b[0].score
g2->b[j+1].boys=g2->b[0].boys
g2->b[j+1].girls=g2->b[0].girls
g2->b[j+1].school=g2->b[0].school
}
for(k=1k<=g2->nk++)
printf("%d \t\t%d\n",g2->b[k].school,g2->b[k].score)
system("pause")
printf("按任意键返回主菜单......")
getchar()
}
void funct5(ALLNode *g2) /* 按男团体总分排序输出 */
{
int i,j,k
Items *p2
p2=(Items *)malloc(sizeof(Items))
printf("\n\n ****** 按男团体总分排序输出 ******\n")
printf("学校编号\t\t男团体总分 \n")
scanf("%d",&k)
//printf("输入要查询的学校编号:")
for(i=2i<=g2->ni++)
{
printf("%d\t",k)
p2=g2->b[k].firstitem
while(p2!=NULL)
{ printf("%d\t\t %d\n",g2->b[k].school,g2->b[k].boys)
p2=p2->next
}
printf("\n")g2->b[0].score=g2->b[i].score
g2->b[0].boys=g2->b[i].boys
g2->b[0].girls=g2->b[i].girls
g2->b[0].school=g2->b[i].school
j=i-1
while(g2->b[0].boys<g2->b[j].boys&&j>0)
{
g2->b[j+1].score=g2->b[j].score
g2->b[j+1].boys=g2->b[j].boys
g2->b[j+1].girls=g2->b[j].girls
g2->b[j+1].school=g2->b[j].school
j--
}
g2->b[j+1].score=g2->b[0].score
g2->b[j+1].boys=g2->b[0].boys
g2->b[j+1].girls=g2->b[0].girls
g2->b[j+1].school=g2->b[0].school
}
for(k=1k<=g2->nk++)
printf("%d\t\t %d\n",g2->b[k].school,g2->b[k].boys)
system("pause")// 暂停等待
printf("按任意键返回主菜单......")
getchar()
}
void funct6(ALLNode *g2) /* 按女团体总分排序输出 */
{
int i,j,k
Items *p2
p2=(Items *)malloc(sizeof(Items))
printf("\n\n ****** 按女团体总分排序输出 ******\n")
printf("学校编号\t\t女团体总分 \n")
scanf("%d",&k)// printf("输入要查询的项目编号:")
for(i=2i<=g2->ni++)
{
printf("%d\t",k)
p2=g2->b[k].firstitem
while(p2!=NULL)
{ printf("%d\t\t %d\n",g2->b[k].school,g2->b[k].girls)
p2=p2->next
}
printf("\n")
g2->b[0].score=g2->b[i].score
g2->b[0].boys=g2->b[i].boys
g2->b[0].girls=g2->b[i].girls
g2->b[0].school=g2->b[i].school
j=i-1
while(g2->b[0].girls<g2->b[j].girls&&j>0)
{ g2->b[j+1].score=g2->b[j].score
g2->b[j+1].boys=g2->b[j].boys
g2->b[j+1].girls=g2->b[j].girls
g2->b[j+1].school=g2->b[j].school
j--
}
g2->b[j+1].score=g2->b[0].score
g2->b[j+1].boys=g2->b[0].boys
g2->b[j+1].girls=g2->b[0].girls
g2->b[j+1].school=g2->b[0].school
}
for(k=1k<=g2->nk++)
printf("%d\t\t %d\n",g2->b[k].school,g2->b[k].girls)
system("pause")
printf("按任意键返回主菜单......")
getchar()
}
void funct7(ALLNode *g2) /* 按学校编号查询学校某个项目情况 */
{
int i,j
Items *p2
printf("\n ****** 按学校编号查询学校某个项目情况 ******\n")
printf(" 输入要查询的学校编号:")
scanf("%d",&i)
printf(" 输入要查询的项目编号:")
scanf("%d",&j)
p2=g2->b[i].firstitem
while(p2!=NULL)
{
if(p2->item==j)
printf(" 学校编号:%d\t项目%d:得%d分\n",i,p2->item,p2->record)p2=p2->next
}
printf("\n")
system("pause")
printf(" 按任意键返回主菜单......")
getchar()
}
void funct8(ALLitems *g1) /* 按项目编号查询取得名次的学校 */
{
int i
Schools *p1
printf("\n*** 按项目编号查询取得名次的学校 ***\n")
printf("输入要查询的项目编号:")
scanf("%d",&i)
printf("项目编号\t\t\t取得名次的学校\n")
printf("%d\t",i)
p1=g1->a[i].firstschool
while(p1!=NULL)
{ printf(" 学校%d:得%d分 ",p1->school,p1->record)
p1=p1->next
}
printf("\n\n")
system("pause")
printf("按任意键返回主菜单......")
getchar()
}
void main()
{
int t
g2=(ALLNode*)malloc(sizeof(ALLNode))
g1=(ALLitems*)malloc(sizeof(ALLitems))
if(!g2||!g1)
exit(1)
system("cls")
for()
{
printf("\t\t* * * * * * * * * * * * * * * * * * * * * * *\n")
printf("\t\t 运动会分数统计系统 \n")
printf("\t\t* * * * * * * * * * * * * * * * * * * * * * *\n")
printf("\t\t* 1.输入各个项目成绩并存储文件 *\t \n")
printf("\t\t* 2.统计各学校总分 *\t \n")
printf("\t\t* 3.按学校编号排序输出 *\t \n")
printf("\t\t* 4.按学校总分排序输出 *\t \n")
printf("\t\t* 5.按男团体总分排序输出 *\t \n")
printf("\t\t* 6.按女团体总分排序输出 *\t \n")
printf("\t\t* 7.按学校编号查询学校某个项目情况 *\t \n")
printf("\t\t* 8.按项目编号查询取得名次的学校 *\n")
printf("\t\t* 0.退出 *\n")
printf("\t\t* * * * * * * * * * * * * * * * * * * * * * *\n")
printf("\t\t \n")printf("\t\t \n")printf("\t\t \n")printf("\t\t 请选择(0-8):")
loop:scanf("%d",&t)
system("cls")
switch(t)
{
case 1:funct1(g1,g2)save()break
case 2:funct2(g2)break
case 3:funct3(g2)break
case 4:funct4(g2)break
case 5:funct5(g2)break
case 6:funct6(g2)break
case 7:funct7(g2)break
case 8:funct8(g1)break
case 0:exit(0)
default:{ printf("输入有误,请重新选择:")
goto loop}
}//clrscr()
system("cls")
}
}
#include<iostream>#include <algorithm>
#include<vector>
#include<string>
#include<fstream>
#include<stdlib.h>
using namespace stdstruct player
{
string sex
int score
//school playerschool
}
struct school
{
int ID
int score
player girl
player boy
}
struct match
{
int number
int score
school sch[100]
bool Isthree
}
bool cmp(school &q,school &p)
{
return q.score<p.score
}
bool cmp1(school &q,school &p)
{
return q.boy.score<p.boy.score}
bool cmp2(school &q,school &p)
{
return q.girl.score<p.girl.score
}
void save2(school *q,int n)
{
string b
cin>>b
int i
ofstream fout(b.c_str())
for (i=1i<=ni++)
fout<<q[i].score<<endl
}
void save6(int total,int temp,match *p,int kq)
{
string b
cin>>b
//int i
ofstream fout(b.c_str())
fout<<total<<"号学校在第"<<temp<<"次比赛中积分为:"<<endl
fout<<p[temp].sch[kq].score<<endl
}
void save3(match *p,int n,int temp)
{
string b
int i
cin>>b
ofstream fout(b.c_str())
if (p[temp].Isthree)
for (i=1i<=3i++)
{
fout<<"第【"<<i<<"】名学校编号为:"<<p[temp].sch[i].ID<<endl
fout<<"得分: "<<p[temp].sch[i].score<<endl<<endl
}
else
for (i=1i<=5i++)
{
fout<<"第【"<<i<<"】名学校编号为:"<<p[temp].sch[i].ID<<endl
fout<<"得分: "<<p[temp].sch[i].score<<endl<<endl
}}
int main()
{
int n,m,r,w,N
bool BB=false
int flag,lex
char c
int temp
int total
int bisai,schoo
system("color 4F")cout<<"\t\t------------------------------------"<<endl
cout<<"\t\t\t***********************"<<endl
printf ("\t\t\t 运动会成绩统计系统\t\n")
cout<<"\t\t\t***********************"<<endl
cout<<"\t\t------------------------------------"<<endl<<endl<<endl
getchar()
system("cls")
cout<<" 请输入学校数目"<<endl
cin>>n
system("cls")
cout<<"请输入男生比赛项目数"<<endl
cin>>m
system("cls")
cout<<"请输入女生比赛项目数"<<endl
cin>>w
system("cls")
match *p=new match[m+1+w]
school *q=new school[n+1]
match *pp
school *qq
for (int i=1i<=ni++)
{
q[i].boy.score=0
q[i].girl.score=0
q[i].score=0
q[i].ID=i
}
for (i=1i<=m+wi++)
for (int j=1j<=nj++)
{
p[i].sch[j].score=0
p[i].sch[1].ID=-1
}system("cls")
loop:
system("cls")
cout<<"\t\t\t\t主界面:"<<endl
cout<<"1: 开始录入成绩...."<<endl<<endl
cout<<"2: 按学校编号排序输出"<<endl<<endl
cout<<"3: 按学校总分排序输出"<<endl<<endl
cout<<"4: 按男生团体总分排序输出"<<endl<<endl
cout<<"5: 按女生团体总分排序输出"<<endl<<endl
cout<<"6: 按学校编号查询指定项目得分情况"<<endl<<endl
cout<<"7: 查询某一项目所参与学校的得分情况"<<endl<<endl
cout<<"8: 操作完毕... 退出系统"<<endl
cin>>flag
if (flag==1)
{
system("cls")
//freopen("match.txt","r",stdin)
ifstream fin("match.txt")
while (fin>>bisai>>lex)
{
if (lex==3)
p[bisai].Isthree=true
else p[bisai].Isthree=false }
fin.close()
ifstream tin("school.txt")
while (tin>>bisai)
{
if (p[bisai].Isthree)
{
for (i=1i<=3i++)
{
tin>>schoo
p[bisai].sch[i].ID=schoo
//p[bisai].sch[]=scho
if (i==1)
{
q[schoo].score+=5
if (bisai>m)
q[schoo].girl.score+=5
else
q[schoo].boy.score+=5
p[bisai].sch[i].score=5
}
else if (i==2)
{
q[schoo].score+=3
if (bisai>m)
q[schoo].girl.score+=3
else
q[schoo].boy.score+=3
p[bisai].sch[i].score=3
}
else
{
q[schoo].score+=2
if (bisai>m)
q[schoo].girl.score+=2
else
q[schoo].boy.score+=2
p[bisai].sch[i].score=2
}
}
}
else
{
for (i=1i<=5i++)
{
tin>>schoo
p[bisai].sch[i].ID=schoo
//p[bisai].sch[]=scho
if (i==1)
{
q[schoo].score+=7
if (bisai>m)
q[schoo].girl.score+=7
else
q[schoo].boy.score+=7
p[bisai].sch[i].score=7
}
else if (i==2)
{
q[schoo].score+=5
if (bisai>m)
q[schoo].girl.score+=5
else
q[schoo].boy.score+=5
p[bisai].sch[i].score=5
} else if (i==3)
{
q[schoo].score+=3
if (bisai>m)
q[schoo].girl.score+=3
else
q[schoo].boy.score+=3
p[bisai].sch[i].score=3
}
else if (i==4)
{
q[schoo].score+=2
if (bisai>m)
q[schoo].girl.score+=2
else
q[schoo].boy.score+=2
p[bisai].sch[i].score=2
}
else
{
q[schoo].score+=1
if (bisai>m)
q[schoo].girl.score+=1
else
q[schoo].boy.score+=1
p[bisai].sch[i].score=1
}
}
} }
//cout<<q[5].boy.score<<endl
cout<<"\t\t\t成绩录入完毕...."<<endl<<endl
tin.close()
cout<<"跳回主界面 Y/N?"<<endl
pp=p
qq=q
cin>>c
if (c=='Y'||c=='y')
goto loop
else return 0
//else return 0
}
else if (flag==2)
{
system("cls")
cout<<"\t\t 【按学校编号排列】"<<endl
for (i=1i<=ni++)
cout<<q[i].score<<endl
cout<<"显示完毕"<<endl
cout<<"\t\t\t 是否将文件保存Y/N??"<<endl
cin>>c
system("cls")
if (c=='y'||c=='Y')
{
cout<<"\t\t\t*******请输入要保存到的文件名******"<<endl
save2(q,n)
}
cout<<"跳回主界面 Y/N?"<<endl
cin>>c
if (c=='Y'||c=='y')
goto loop
else return 0 //getchar()
//goto loop
}
else if (flag==3)
{
q=qq
sort(q+1,q+n+1,cmp)
system("cls")
cout<<"\t\t【学校总分按小到大排列】"<<endl
cout<<"ID"<<" "<<"score"<<endl
for (i=1i<=ni++)
cout<<q[i].ID<<" "<<q[i].score<<endl
cout<<"显示完毕"<<endl
cout<<"\t\t\t 是否将文件保存Y/N??"<<endl
cin>>c
system("cls")
if (c=='y'||c=='Y')
{
cout<<"\t\t\t*******请输入要保存到的文件名******"<<endl
save2(q,n) }
goto loop
/*cout<<"跳回主界面 Y/N?"<<endl
cin>>c
if (c=='Y'||c=='y')
else return 0*/
}
else if (flag==4)
{
q=qq
sort(q+1,q+n+1,cmp1)
system("cls")
cout<<"\t\t按男生团体总分排名"<<endl<<endl
cout<<"ID "<<"SCORE"<<endl
for (i=1i<=ni++)
cout<<q[i].ID<<" "<<q[i].boy.score<<endl cout<<"\t\t\t 是否将文件保存Y/N??"<<endl
cin>>c
system("cls")
if (c=='y'||c=='Y')
{
cout<<"\t\t\t*******请输入要保存到的文件名******"<<endl
save2(q,n)
}
//cout<<"跳回主界面...."
// getchar()
goto loop
}
else if (flag==5)
{
q=qq
sort(q+1,q+n+1,cmp2)
system("cls")
cout<<"\t\t按女生团体总分排名"<<endl<<endl
cout<<"ID "<<"SCORE"<<endl
for (i=1i<=ni++)
cout<<q[i].ID<<" "<<q[i].girl.score<<endl
cout<<"\t\t\t 是否将文件保存Y/N??"<<endl
cin>>c
system("cls")
if (c=='y'||c=='Y')
{
cout<<"\t\t\t*******请输入要保存到的文件名******"<<endl
save2(q,n)
}
// cout<<"跳回主界面..."
// getchar()
goto loop
}
else if (flag==6)
{
int temp
int total
cout<<"\t\t\t请输入要查询的学校编号"<<endl
cin>>total
cout<<endl
cout<<"\t\t\t请输入指定比赛项目编号"<<endl
cin>>temp
cout<<endl
for (i=1i++)
if(p[temp].sch[i].ID==total)
break
cout<<total<<"号学校在第"<<temp<<"次比赛中积分为:"<<endl
cout<<p[temp].sch[i].score<<endl cout<<"\t\t\t 是否将文件保存Y/N??"<<endl
cin>>c
if (c=='y'||c=='Y')
{
cout<<"\t\t\t*******请输入要保存到的文件名******"<<endl
save6(total,temp,p,i)
}
// cout<<"跳回主界面...."
// getchar()
goto loop
}
else if (flag==7) {
system("cls")
loop45:
cout<<"\t\t输入比赛编号"<<endl
cin>>temp
cout<<endl if (p[temp].Isthree)
for (i=1i<=3i++)
{
if (p[temp].sch[i].ID==-1)
{
cout<<"\t\t该比赛项目没有学校参与"<<endl
cout<<"\t\t重新选择...."<<endl
goto loop45
}
cout<<"第【"<<i<<"】名学校编号为:"<<p[temp].sch[i].ID<<endl
cout<<"得分: "<<p[temp].sch[i].score<<endl<<endl
}
else
for (i=1i<=5i++)
{
cout<<"第【"<<i<<"】名学校编号为:"<<p[temp].sch[i].ID<<endl
cout<<"得分: "<<p[temp].sch[i].score<<endl<<endl
}
cout<<"\t\t\t 是否将文件保存Y/N??"<<endl
cin>>c
system("cls")
if (c=='y'||c=='Y')
{
cout<<"\t\t\t*******请输入要保存到的文件名******"<<endl
save3(p,n,temp)
}
// cout<<"跳回主界面...."
//getchar()
goto loop
}
else
{
system("cls")
cout<<"\t\t谢谢使用...."<<endl
return 0
}
return 0
}
#include<iostream.h>#include<iomanip.h>
#include<string.h>
#include<fstream.h>
#include<stdlib.h>
#include<ctype.h>
#include<stdio.h>
#include<conio.h>
typedef struct Department//系的结构
{
char name[20] //系的名称
int number //系的编号
int boy //男子团体总分
int girl //女子团体总分
Department *next }Department
typedef struct Sport//运动项目结构
{
char name[20] //运动项目名称
int isboy //0为女项目,1为男项目
int is3 //0为取前五名,1为取前五名
int number //项目编号
int first //第一名系的编号
int second //第二名系的编号
int third //第三名系的编号
int fourth //第四名系的编号
int fifth //第五名系的编号
Sport *next
}Sport
int getint(int a)//字符转换成数字
{
return (int)(a-'0')
}
Department * head1
//-------启动画面函数----------
void Cover()
{ system("color 1b")
char line[]={"程序读取中 请耐心等待..."}
char bar[]={"...."}
int i,j,k=0,x=0,y=0
for(i=0i<=strlen(line)/2)
{
system("cls")
for(j=0j<9j++) //改变行坐标
cout<<endl
for(j=0j<(75-strlen(line))/2j++) //改变列坐标
cout<<" "
for(j=1j<=ij++) //进度显示器
cout<<"●"
for(x=strlen(line)/2x>ix--)
cout<<"○"
if(k==4)
i++
cout<<endl
for(j=0j<(75-strlen(line))/2j++) //行坐标定位
cout<<" "
cout<<line//输出线条
cout<<endl
for(j=0j<(65-strlen(bar))/2j++)
cout<<" "
cout<<(i+7)*5<<"% Loading"
cout.write(bar,k)
cout<<endl
for(j=0j<10j++)
cout<<endl
for(j=0j<24j++)
cout<<" "
cout<<"程序设计员5080906 石行"<<endl
for(j=0j<24j++)
cout<<" "
for(j=0j<=18j++)
cout<<"—"
cout<<endl
for(j=0j<10000000j++)//延时效果
k++
if(k>4)
k=0
}
}
void department_add()//添加系
{
Department * p
int mark=0
p=new Department
cout<<"请输入系的名称:"
cin>>p->name
char c
while (mark!=1)
{
cout<<"请输入系的编号:"
cin>>c
if (!isdigit(c))//是否为数字
{
cout<<"数据非法"<<endl
}
else
{
mark=1
p->number=c
}
}
p->boy=0
p->girl=0
p->next=head1->next
head1->next=p
cout<<"成功添加了一个系"<<endl
}
int department_getlong(Department *first)//得到链表长度
{
int i=0
while (first->next!=NULL)
{
i++
first=first->next
}
return i
}
void department_write()//将系数据写入文本
{
Department * p
p=head1
p=p->next
ofstream outfile("Department.txt",ios::out)
outfile<<department_getlong(p)+1<<" "
while (p!=NULL)
{
outfile<<p->name<<" "<<p->number<<" "<<p->boy<<" "<<p->girl<<" "
p=p->next
}
outfile.close()
cout<<"Write Success!"<<endl
}
void department_read()//从文本读入系数据
{
int i
ifstream infile ("Department.txt",ios::in)
infile>>i
while(i>0)
{
Department * p
p=new Department
infile>>p->name>>p->number>>p->boy>>p->girl
p->next=head1->next
head1->next=p
i--
}
cout<<"Department Data Read Success!"<<endl
}
void department_output(Department *p)//输出系
{
cout<<" 系名编号 男团总分 女团总分 总分\t\n"
while(p)
{
cout<<p->name<<" \t"<<getint(p->number)<<"\t"<<p->boy<<"\t"<<p->girl<<"\t "<<(p->girl+p->boy)<<endl
p=p->next
}
}
int department_isexist(int a)//检验系是否存在
{
int b=0
Department *p
p=head1
p=p->next
while(p)
{
if(p->number==a)
{
return 1
}
p=p->next
}
return 0
}
void department_show(int a)//输出所有系
{
Department *p
p=head1
p=p->next
while(p)
{
if(p->number==a)
{
cout<<p->name<<" "
return
}
p=p->next
}
cout<<" 无 "
}
void department_search(int a)//按编号搜索系
{
Department *p
p=head1
p=p->next
while(p)
{
if(p->number==a)
{
cout<<"系名:"<<p->name<<" "<<"男子团体总分:"<<p->boy<<" "<<"女子团体总分:"<<p->girl<<" "<<"总分:"<<(p->boy+p->girl)<<" "
return
}
p=p->next
}
cout<<"无此编号"
}
void department_addmark(int a,int b,int c)//a为分数,b为系编号,c=1表示男,c=0表示女
{
Department *p
p=head1
p=p->next
while(p)
{
if(p->number==b)
{
if(c=='1')
{
p->boy=p->boy+a
}
else
{
p->girl=p->girl+a
}
}
p=p->next
}
}
void department_order(Department *temp,int type) //type=0按总分,type=1按男总分,type=2按女总分,
{
Department *p,*q,*small,*temp1
temp1=new Department
temp1->next=NULL
p=temp
while(p)
{
small=p
q=p->next
while(q)
{
switch(type)
{
case 0:
if((q->boy+q->girl)<(small->girl+small->boy))
{
small=q
}
break
case 1:
if(q->boy<small->boy)
{
small=q
}
break
case 2:
if(q->girl<small->girl)
{
small=q
}
break
default:
cout<<"error"<<endl
}
if(small!=p)
{
temp1->boy=p->boy
p->boy=small->boy
small->boy=temp1->boy
temp1->girl=p->girl
p->girl=small->girl
small->girl=temp1->girl
strcpy(temp1->name,p->name)
strcpy(p->name,small->name)
strcpy(small->name,temp1->name)
temp1->number=p->number
p->number=small->number
small->number=temp1->number //将系的名字互换
}
q=q->next
}
p=p->next
}
}
Sport * head2
int sport_isexist(int a)//检查运动项目(编号)是否已经存在
{
int b=0
Sport *p
p=head2
p=p->next
while(p)
{
if(p->number==a)
{
return 1
}
p=p->next
}
return 0
}
void sport_add()//添加项目
{
Sport * p
int mark=0
p=new Sport
cout<<"请输入项目名称:"
cin>>p->name
char c
while (mark!=1)
{
cout<<"请输入项目编号:"
cin>>c
if (!isdigit(c))
{
cout<<"数据非法"<<endl
}
else
{
if(sport_isexist(c))
{
cout<<"该编号已存在"<<endl
}
else
{
mark=1
p->number=c
}
}
}
mark=0
while (mark!=1)
{
cout<<"请输入项目类型(0为女子项目,1为男子项目):"
cin>>c
p->isboy=(int)(c-'0')//字符转换成数字
if (!isdigit(c))
{
cout<<"数据非法"<<endl
}
else if(p->isboy<0||p->isboy>1)
{
cout<<"数据非法"<<endl
}
else
{
mark=1
p->isboy=c
}
}
mark=0
while (mark!=1)
{
cout<<"请输入项目名次情况(0为取前3名,1为取前5名):"
cin>>c
p->is3=(int)(c-'0')
if (!isdigit(c))
{
cout<<"数据非法"<<endl
}
else if(p->is3<0||p->is3>1)
{
cout<<"数据非法"<<endl
}
else
{
mark=1
p->is3=c
}
}
mark=0
while (mark!=1)
{
cout<<"请输入第一名的系的编号:"
cin>>c
if (!isdigit(c))
{
cout<<"数据非法"<<endl
}
else
{
if(!department_isexist(c))
{
cout<<"该系不存在,请先添加"
}
else
{
mark=1
p->first=c
if(p->is3=='0')
department_addmark(5,c,p->isboy)
else
department_addmark(7,c,p->isboy)
}
}
}
mark=0
while (mark!=1)
{
cout<<"请输入第二名的系的编号:"
cin>>c
if (!isdigit(c))
{
cout<<"数据非法"<<endl
}
else
{
if(!department_isexist(c))
{
cout<<"该系不存在,请先添加"
}
else
{
mark=1
p->second=c
if(p->is3=='0')
department_addmark(3,c,p->isboy)
else
department_addmark(5,c,p->isboy)
}
}
}
mark=0
while (mark!=1)
{
cout<<"请输入第三名的系的编号:"
cin>>c
if (!isdigit(c))
{
cout<<"数据非法"<<endl
}
else
{
if(!department_isexist(c))
{
cout<<"该系不存在,请先添加"
}
else
{
mark=1
p->third=c
if(p->is3=='0')
department_addmark(2,c,p->isboy)
else
department_addmark(3,c,p->isboy)
}
}
}
mark=0
if(p->is3=='1')
{
while (mark!=1)
{
cout<<"请输入第四名的系的编号:"
cin>>c
if (!isdigit(c))
{
cout<<"数据非法"<<endl
}
else
{
if(!department_isexist(c))
{
cout<<"该系不存在,请先添加"
}
else
{
mark=1
p->fourth=c
department_addmark(2,c,p->isboy)
}
}
}
mark=0
while (mark!=1)
{
cout<<"请输入第五名的系的编号:"
cin>>c
if (!isdigit(c))
{
cout<<"数据非法"<<endl
}
else
{
if(!department_isexist(c))
{
cout<<"该系不存在,请先添加"<<endl
}
else
{
mark=1
p->fifth=c
department_addmark(1,c,p->isboy)
}
}
}
}
else
{
p->fourth='0'
p->fifth='0'
}
p->next=head2->next
head2->next=p
cout<<"成功添加了一个运动项目"<<endl
}
int sport_getlong(Sport *first)//得到项目链表长度
{
int i=0
while (first->next!=NULL)
{
i++
first=first->next
}
return i
}
void sport_write()//将项目数据写入文本文档
{
Sport * p
p=head2
p=p->next
ofstream outfile("Sport.txt",ios::out)
outfile<<sport_getlong(p)+1<<" "
while (p!=NULL)
{
outfile<<p->name<<" "<<p->number<<" "<<p->isboy<<" "<<p->is3<<" "<<p->first<<" "<<p->second<<" "<<p->third<<" "<<p->fourth<<" "<<p->fifth<<" "
p=p->next
}
outfile.close()
cout<<"Write Success!"<<endl
}
void sport_read()//从文本读取项目数据
{
int i
ifstream infile ("Sport.txt",ios::in)
infile>>i
while(i>0)
{
Sport * p
p=new Sport
infile>>p->name>>p->number>>p->isboy>>p->is3>>p->first>>p->second>>p->third>>p->fourth>>p->fifth
p->next=head2->next
head2->next=p
i--
}
cout<<"Sport Data Read Success!"<<endl
}
void sport_output(Sport *p)//输出项目的情况
{
cout<<"name "<<"\t"<<"Num"<<" "<<"B/G"<<" "<<" 3/5"<<""<<" first"<<" "<<"second"<<" "<<"third"<<" "<<"fourth"<<" "<<"fifth"<<" "<<endl
while(p)
{
cout<< p->name <<"\t" <<" "<<getint(p->number)<<" " << getint(p->isboy)<<" " <<getint(p->is3)<<" "<<" "
department_show(p->first)
department_show(p->second)
department_show(p->third)
department_show(p->fourth)
department_show(p->fifth)
//printf("\n")
p=p->next
cout<<"\n"
}
cout<<endl
}
void sport_search(int a)//搜索项目
{
Sport *p
p=head2
p=p->next
while(p)
{
if(p->number==a)
{
cout<<"项目名:"<<p->name<<endl<<"项目类型:"
if(p->isboy==1)
{
cout<<"男子项目"
}
else
{
cout<<"女子项目"
}
cout<<endl<<"第一名:"
department_show(p->first)
cout<<endl<<"第二名:"
department_show(p->second)
cout<<endl<<"第三名:"
department_show(p->third)
cout<<endl<<"第四名:"
department_show(p->fourth)
cout<<endl<<"第五名:"
department_show(p->fifth)
return
}
p=p->next
}
cout<<"无此编号"
}
void main()//运动会程序主函数
{
Cover()
system("color 2b") //改变背景,前景色
head1=new Department
head1->next=NULL
head2=new Sport
head2->next=NULL
//school_add()
sport_read()
department_read()
//sport_add()
Department * p1
Sport * p2
p1=head1
p1=p1->next
p2=head2
p2=p2->next
char choose
char temp
//string ch=" "
int a=1
while(a!=0)
{
cout<<endl
cout<<" .oO欢迎使用运动会分数统计系统Oo. "<<endl
cout<<" **********************************************************"<<endl
cout<<" **"<<endl
cout<<" * 1.输入系别2.输入运动项目 *"<<endl
cout<<" **"<<endl
cout<<" * 3.按系别编号输出总分 4.按总分排序 *"<<endl
cout<<" **"<<endl
cout<<" * 5.按男团体总分排序6.按女团体总分排序 *"<<endl
cout<<" **"<<endl
cout<<" * 7.按项目编号查询 8.按系别编号查询 *"<<endl
cout<<" **"<<endl
cout<<" * 0.退出 *"<<endl
cout<<" **"<<endl
cout<<" * 提示:需先输入系别后才能输入运动项目 *"<<endl
cout<<" **"<<endl
cout<<" **********************************************************"<<endl
cout<<" 请选择:"
//cin>>ch
//choose=int(ch[0])+int(ch[1])-'0' //处理异常状态
cin>>choose
if (!isdigit(choose))
{
system("cls")
cout<<"操作非法1"<<endl
}
else
{
switch(getint(choose))
{
case 1:
system("cls")
department_add()
break
case 2:
system("cls")
cout<<"当前项目:"<<endl
sport_output(p2)
cout<<"当前系:"<<endl
department_output(p1)
sport_add()
break
case 3:
system("cls")
department_output(p1)
break
case 4:
system("cls")
department_order(p1,0)
department_output(p1)
break
case 5:
system("cls")
department_order(p1,1)
department_output(p1)
break
case 6:
system("cls")
department_order(p1,2)
department_output(p1)
break
case 7:
system("cls")
cout<<"请输入项目编号:"
cin>>temp
sport_search(temp)
break
case 8:
system("cls")
cout<<"请输入系的编号:"
cin>>temp
department_search(temp)
break
case 0:
system("cls")
a=0
break
default:
system("cls")
cout<<"操作非法\n"
}
}
}
department_write()
sport_write()
system("exit")
}