实验要求
(1)录入各运动项目信息(项目类别编号,项目编号,项目名称,本校男子历史记录 本校女子历史记录),其中历史记录根据田赛、径赛分别记录时间值(时:分:秒)和长度值(float类型(米))。因此建议使用共用体完成类型定义。运动项目内容通常不插入删除,只可查询或修改(如历史记录值的修改)。
(2)录入所有参赛运动员的个人信息(学号,姓名,性别,学院编号),并存储在文件中。对于运动员信息可以做到:插入、修改、删除等。
(3)运动员所报项目登记表的录入:(学号,项目类别号,运动项目号,成绩,名次,是否打破记录),后三项在初始录入时全部为0.对于运动员参赛可以做到:插入一个报名,修改所报项目、删除报名。
(4)记分规则:对于每一运动项目,将所有参加本项目的男子(或者女子)按得分显示前6名,分别记入成绩每项目取前三名,分别记分为10,7,5、4、3、2分,所有参赛人员均记入1分。而对于破记录的运动员记入20分。
(5)能查找每个学生(按姓名、学号等)运动项目以及各运动项目的名次及得分。
(6)能随时统计目前整个运动会各项目的男子和女子项目的最高成绩并判断该成绩是否可打破本校记录,如果打破记录,除了信息提示“祝贺***同学本次运动会在男子(或女子)***项目上打破本校历史记录!”。同时更新历史记录值。
(7)统计各学院参赛总人数、各项目参赛人数,各项目男、女学生参赛人数。
(8)统计各学院在本届运动会上总分结果存入文件中以备查询,并显示排名表。
(9)学院名查询本届运动会总得分及名次。
设计思路
源代码
头文件
#pragma once
#define _CRT_SECURE_NO_WARNINGS 1
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <windows.h>
#include <malloc.h>
//历史记录
union History
{
char time[10]; //田赛时间
float meter; //径赛长度
};
//成绩
union Score
{
char time[10]; //田赛时间
float meter; //径赛长度
};
//运动项目
typedef struct Sport_event
{
char cate_num[10]; //项目类别编号
char item_num[10]; //项目编号
char pro_name[15]; //项目名称
union History man; //本校男子历史记录
union History woman; //本校女子历史记录
struct Sport_event* next;
}sport_event;
//运动员信息
typedef struct Athlete_inform
{
char number[10]; //学号
char name[20]; //姓名
char sex[5]; //性别
char school_num[8]; //学院编号
struct Athlete_inform* next;
}athlete_inform;
//运动员登记表
typedef struct Athlete_reg
{
char number[10]; //学号
char cate_num[10]; //项目类别号
char item_num[10]; //运动项目号
union Score score; //成绩
int ranking; //名次
char gudje[5]; //是否打破记录
struct Athlete_reg* next;
}athlete_reg;
//学院成绩及排名
typedef struct College
{
char school_num[8]; //学院编号
int point; //成绩
int ranking; //名次
struct College* next;
}college;
主菜单
#include "head.h"
int main()
{
system("color E0");
modeset(80, 25);
menu();
return 0;
}
//设置窗口大小
void modeset(int w, int h)
{
HANDLE hOut = GetStdHandle(STD_OUTPUT_HANDLE);
COORD size = { w, h };
SetConsoleScreenBufferSize(hOut, size);
SMALL_RECT rc = { 1,1, w, h };
SetConsoleWindowInfo(hOut, 1, &rc);
system("cls");
return;
}
//主菜单
void menu()
{
sport_event* head = Creat1();
athlete_inform* head1 = Creat2();
athlete_reg* head2 = Creat3();
int input;
printf("\n");
printf(" 欢迎来到学生运动会成绩数据库 !!! \n");
printf(" _____________________________________________________________ \n");
printf(" | |\n");
printf(" | 1.运动项目信息表 |\n");
printf(" | 2.参赛运动员的个人信息表 |\n");
printf(" | 3.运动员所报项目登记表 |\n");
printf(" | 4.登记成绩 |\n");
printf(" | 5.查看成绩及名次 |\n");
printf(" | 0.退出 |\n");
printf(" |_____________________________________________________________|\n");
printf(" 请选择:");
scanf("%d", &input);
switch (input)
{
case 0:
system("cls");
exit(-1);
break;
case 1:
system("cls");
event_menu();
break;
case 2:
system("cls");
inform_menu();
break;
case 3:
system("cls");
reg_menu();
break;
case 4:
Init_eventx(&head);
Init_athlete(&head1);
Init_score_reg(&head2);
system("cls");
score_menu(&head,&head1,&head2);
break;
case 5:
Init_eventx(&head);
Init_athlete(&head1);
Init_score_reg(&head2);
system("cls");
collect_menu(&head,&head1,&head2);
break;
default:
printf(" 输入错误!请重新输入!\n");
Sleep(1500);
system("cls");
menu();
}
}
//将项目文件中的信息存储到项目链表中
void Init_eventx(sport_event** head)
{
sport_event* ch = (*head);
FILE* pf = fopen("event.txt", "r");
if (pf == NULL) //打开失败
{
printf("\n");
printf(" 文件打开失败!无法进行操作!\n");
Sleep(1200);
system("cls");
menu();
}
else
{
char str[20] = { 0 };
while (fscanf(pf, "%s", str) != EOF)
{
sport_event* temp = Creat1();
strcpy(temp->cate_num, str);
fscanf(pf, "%s", temp->item_num);
fscanf(pf, "%s", temp->pro_name);
if (strcmp(str, "1001") == 0)//田赛
{
fscanf(pf, "%s", temp->man.time);
fscanf(pf, "%s", temp->woman.time);
}
else
{
fscanf(pf, "%f", &temp->man.meter);
fscanf(pf, "%f", &temp->woman.meter);
}
ch->next = temp;
temp->next = NULL;
ch = temp;
}
}
}
//将运动员所报项目文件中的信息存储到运动员所报项目链表中
void Init_score_reg(athlete_reg** head)
{
athlete_reg* ch = (*head);
FILE* pf = fopen("athlete_reg.txt", "r");
if (pf == NULL) //打开失败
{
printf("\n");
printf(" 文件打开失败!无法进行操作!\n");
Sleep(1200);
system("cls");
menu();
}
else
{
char str[20] = { 0 };
while (fscanf(pf, "%s", str) != EOF)
{
athlete_reg* temp = Creat3();
strcpy(temp->number, str);
fscanf(pf, "%s", temp->cate_num);
fscanf(pf, "%s", temp->item_num);
if (strcmp(temp->cate_num, "1001") == 0)//田赛
{
fscanf(pf, "%s", temp->score.time);
}
else
{
fscanf(pf, "%f", &temp->score.meter);
}
fscanf(pf, "%d", &temp->ranking);
fscanf(pf, "%s", temp->gudje);
ch->next = temp;
temp->next = NULL;
ch = temp;
}
}
}
//将运动员信息文件中的信息存储到运动员信息链表中
void Init_athlete(athlete_inform** head)
{
athlete_inform* ch = (*head);
FILE* pf = fopen("athlete_inform.txt", "r");
if (pf == NULL) //打开失败
{
printf("\n");
printf(" 文件打开失败!无法进行操作!\n");
Sleep(1200);
system("cls");
menu();
}
else
{
char str[20] = { 0 };
while (fscanf(pf, "%s", str) != EOF)
{
athlete_inform* temp = Creat2();
strcpy(temp->number, str);
fscanf(pf, "%s", temp->name);
fscanf(pf, "%s", temp->sex);
fscanf(pf, "%s", temp->school_num);
ch->next = temp;
temp->next = NULL;
ch = temp;
}
}
}
录入成绩
#include "head.h"
athlete_reg* Creat3()
{
athlete_reg* newnode = (athlete_reg*)malloc(sizeof(athlete_reg));
if (newnode == NULL)
{
perror("error:");
exit(-1);
}
newnode->next = NULL;
return newnode;
}
//菜单
void score_menu(sport_event** head, athlete_inform** head1, athlete_reg** head2)
{
int input;
printf("\n");
printf(" _____________________________________________________________ \n");
printf(" | |\n");
printf(" | 1.录入成绩 |\n");
printf(" | 2.修改成绩 |\n");
printf(" | 3.保存成绩(保存后记分) |\n");
printf(" | 0.返回 |\n");
printf(" |_____________________________________________________________|\n");
printf(" 请选择:");
scanf("%d", &input);
switch (input)
{
case 0:
system("cls");
menu();
break;
case 1:
system("cls");
Init_score(head,head1,head2);
break;
case 2:
system("cls");
modif_score(head,head1, head2);
break;
case 3:
system("cls");
save_score(head,head1, head2);
break;
default:
printf(" 输入错误!请重新输入!\n");
Sleep(1500);
system("cls");
save_score(head,head1, head2);
}
}
void Init_score(sport_event** head, athlete_inform** head1, athlete_reg** head2)
{
char arr1[20] = { 0 }, arr2[20] = { 0 };
char str1[20] = { 0 };
float str2 = 0;
int a[10] = { 0 };
int choice = 0;
printf("\n 请选择你选择的登记方式(1.学号 2.项目编号):");
scanf("%d", &choice);
if (choice == 1)
{
printf("\n 请选择你要登记数据的学号:");
scanf("%s", arr1);
search_reg("athlete_reg.txt", arr1, a);
printf(" 请选择你要登记数据的项目编号:");
scanf("%s", arr2);
}
else
{
if (choice == 2)
{
printf(" 请选择你要登记数据的项目编号:");
scanf("%s", arr2);
search_reg("athlete_reg.txt", arr2, a);
printf("\n 请选择你要登记数据的学号:");
scanf("%s", arr1);
}
else
{
printf(" 输入错误!\n");
Sleep(1500);
system("cls");
Init_score(head, head1, head2);
}
}
athlete_reg* temp = *head2;
while (temp != NULL)
{
if (strcmp(temp->number, arr1) == 0 && strcmp(temp->item_num, arr2) == 0)
{
printf(" 查找成功!\n");
printf(" 学号 项目类别号 运动项目号 成绩 名次 是否打破记录\n");
if (strcmp(temp->cate_num, "1001") == 0)//田赛
{
printf(" %s%10s%11s%14s%10d%11s\n", temp->number, temp->cate_num, temp->item_num, temp->score.time, temp->ranking, temp->gudje);
printf(" 请输入成绩(时间):");
scanf("%s", str1);
strcpy(temp->score.time, str1);
judge1(head1, temp->number, temp->item_num, str1);
}
else
{
printf(" %s%10s%11s%14f%10d%11s\n", temp->number, temp->cate_num, temp->item_num, temp->score.meter, temp->ranking, temp->gudje);
printf(" 请输入成绩(米):");
scanf("%f", &str2);
temp->score.meter = str2;
judge2(head1, temp->number, temp->item_num, str2);
}
printf(" 登记成功!\n");
printf(" ");
system("pause");
system("cls");
score_menu(head,head1, head2);
}
else
{
temp = temp->next;
}
}
printf(" 查找失败!");
printf(" ");
system("pause");
system("cls");
score_menu(head, head1, head2);
}
//判断是否破田赛最高
void judge1(athlete_inform** head,char number[],char item[],char arr[])
{
int line = 0;
athlete_inform* temp = NULL;
temp = (*head)->next;
while (strcmp(temp->number, number) != 0)
{
temp = temp->next;
}
FILE* pf = fopen("event.txt", "r");
if (pf == NULL)
{
printf(" 文件打开失败!");
exit(-1);
}
char ch[20] = { 0 };
char man[20] = { 0 };
char woman[20] = { 0 };
while (strcmp(item, ch) != 0)
{
fscanf(pf, "%s", ch);
line++;
}
fscanf(pf, "%s", ch);
fscanf(pf, "%s", man);
fscanf(pf, "%s", woman);
if (strcmp(temp->sex, "男") == 0)//时间越短,分数越高
{
if (strcmp(arr, man) < 0)//超过记录
{
printf(" 祝贺%s同学本次运动会在男子%s项目上打破本校历史记录!\n", temp->name, ch);
line += 2;
change("event.txt", line, arr);
}
}
else
{
if (strcmp(arr, woman) < 0)//超过记录
{
printf(" 祝贺%s同学本次运动会在女子%s项目上打破本校历史记录!\n",temp->name, ch);
line += 3;
change("event.txt", line, arr);
}
}
fclose(pf);
}
//判断是否破径赛最高
void judge2( athlete_inform** head, char number[],char item[], float arr)
{
int line = 0;
float man = 0, woman = 0;
char* pc = (char*)&arr;
char c[4] = { 0 };
athlete_inform* temp = NULL;
temp = (*head)->next;
while (strcmp(temp->number, number) != 0)
{
temp = temp->next;
}
FILE* pf = fopen("event.txt", "r");
if (pf == NULL)
{
printf(" 打开失败!");
}
else
{
char ch[20] = { 0 };
while (strcmp(item, ch) != 0)
{
fscanf(pf, "%s", ch);
line++;
}
fscanf(pf, "%s", ch);
fscanf(pf, "%f", &man);
fscanf(pf, "%f", &woman);
if (strcmp(temp->sex, "男") == 0)//米数越大,分数越高
{
if (arr > man)//超过记录
{
printf(" 祝贺%s同学本次运动会在男子%s项目上打破本校历史记录!\n", temp->name, ch);
line += 2;
for (int i = 0; i < 4; i++)
{
c[i] = *(pc + i);
}
pc = c;
change("event.txt", line, pc);
}
}
else
{
if (arr > woman)//超过记录
{
printf(" 祝贺%s同学本次运动会在女子%s项目上打破本校历史记录!\n", temp->name, ch);
line += 3;
for (int i = 0; i < 4; i++)
{
c[i] = *(pc + i);
}
pc = c;
change("event.txt", line, pc );
}
}
fclose(pf);
}
}
//修改
void modif_score(sport_event** head, athlete_inform** head1, athlete_reg** head2)
{
char arr1[20] = { 0 }, arr2[20] = { 0 };
char str1[20] = { 0 };
float str2 = 0;
int choice = 0;
int a[10] = { 0 };
printf("\n 请选择你选择的修改方式(1.学号 2.项目编号):");
scanf("%d", &choice);
if (choice == 1)
{
printf("\n 请选择你要修改数据的学号:");
scanf("%s", arr1);
search_reg("athlete_reg.txt", arr1, a);
printf(" 请选择你要修改数据的项目编号:");
scanf("%s", arr2);
}
else
{
if (choice == 2)
{
printf(" 请选择你要登记数据的项目编号:");
scanf("%s", arr2);
search_reg("athlete_reg.txt", arr2, a);
printf("\n 请选择你要登记数据的学号:");
scanf("%s", arr1);
}
else
{
printf(" 输入错误!\n");
Sleep(1500);
system("cls");
Init_score(head, head1, head2);
}
}
athlete_reg* temp = *head2;
while (temp != NULL)
{
if (strcmp(temp->number, arr1) == 0 && strcmp(temp->item_num, arr2) == 0)
{
printf(" 查找成功!\n");
printf(" 学号 项目类别号 运动项目号 成绩 名次 是否打破记录\n");
if (strcmp(temp->cate_num, "1001") == 0)//田赛
{
printf(" %s%10s%11s%14s%10d%11s\n", temp->number, temp->cate_num, temp->item_num, temp->score.time, temp->ranking, temp->gudje);
printf(" 请输入成绩(时间):");
scanf("%s", str1);
strcpy(temp->score.time, str1);
judge1(head1, temp->number, temp->item_num, str1);
}
else
{
printf(" %s%10s%11s%14f%10d%11s\n", temp->number, temp->cate_num, temp->item_num, temp->score.meter, temp->ranking, temp->gudje);
printf(" 请输入成绩(米):");
scanf("%f", &str2);
temp->score.meter = str2;
judge2(head1, temp->number, temp->item_num, str2);
}
printf(" 登记成功!\n");
printf(" ");
system("pause");
system("cls");
score_menu(head, head1, head2);
}
else
{
temp = temp->next;
}
}
printf(" 查找失败!");
printf(" ");
system("pause");
system("cls");
score_menu(head, head1, head2);
}
//保存
void save_score(sport_event** head, athlete_inform** head1, athlete_reg** head2)
{
sort(head2);//排序并记分
//存储到文件中
is_histery(head, head1, head2);
FILE* pf = fopen("athlete_reg.txt", "w");
if (pf == NULL) //打开失败
{
printf("\n");
printf(" 文件打开失败!无法进行操作!\n");
Sleep(1200);
system("cls");
Init_reg();
}
else
{
athlete_reg* temp = (*head2)->next;
while (temp != NULL)
{
fputs(temp->number, pf);
fputs("\n", pf);
fputs(temp->cate_num, pf);
fputs("\n", pf);
fputs(temp->item_num, pf);
fputs("\n", pf);
if (strcmp(temp->cate_num, "1001") == 0)
{
fprintf(pf, "%s", temp->score.time);
}
else
{
fprintf(pf, "%f", temp->score.meter);
}
fputs("\n", pf);
fprintf(pf, "%d", temp->ranking);
fputs("\n", pf);
fputs(temp->gudje, pf);
fputs("\n", pf);
temp = temp->next;
}
fclose(pf);
printf("\n 保存成功!\n");
printf(" ");
system("pause");
system("cls");
score_menu(head,head1, head2);
}
}
void sort(athlete_reg** head)
{
int num1 = 0, num2 = 0,num = 0, j = 0;
athlete_reg* prev = (*head);
athlete_reg* head1 = (*head)->next;//田赛
athlete_reg* head2 = Creat3();//径赛
athlete_reg* tail = head2;
while (head1 != NULL)//区分田赛径赛
{
if (strcmp(head1->cate_num, "1002") == 0)
{
tail ->next = head1;
prev->next = head1->next;
head1->next = NULL;
tail = tail->next;
head1 = prev->next;
}
else
{
head1 = head1->next;
prev = prev->next;
}
}
athlete_reg *temp= (*head);//田赛排序
while (temp->next != NULL)
{
temp = temp->next;
num1++;
}
athlete_reg* p, * q, *s;
for (int i = 0; i < num1 - 1; i++)
{
s = (*head);
q = (*head)->next;
p = (*head)->next->next;
num = num1 - 1 - i;
while(num--)
{
if (strcmp(q->score.time , p->score.time) > 0) //交换,成绩好的靠前
{
q->next = p->next;
p->next = q;
s->next = p;
}
s = s->next;
q = s->next;
p = q->next;
}
}
temp = head2->next;//径赛排序
while (temp != NULL)
{
temp = temp->next;
num2++;
}
for (int i = 0; i < num2 - 1; i++)
{
s = head2;
q = head2->next;
p = head2->next->next;
num = num2 - 1 - i;
while (num--)
{
if (q->score.meter < p->score.meter) //交换,成绩好的靠前
{
q->next = p->next;
p->next = q;
s->next = p;
}
s = s->next;
q = s->next;
p = q->next;
}
}
temp = (*head)->next;
while (temp->next != NULL)
{
temp = temp->next;
}
temp->next = head2->next;
scoring(head);
printf("\n 排序完成!");
}
void scoring(athlete_reg** head)
{
rank(head, "01");
rank(head, "02");
rank(head, "03");
rank(head, "04");
rank(head, "05");
rank(head, "06");
rank(head, "07");
rank(head, "08");
rank(head, "09");
}
void rank(athlete_reg** head,char arr[10])
{
int x = 1;
athlete_reg* temp = (*head)->next;
while (temp != NULL)
{
if (strcmp(temp->item_num, arr) == 0)
{
temp->ranking = x;
x++;
}
temp = temp->next;
}
}
void is_histery(sport_event** head, athlete_inform** head1, athlete_reg** head2)
{
Init_eventx(head);
sport_event* temp1 = (*head)->next;
athlete_inform* temp2 = (*head1)->next;
athlete_reg* temp3 = (*head2)->next;
while (temp3 != NULL)
{
temp1 = (*head)->next;
temp2 = (*head1)->next;
while (strcmp(temp2->number, temp3->number) != 0)
{
temp2 = temp2->next;
}
while (strcmp(temp1->item_num, temp3->item_num) != 0)
{
temp1 = temp1->next;
}
if (strcmp(temp3->cate_num, "1001") == 0)
{
if (strcmp(temp2->sex, "男") == 0)
{
if (strcmp(temp1->man.time, temp3->score.time) == 0)
{
strcpy(temp3->gudje, "是");
}
else
{
strcpy(temp3->gudje, "否");
}
}
else
{
if (strcmp(temp1->woman.time, temp3->score.time) == 0)
{
strcpy(temp3->gudje, "是");
}
else
{
strcpy(temp3->gudje, "否");
}
}
}
else
{
if (strcmp(temp2->sex, "男") == 0)
{
if (temp1->man.meter== temp3->score.meter )
{
strcpy(temp3->gudje, "是");
}
else
{
strcpy(temp3->gudje, "否");
}
}
else
{
if (temp1->woman.meter == temp3->score.meter)
{
strcpy(temp3->gudje, "是");
}
else
{
strcpy(temp3->gudje, "否");
}
}
}
temp3 = temp3->next;
}
}
查看成绩
#include "head.h"
college* Creat4()
{
college* newnode = (college*)malloc(sizeof(college));
if (newnode == NULL)
{
perror("error:");
exit(-1);
}
newnode->next = NULL;
return newnode;
}
void collect_menu(sport_event** head, athlete_inform** head1, athlete_reg** head2)
{
int input;
printf("\n");
printf(" _____________________________________________________________ \n");
printf(" | |\n");
printf(" | 1.参赛人数查询 |\n");
printf(" | 2.运动项目成绩查询 |\n");
printf(" | 3.学生个人成绩查询 |\n");
printf(" | 4.学院成绩查询 |\n");
printf(" | 0.返回 |\n");
printf(" |_____________________________________________________________|\n");
printf(" 请选择:");
scanf("%d", &input);
switch (input)
{
case 0:
system("cls");
menu();
break;
case 1:
system("cls");
people(head,head1, head2);
break;
case 2:
system("cls");
event_score(head, head1, head2);
break;
case 3:
system("cls");
person(head,head1,head2);
break;
case 4:
system("cls");
college_menu(head,head1, head2);
break;
default:
printf(" 输入错误!请重新输入!\n");
Sleep(1500);
system("cls");
collect_menu(head, head1, head2);
}
}
void people(sport_event** head,athlete_inform** head1, athlete_reg** head2)
{
int input;
printf("\n");
printf(" _____________________________________________________________ \n");
printf(" | |\n");
printf(" | 1.各学院总参赛人数 |\n");
printf(" | 2.各项目参赛人数 |\n");
printf(" | 0.返回 |\n");
printf(" |_____________________________________________________________|\n");
printf(" 请选择:");
scanf("%d", &input);
switch (input)
{
case 0:
system("cls");
collect_menu(head, head1, head2);
break;
case 1:
system("cls");
college_people(head, head1, head2);
break;
case 2:
system("cls");
event_people(head, head1, head2);
break;
default:
printf(" 输入错误!请重新输入!\n");
Sleep(1500);
system("cls");
people(head, head1, head2);
}
}
void college_people(sport_event** head,athlete_inform** head1, athlete_reg** head2)
{
athlete_inform* temp = *head1;
char arr[20] = { 0 };
int man = 0, woman = 0;
printf("\n 请输入您要查询的学院编号:");
scanf("%s", arr);
while (temp != NULL)
{
if (strcmp(temp->school_num, arr) == 0 && strcmp(temp->sex, "男") == 0)
{
man++;
}
if (strcmp(temp->school_num, arr) == 0 && strcmp(temp->sex, "女") == 0)
{
woman++;
}
temp = temp->next;
}
printf(" 学院总参赛人数为:%d\n", man+woman);
printf(" 男生:%d人 女生:%d人\n", man , woman);
printf(" ");
system("pause");
system("cls");
people(head,head1, head2);
}
void event_people(sport_event** head,athlete_inform** head1, athlete_reg** head2)
{
athlete_inform* ch = *head1;
athlete_reg* temp = *head2;
char arr[20] = { 0 };
int num = 0;
int man = 0, woman = 0;
printf("\n 请输入您要查询的项目编号:");
scanf("%s", arr);
while (temp != NULL)
{
if (strcmp(temp->item_num, arr) == 0)
{
//判断是男是女
ch= *head1;
while (strcmp(temp->number, ch->number) != 0)
{
ch = ch->next;
}
if (strcmp(ch->sex, "男") == 0)
{
man++;
}
if (strcmp(ch->sex, "女") == 0)
{
woman++;
}
}
temp = temp->next;
}
printf(" 该项目总参赛人数为:%d\n", man + woman);
printf(" 男生:%d人 女生:%d人\n", man, woman);
printf(" ");
system("pause");
system("cls");
people(head, head1, head2);
}
void event_score(sport_event** head, athlete_inform** head1, athlete_reg** head2)
{
char arr[10] = { 0 };
printf("\n 请输入您要查询的项目编号:");
scanf("%s", arr);
athlete_reg* temp = (*head2)->next;
printf(" 姓名 学号 成绩 名次\n");
while (temp != NULL)
{
if (strcmp(temp->item_num, arr) == 0 && temp->ranking <= 6)
{
printf(" ");
name(head1, temp->number);
printf("%12s",temp->number);
if (strcmp(temp->cate_num, "1001") == 0)
{
printf("%14s", temp->score.time);
}
else
{
printf("%14f", temp->score.meter);
}
printf("%10d\n", temp->ranking);
}
temp = temp->next;
}
printf(" ");
system("pause");
system("cls");
collect_menu(head, head1, head2);
}
void name(athlete_inform** head, char number[10])
{
athlete_inform* temp = (*head);
while (strcmp(temp->number, number) != 0)
{
temp = temp->next;
}
printf("%8s", temp->name);
}
void person(sport_event** head,athlete_inform** head1, athlete_reg** head2)
{
int ch = 0;
char arr[20];
printf("\n 请输入您要查询的学生姓名或者学号:");
scanf("%s", arr);
athlete_inform* temp1 = (*head1)->next;
while (1)
{
if (strcmp(temp1->name, arr) == 0 || strcmp(temp1->number, arr) == 0)
{
break;
}
temp1 = temp1->next;
}
printf(" 姓名:%s\n", temp1->name);
printf(" 学号:%s\n", temp1->number);
printf(" -----------------------------------------------------------------\n");
printf(" 项目名称 项目编号 成绩 名次 得分 是否打破记录\n");
athlete_reg* temp2 = (*head2)->next;
while (temp2 != NULL)
{
if (strcmp(temp1->number, temp2->number) == 0)
{
printf(" ");
item(head, temp2->item_num);
printf("%10s", temp2->item_num);
if (strcmp(temp2->cate_num, "1001") == 0)
{
printf("%14s", temp2->score.time);
}
else
{
printf("%14f", temp2->score.meter);
}
printf("%8d", temp2->ranking);
ch = score(temp2->ranking, temp2->gudje);
printf("%8d", ch);
printf("%8s\n", temp2->gudje);
}
temp2 = temp2->next;
}
printf(" ");
system("pause");
system("cls");
collect_menu(head, head1, head2);
}
void item(sport_event** head, char item[10])
{
sport_event* temp = (*head)->next;
while (strcmp(temp->item_num, item) != 0)
{
temp = temp->next;
}
printf("%7s", temp->pro_name);
}
int score(int ranking,char gudje[5])//返回得分
{
switch (ranking)
{
case 1:
if (strcmp(gudje, "是") == 0)
{
return 20;
}
else
{
return 10;
}
break;
case 2:
return 7;
break;
case 3:
return 5;
break;
case 4:
return 4;
break;
case 5:
return 3;
break;
case 6:
return 2;
break;
default:
return 1;
}
}
void college_menu(sport_event** head, athlete_inform** head1, athlete_reg** head2)
{
Init_colloge(head,head1,head2);
int input;
printf("\n");
printf(" _____________________________________________________________ \n");
printf(" | |\n");
printf(" | 1.各学院排名表 |\n");
printf(" | 2.查询单个学院成绩及排名 |\n");
printf(" | 0.返回 |\n");
printf(" |_____________________________________________________________|\n");
printf(" 请选择:");
scanf("%d", &input);
switch (input)
{
case 0:
system("cls");
collect_menu(head, head1, head2);
break;
case 1:
system("cls");
college_score_show(head, head1, head2);
break;
case 2:
system("cls");
college_special(head, head1, head2);
break;
default:
printf(" 输入错误!请重新输入!\n");
Sleep(1500);
system("cls");
college_menu(head, head1, head2);
}
}
void Init_colloge(sport_event** head, athlete_inform** head1, athlete_reg** head2)
{
athlete_inform* temp1 = (*head1)->next;
athlete_reg* temp2 = (*head2)->next;
college* px = Creat4();
college* temp = px;
for (int i = 0; i < 3; i++)
{
college* x = Creat4();
temp->next = x;
x->next = NULL;
temp = x;
}
px->next->point = 0;
px->next->next->point = 0;
px->next->next->next->point = 0;
strcpy(px->next->school_num ,"10023");
strcpy(px->next->next->school_num, "10024");
strcpy(px->next->next->next->school_num, "10025");
while (temp2 != NULL)
{
temp1 = (*head1)->next;
while (strcmp(temp1->number ,temp2->number) != 0 )
{
temp1 = temp1->next;
}
int ch = score(temp2->ranking, temp2->gudje);
if (strcmp(temp1->school_num, "10023") == 0)
{
px->next->point += ch;
}
if (strcmp(temp1->school_num, "10024") == 0)
{
px->next->next->point += ch;
}
if (strcmp(temp1->school_num, "10025") == 0)
{
px->next->next->next->point += ch;
}
temp2 = temp2->next;
}
college* p, * q, * s;
for (int i = 0; i < 2; i++)
{
s = px;
q = px->next;
p = q->next;
int num = 3 - 1 - i;
while (num--)
{
if (q->point < p->point) //交换,得分高的靠前
{
q->next = p->next;
p->next = q;
s->next = p;
}
s = s->next;
q = s->next;
p = q->next;
}
}
save(px);
}
void save(college* temp)
{
FILE* pf = fopen("college_score.txt", "w");
if (pf == NULL) //打开失败
{
printf("\n");
printf(" 文件打开失败!无法保存!\n");
printf(" 即将返回上一级!");
Sleep(1200);
system("cls");
menu();
}
else
{
temp = temp->next;
fputs(temp->school_num, pf);
fputs("\n", pf);
fprintf(pf, "%d", temp->point);
fputs("\n", pf);
fputs("1", pf);
fputs("\n", pf);
temp = temp->next;
fputs(temp->school_num, pf);
fputs("\n", pf);
fprintf(pf, "%d", temp->point);
fputs("\n", pf);
fputs("2", pf);
fputs("\n", pf);
temp = temp->next;
fputs(temp->school_num, pf);
fputs("\n", pf);
fprintf(pf, "%d", temp->point);
fputs("\n", pf);
fputs("3", pf);
fputs("\n", pf);
}
fclose(pf);
}
void college_score_show(sport_event** head, athlete_inform** head1, athlete_reg** head2)
{
char arr[20] = { 0 };
int x = 0, y = 0;
FILE* pf = fopen("college_score.txt", "r");
if (pf == NULL) //打开失败
{
printf("\n");
printf(" 文件打开失败!无法展示!\n");
printf(" 即将返回上一级!");
Sleep(1200);
system("cls");
college_menu(head, head1, head2);
}
else
{
printf("\n 学院编号 得分 排名\n");
for (int i = 0; i < 3; i++)
{
fscanf(pf, "%s", arr);
fscanf(pf, "%d", &x);
fscanf(pf, "%d", &y);
printf(" %10s%10d%8d\n", arr, x, y);
}
}
fclose(pf);
printf(" ");
system("pause");
system("cls");
college_menu(head, head1, head2);
}
void college_special(sport_event** head, athlete_inform** head1, athlete_reg** head2)
{
char arr[20] = { 0 }, college[20] = { 0 };
int x;
printf("\n 请输入您要查询的学院编号:");
scanf("%s", arr);
FILE* pf = fopen("college_score.txt", "r");
if (pf == NULL) //打开失败
{
printf("\n");
printf(" 文件打开失败!无法展示!\n");
printf(" 即将返回上一级!");
Sleep(1200);
system("cls");
college_menu(head, head1, head2);
}
else
{
while (fscanf(pf, "%s", college) != EOF)
{
if (strcmp(college, arr) == 0)
{
printf(" 查找成功!\n");
printf(" 学院编号:%s\n", college);
fscanf(pf, "%d", &x);
printf(" 得分:%d\n", x);
fscanf(pf, "%d", &x);
printf(" 排名:%d\n", x);
printf(" ");
system("pause");
system("cls");
college_menu(head, head1, head2);
}
}
printf(" 查找失败!");
printf(" ");
system("pause");
system("cls");
college_menu(head, head1, head2);
}
}