C语言课程设计 要求编写一段程序 题目是《运动会分数统计系统》

1实验描述
参加运动会有N个学校,学校编号为1……m,女子 m+1…… m+w。不同的项目取前五名或前三名积分;取前五名的积分分别为:7.5.4.2.1 ,前三名的积分分别为:5、3、2;哪些 取前五名或前三名由自己设定。(m<=20,n>=20)
2.实验要求
功能要求:1)可以输入各个项目的前三名或前五名的成绩
2)能统计各学校总分,
3)可以按学校编号、学校总分、男女团体总分排序输出;
4)可以按学校编号查询学校某个醒目的情况;可以按项目编号查询取得前三或前五名的学校
规定:输入数据形式和范围:20以内的整数(如果做的更好可以输入学校 的名称,运动项目的名称)
输出形式:有中文提示。各学校分数为整数
界面要求:有合理的提示,每个功能可以设定菜单,根据提示,可以完成相关的功能要求。
存储结构:学生自己根据系统功能要求自己设计,但是要求运动会的相关数据要存储在数据文件中。
测试数据:要求使用1、全部合法数据;2、整体非法数据;3、局部非法数据。进行程序测试,以保证程序的稳定

第1个回答  2010-06-24
#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=0;i<=strlen(line)/2;)
{
system("cls");
for(j=0;j<9;j++) //改变行坐标
cout<<endl;
for(j=0;j<(75-strlen(line))/2;j++) //改变列坐标
cout<<" ";
for(j=1;j<=i;j++) //进度显示器
cout<<"●";
for(x=strlen(line)/2;x>i;x--)
cout<<"○";
if(k==4)
i++;
cout<<endl;
for(j=0;j<(75-strlen(line))/2;j++) //行坐标定位
cout<<" ";
cout<<line; //输出线条
cout<<endl;
for(j=0;j<(65-strlen(bar))/2;j++)
cout<<" ";
cout<<(i+7)*5<<"% Loading";
cout.write(bar,k);
cout<<endl;
for(j=0;j<10;j++)
cout<<endl;
for(j=0;j<24;j++)
cout<<" ";
cout<<"程序设计员5080906 石行"<<endl;
for(j=0;j<24;j++)
cout<<" ";
for(j=0;j<=18;j++)
cout<<"—";
cout<<endl;
for(j=0;j<10000000;j++);//延时效果
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");
}
第2个回答  推荐于2021-02-02
#include <malloc.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define NULL 0
#define MaxSize 30

typedef struct athletestruct /*运动员*/
{
char name[20];
int score; /*分数*/
int range; /**/
int item; /*项目*/
}ATH;
typedef struct schoolstruct /*学校*/
{
int count; /*编号*/
int serial; /**/
int menscore; /*男选手分数*/
int womenscore; /*女选手分数*/
int totalscore; /*总分*/
ATH athlete[MaxSize]; /**/
struct schoolstruct *next;
}SCH;

int nsc,msp,wsp;
int ntsp;
int i,j;
int overgame;
int serial,range;
int n;
SCH *head,*pfirst,*psecond;
int *phead=NULL,*pafirst=NULL,*pasecond=NULL;

input ()
{
char answer;
head = (SCH *)malloc(sizeof(SCH)); /**/
head->next = NULL;
pfirst = head;
answer = 'y';
while ( answer == 'y' )
{
Is_Game_DoMain:
printf("\nGET Top 5 when odd\nGET Top 3 when even");
printf("\n输入运动项目序号 (x<=%d):",ntsp);
scanf("%d",pafirst);
overgame = *pafirst;
if ( pafirst != phead )
{
for ( pasecond = phead ; pasecond < pafirst ; pasecond ++ )
{
if ( overgame == *pasecond )
{
printf("\n这个项目已经存在请选择其他的数字\n");
goto Is_Game_DoMain;
}
}
}
pafirst = pafirst + 1;
if ( overgame > ntsp )
{
printf("\n项目不存在");
printf("\n请重新输入");
goto Is_Game_DoMain;
}
switch ( overgame%2 )
{
case 0: n = 3;break;
case 1: n = 5;break;
}
for ( i = 1 ; i <= n ; i++ )
{
Is_Serial_DoMain:
printf("\n输入序号 of the NO.%d (0<x<=%d): ",i,nsc);

scanf("%d",&serial);
if ( serial > nsc )
{
printf("\n超过学校数目,请重新输入");
goto Is_Serial_DoMain;
}
if ( head->next == NULL )
{
create();
}
psecond = head->next ;
while ( psecond != NULL )
{
if ( psecond->serial == serial )
{
pfirst = psecond;
pfirst->count = pfirst->count + 1;
goto Store_Data;
}
else
{
psecond = psecond->next;
}
}
create();
Store_Data:

pfirst->athlete[pfirst->count].item = overgame;
pfirst->athlete[pfirst->count].range = i;
pfirst->serial = serial; ("Input name:) : ");

scanf("%s",pfirst->athlete[pfirst->count].name);
}
printf("\n继续输入运动项目(y&n)?");
answer = getch();
printf("\n");
}
}

calculate() /**/
{
pfirst = head->next;
while ( pfirst->next != NULL )
{
for (i=1;i<=pfirst->count;i++)
{
if ( pfirst->athlete[i].item % 2 == 0 )
{
switch (pfirst->athlete[i].range)
{
case 1:pfirst->athlete[i].score = 5;break;
case 2:pfirst->athlete[i].score = 3;break;
case 3:pfirst->athlete[i].score = 2;break;
}
}
else
{
switch (pfirst->athlete[i].range)
{
case 1:pfirst->athlete[i].score = 7;break;
case 2:pfirst->athlete[i].score = 5;break;
case 3:pfirst->athlete[i].score = 3;break;
case 4:pfirst->athlete[i].score = 2;break;
case 5:pfirst->athlete[i].score = 1;break;
}
}
if ( pfirst->athlete[i].item <=msp )
{
pfirst->menscore = pfirst->menscore + pfirst->athlete[i].score;
}
else
{
pfirst->womenscore = pfirst->womenscore + pfirst->athlete[i].score;
}
}
pfirst->totalscore = pfirst->menscore + pfirst->womenscore;
pfirst = pfirst->next;
}
}

output()
{
pfirst = head->next;
psecond = head->next;
while ( pfirst->next != NULL )
{
clrscr();
printf("\n第%d号学校的结果成绩:",pfirst->serial);
printf("\n\n项目的数目\t学校的名字\t分数");
for (i=1;i<=ntsp;i++)
{
for (j=1;j<=pfirst->count;j++)
{
if ( pfirst->athlete[j].item == i )
{

printf("\n %d\t\t\t\t\t\t%s\n %d",i,pfirst->athlete[j].name,pfirst->athlete[j].score);break;

}
}
}
printf("\n\n\n\t\t\t\t\t\t按任意建 进入下一页");
getch();
pfirst = pfirst->next;
}
clrscr();
printf("\n运动会结果:\n\n学校编号\t男运动员成绩\t女运动员成绩\t总分");
pfirst = head->next;
while ( pfirst->next != NULL )
{
printf("\n %d\t\t %d\t\t %d\t\t %d",pfirst->serial,pfirst->menscore,pfirst->womenscore,pfirst->totalscore);
pfirst = pfirst->next;
}
printf("\n\n\n\t\t\t\t\t\t\t按任意建结束");
getch();
}

create()
{

pfirst = (struct schoolstruct *)malloc(sizeof(struct schoolstruct));
pfirst->next = head->next ;
head->next = pfirst ;

pfirst->count = 1;
pfirst->menscore = 0;
pfirst->womenscore = 0;
pfirst->totalscore = 0;
}
void Save()
{FILE *fp;
if((fp = fopen("school.dat","wb"))==NULL)
{printf("can't open school.dat\n");
fclose(fp);
return;
}
fwrite(pfirst,sizeof(SCH),10,fp);
fclose(fp);
printf("文件已经成功保存\n");
}

main()
{
system("cls");
printf("\n\t\t\t 运动会分数统计\n");
printf("输入学校数目 (x>= 5):");
scanf("%d",&nsc);
printf("输入男选手的项目(x<=20):");
scanf("%d",&msp);
printf("输入女选手项目(<=20):");
scanf("%d",&wsp);
ntsp = msp + wsp;

phead = calloc(ntsp,sizeof(int));
pafirst = phead;
pasecond = phead;
input();
calculate();
output();
Save();
}本回答被提问者采纳

C语言课程设计~~~ 要求编写一段程序,题目是《校际运动会管理系统》
我这是源代码已经调试过了,在VC++上运行成功了。include "stdio.h" \/*I\/O函数*\/ include "stdlib.h" \/*其它说明*\/ include "string.h" \/*字符串函数*\/ include "conio.h" \/*屏幕操作函数*\/ include "mem.h" \/*内存操作函数*\/ include "ctype.h" \/*字符操作函数*\/...

C语言编写 运动会分数统计系统
include <malloc.h> #include <stdio.h> #include <stdlib.h> #include <string.h> #define NULL 0 #define MaxSize 30 typedef struct athletestruct \/*运动员*\/ { char name[20]; int score; \/*分数*\/ int range; \/**\/ int item; \/*项目*\/ }ATH; typedef st...

c语言程序设计题。实验报告。高分。
一、实习题目:1)运动会分数统计;任务:参加运动会有n个学校,学校编号为1……n.比赛分成m个男子项目,和w个女子项目.项目编号为男子1...m,女子m+1...m+w.不同的项目取前五名或前... 一、实习题目:1)运动会分数统计;任务:参加运动会有n个学校,学校编号为1……n.比赛分成m个男子项目,和w个女子项目.项...

运动会分数统计
while(1){ scanf("%d%d",&m,&w);if(m<=20&&m>=1&&w<=20&&w>=1)y=1;if(y)break;else printf("输入数据有误,请重新输入:");} for(i=1;i<=m+w;i++){ printf("输入第%d个项目的名称:\\n",i);scanf("%s",& p[i].name);printf("输入第%d个项目的前5名的学校编号:\\n...

运动会分数统计系统
界面要求:有合理的提示,每个功能可以设立菜单,根据提示,可以完成相关的功能要求。存储结构:学生自己根据系统功能要求自己设计,但是要求运动会的相关数据要存储在数据文件中。用C语言实现这是我们的数据结构课程设计牛人帮帮忙吧,被采纳为答案后会另外给积分帮助别人,自己的编程水平也得到了提高,多好啊 四楼的貌似是C++...

1、 运动会分数统计 2、航空订票系统
ap30rajkdsafjoweu3oujdw8aujksdsa4fnjnjmckj99 参考资料:www.baidu.com\/1266586.cn

求数据结构课程设计 《运动会分数统计》要有完整的报告。 有的直接发...
存储结构:学生自己根据系统功能要求自己设计,但是要求运动会的相关数据要存储在数据文件中。(数据文件的数据读写方法等相关内容在c语言程序设计的书上,请自学解决)请在最后的上交资料中指明你用到的存储结构;测试数据:要求使用1、全部合法数据;2、整体非法数据;3、局部非法数据。进行程序测试,以保证程序的稳定。测试数...

相似回答