球员管理系统可分为添加球队球员信息,查询修改球员信息,删除球员信息,统计球队信息,其他修改存入球队球队信息和退出球队管理系统。
为了实现各个模块的功能,系统中声明了所需的头文件:
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<windows.h>
为了实现相应的功能,在程序的设计中定义了相关的函数,哥哥函数原型如下:
void Menu();/*球队菜单函数*/ //两个菜单函数嵌套
void Menu1();/*球员菜单函数*/
void Face();/*欢迎界面*/
void Tail();/*结尾界面*/
void Display();/*浏览函数*/
void Show();/*展示所有球队函数*/
void Show1();/*展示所有球员函数*/
void Add();/*录入球队信息函数*/
void Save();/*信息保存函数*/
int Load();/*信息保存函数*/
void Update();/*修改球员部分信息函数*/
void Update1();/*修改球员所有信息函数*/
void Alter();/*修改球队部分信息函数*/
void Alter1();/*修改球队所有信息函数*/
void Delete();/*删除球队信息函数*/
void Delete1();/*删除球员信息函数*/
void Find();/*搜索球队函数*/
void find_team();/*通过队名搜索*/
void find_score();/*通过赛季积分搜索*/
void find_boss();/*通过老板搜索*/
void Search();/*搜索球员函数*/
void search_name();/*通过姓名搜索*/
void search_ID();/*通过身份证号搜索*/
void search_age();/*通过年龄搜索*/
void search_ball_age();/*通过球龄搜索*/
本系统采用结构体设计储存数据,系统共定义个两个结构体:
rebounder.Rebounder和team.Team,利用Rebounder储存球员的姓名,年龄,球龄等信息,利用Tea m储存球队的相关信息,并将Rebounder嵌入Team结构体中。具体结构如下:
struct rebounder
{
char name[20];
char age[5];
char ball_age[5];
char value[10];
char position[30];
char ID[10];
char goals_this_season[5];
char condition[30] ;
}Rebounder[20];
struct team
{
char team_name[20];
char level[5];
char score[5];
char sponsor[10];
char boss[10];
char coach[10];
struct rebounder Rebounder[20];
}Team[20];
void Face()
{
printf("\t|------------------------------------------------------------------------|\n");
printf("\t| |\n");
printf("\t| ★★★★★ |\n");
printf("\t| ★ 中南民族大学 ★ |\n");
printf("\t| ★★★★★ |\n");
printf("\t| |\n");
printf("\t|------------------------------------------------------------------------|\n");
printf("\t| |\n");
printf("\t| 欢迎访问球员管理系统 |\n");
printf("\t| 点击进入 |\n");
printf("\t| |\n");
printf("\t|------------------------------------------------------------------------|\n\n");
system("pause");
system("cls");
}
为了实现对球队信息的查询,程序定义了五个查询球队信息函数,并通过Find()函数将另外三个find()函数嵌入其中。
修改模块先展示所有球队的信息,然后通过字符串比较函数strcmp()匹配系统内球队队名数据,当所需修改的球队队名匹配成功时,可对该球队的信息进行修改。
对球队信息修改情况如下图:
删除模块核心是通过字符串比较函数匹配到所需删除的球队队名,然后原下一行信息将上一行覆盖,进行删除,使得信息上移一行,达到删除功能。
删除模块代码如下:
void Delete()
{
int i, j, t, m, n, flag;
char Del_team[20] = { 0 };
Show();
printf("\n");
printf("请输入需要删除的球队姓名:\n");
scanf_s("%s", Del_team, sizeof(Del_team));
for (flag = 1, i = 0; flag && i < 20; i++)
{
if (strcmp(Del_team, Team[i].team_name) == 0)
{
printf("\n已找到该球队,其相关信息为:\n");
printf("\n \t队名 \t球队级别 \t本赛季积分 \t冠名企业 \t老板 \t主教练");
printf("\n \t%s \t%s \t%s \t%s \t%s \t%s\n",
Team[i].team_name, Team[i].level, Team[i].score, Team[i].sponsor, Team[i].boss,
Team[i].coach);
printf("是否删除该球队信息,确定按1,取消按2\n");
scanf_s("%d", &m);
if (m == 1)/*通过原下一行信息将上一行覆盖,进行删除,使得信息上移一行 */
{
for (j = i; j <19; j++)
{
strcpy(Team[j].team_name, Team[j + 1].team_name);
strcpy(Team[j].level, Team[j + 1].level);
strcpy(Team[j].score, Team[j + 1].score);
strcpy(Team[j].sponsor, Team[j + 1].sponsor);
strcpy(Team[j].boss, Team[j + 1].boss);
strcpy(Team[j].coach, Team[j + 1].coach);
for (t = 0; t < 20; t++)
{
strcpy(Team[j].Rebounder[t].name, Team[j + 1].Rebounder[t].name);
strcpy(Team[j].Rebounder[t].age, Team[j + 1].Rebounder[t].age);
strcpy(Team[j].Rebounder[t].ball_age, Team[j + 1].Rebounder[t].ball_age);
strcpy(Team[j].Rebounder[t].condition, Team[j + 1].Rebounder[t].condition);
strcpy(Team[j].Rebounder[t].goals_this_season, Team[j + 1].Rebounder[t].goals_this_season);
strcpy(Team[j].Rebounder[t].ID, Team[j + 1].Rebounder[t].ID);
strcpy(Team[j].Rebounder[t].position, Team[j + 1].Rebounder[t].position);
strcpy(Team[j].Rebounder[t].value, Team[j + 1].Rebounder[t].value);
}
}
flag = 0;
}
}
}
if (!flag)
{
system("cls");
printf("\n浏览删除该球队后所有信息\n");
Save();
Show();
printf("\n继续删除请按1,不再删除请按2\n");
scanf_s("%d", &n);
}
switch (n)
{
case 1:system("cls"); Delete(); break;
case 2:system("cls"); Menu(); break;
default:break;}}
球员菜单模块等同于球队菜单模块,将球员管理系统嵌入球队管理系统,实现查询,修改,删除球员功能原理与球队的管理功能相同。
球员管理系统菜单如图:
球队信息展示通过对两个结构体内各个元素的输出,并用for循环
图14:Display()函数
部分代码
将各个球队的信息有秩序的展示出来,实现展示功能,如下图:
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<windows.h>
#define Max 20
void Menu();/*球队菜单函数*/ //两个菜单函数嵌套
void Menu1();/*球员菜单函数*/
void Face();/*欢迎界面*/
void Tail();/*结尾界面*/
void Display();/*浏览函数*/
void Show();/*展示所有球队函数*/
void Show1();/*展示所有球员函数*/
void Add();/*录入球队信息函数*/
void Save();/*信息保存函数*/
int Load();/*信息保存函数*/
void Update();/*修改球员部分信息函数*/
void Update1();/*修改球员所有信息函数*/
void Alter();/*修改球队部分信息函数*/
void Alter1();/*修改球队所有信息函数*/
void Delete();/*删除球队信息函数*/
void Delete1();/*删除球员信息函数*/
void Find();/*搜索球队函数*/
void find_team();/*通过队名搜索*/
void find_score();/*通过赛季积分搜索*/
void find_boss();/*通过老板搜索*/
void Search();/*搜索球员函数*/
void search_name();/*通过姓名搜索*/
void search_ID();/*通过身份证号搜索*/
void search_age();/*通过年龄搜索*/
void search_ball_age();/*通过球龄搜索*/
struct rebounder
{
char name[20];
char age[10];
char ball_age[10];
char value[10];
char position[30];
char ID[10];
char goals_this_season[5];
char condition[30];
}Rebounder[20];
struct team
{
char team_name[20];
char level[15];
char score[15];
char sponsor[15];
char boss[15];
char coach[15];
struct rebounder Rebounder[20];
}Team[20];
void Menu()/*球队菜单函数*/
{
int choice;
int n;
do
{
printf("\n");
printf("----------------------------------------------------------------------------------------------------------------------\n");
printf(" 1 添加球队信息\n");
printf(" 2 查询球队信息\n");
printf(" 3 修改球队信息\n");
printf(" 4 删除球队信息\n");
printf(" 5 球员信息管理\n");
printf(" 6 展示所有信息\n");
printf(" 0 退出系统\n");
printf("----------------------------------------------------------------------------------------------------------------------\n");
printf("请输入你的选择:");
scanf_s("%d", &n);
if (n < 0 || n>6)
{
system("cls");
printf("输入错误,请重新输入你的选择\n");
system("pause");
system("cls");
choice = 1;
}
else
{
break;
}
} while (choice == 1);
switch (n)
{
case 1:system("cls"); Add(); break;
case 2:system("cls"); Find(); break;
case 3:system("cls"); Alter(); break;
case 4:system("cls"); Delete(); break;
case 5:system("cls"); Menu1(); break;
case 6:system("cls"); Display(); break;
case 0:system("cls"); Tail(); system("pause"); break;
}
}
void Menu1()/*球员菜单函数*/
{
int choice1;
int n1;
do
{
printf("--------------------------------------\n");
printf(" 1 查询球员信息\n");
printf(" 2 修改球员信息\n");
printf(" 3 删除球员信息\n");//有bug
printf(" 0 返回主菜单\n");
printf("--------------------------------------\n");
printf("请输入你的选择:");
scanf_s("%d", &n1);
if (n1 < 0 || n1>3)
{
system("cls");
printf("输入错误!请重新选择!");
system("pause");
choice1 = 1;
}
else
{
break;
}
} while (choice1 == 1);
switch (n1)
{
case 1: system("cls"); Search(); break; /*调用搜索函数以搜索球员信息*/
case 2: system("cls"); Update(); break;
case 3:system("cls"); Delete1(); break;
case 0:system("cls"); Menu(); break;
}
}
void Face()
{
printf("\t|------------------------------------------------------------------------|\n");
printf("\t| |\n");
printf("\t| ★★★★★ |\n");
printf("\t| ★ 中南民族大学 ★ |\n");
printf("\t| ★★★★★ |\n");
printf("\t| |\n");
printf("\t|------------------------------------------------------------------------|\n");
printf("\t| |\n");
printf("\t| 欢迎访问球员管理系统 |\n");
printf("\t| 点击进入 |\n");
printf("\t| |\n");
printf("\t|------------------------------------------------------------------------|\n\n");
system("pause");
system("cls");
}
void Tail()
{
printf("\n\t |-----------------------------------------------------------|\n");
printf("\t | |\n");
printf("\t | 感谢访问! |\n");
printf("\t | 欢迎下次再次访问! |\n");
printf("\t | |\n");
printf("\t |-----------------------------------------------------------|\n");
printf("\t | |\n");
printf("\t | |\n");
printf("\t | 作者: |\n");
printf("\t | 电信 王志涵 |\n");
printf("\t | |\n");
printf("\t |-----------------------------------------------------------|\n");
}
void Display()
{
int i, j;
for (i = 0; i < 20; i++)
{
if (Team[i].team_name[0] != '\0')
{
printf("------------------------------------------------------------------------------------------------------------------------\n");
printf("\n ★\t球队队名:%s \t级别:%s \t本赛季积分:%s \t冠名企业:%s \t老板:%s \t主教练:%s\n球员信息:",
Team[i].team_name, Team[i].level, Team[i].score, Team[i].sponsor, Team[i].boss, Team[i].coach);
}
for (j = 0; j < 20; j++)
if (Team[i].Rebounder[j].name[0] != '\0')
{
printf("\n姓名:%s\t年龄:%s\t球龄:%s\t身价:%s\t位置:%s\t身份证号:%s\t该赛季进球数:%s\t情况:%s\n", Team[i].Rebounder[j].name, Team[i].Rebounder[j].age, Team[i].Rebounder[j].ball_age, Team[i].Rebounder[j].value, Team[i].Rebounder[j].position, Team[i].Rebounder[j].ID, Team[i].Rebounder[j].goals_this_season, Team[i].Rebounder[j].condition);
}
}
printf("----------------------------------------------------------------------------------------------------------------------\n");
printf("\n");
system("pause");
system("cls");
Menu();
}
void Show()
{
int j,i;
for (i = 0; i < 20; i++)
{
if (Team[i].team_name[0] != '\0')
{
printf("------------------------------------------------------------------------------------------------------------------------\n");
printf("\n ★\t球队队名:%s \t级别:%s \t本赛季积分:%s \t冠名企业:%s \t老板:%s \t主教练:%s\n球员信息:",
Team[i].team_name, Team[i].level, Team[i].score, Team[i].sponsor, Team[i].boss, Team[i].coach);
}
for (j = 0; j < 20; j++)
if (Team[i].Rebounder[j].name[0] != '\0')
{
printf("\n姓名:%s\t年龄:%s\t球龄:%s\t身价:%s\t位置:%s\t身份证号:%s\t该赛季进球数:%s\t情况:%s\n", Team[i].Rebounder[j].name, Team[i].Rebounder[j].age, Team[i].Rebounder[j].ball_age, Team[i].Rebounder[j].value, Team[i].Rebounder[j].position, Team[i].Rebounder[j].ID, Team[i].Rebounder[j].goals_this_season, Team[i].Rebounder[j].condition);
}
}
printf("----------------------------------------------------------------------------------------------------------------------\n");
printf("\n");
}
void Show1()
{
int i, j;
for (i = 0; i < 20; i++)
for (j = 0; j < 20; j++)
if (Team[i].Rebounder[j].name[0] != '\0')
{
printf("--------------------------------------------------------------------------------------------------------------\n");
printf("\n姓名:%s\t年龄:%s\t球龄:%s\t身价:%s\t位置:%s\t身份证号:%s\t该赛季进球数:%s\t情况:%s\n", Team[i].Rebounder[j].name, Team[i].Rebounder[j].age, Team[i].Rebounder[j].ball_age, Team[i].Rebounder[j].value, Team[i].Rebounder[j].position, Team[i].Rebounder[j].ID, Team[i].Rebounder[j].goals_this_season, Team[i].Rebounder[j].condition);
printf("---------------------------------------------------------------------------------------------------------------\n");
}
}
void Add()
{
int i, j;
int n;
printf("请输入添加球队个数:\n");
scanf_s("%d", &n);
printf("请输入球队相关信息:\n");
for (i = 0; i < n; i++)
{
printf("请输入球队队名:");
scanf_s("%s", Team[i].team_name, sizeof(Team[i].team_name));
printf("请输入球队级别:");
scanf_s("%s", Team[i].level, sizeof(Team[i].level));
printf("请输入球队本赛季积分:");
scanf_s("%s", Team[i].score, sizeof(Team[i].score));
printf("请输入冠名企业:");
scanf_s("%s", Team[i].sponsor, sizeof(Team[i].sponsor));
printf("请输入老板:");
scanf_s("%s", Team[i].boss, sizeof(Team[i].boss));
printf("请输入教练:");
scanf_s("%s", Team[i].coach, sizeof(Team[i].coach));
int n1;
printf("请输入该球队的球员信息\n");
printf("请输入需添加球员数量:\n");
scanf_s("%d", &n1);
for (j = 0; j < n1; j++)
{
printf("请输入姓名:");
scanf_s("%s", Team[i].Rebounder[j].name, sizeof(Team[i].Rebounder[j].name));
printf("请输入年龄:");
scanf_s("%s", Team[i].Rebounder[j].age, sizeof(Team[i].Rebounder[j].age));
printf("请输入球龄:");
scanf_s("%s", Team[i].Rebounder[j].ball_age, sizeof(Team[i].Rebounder[j].ball_age));
printf("请输入身价:");
scanf_s("%s", Team[i].Rebounder[j].value, sizeof(Team[i].Rebounder[j].value));
printf("请输入位置:");
scanf_s("%s", Team[i].Rebounder[j].position, sizeof(Team[i].Rebounder[j].position));
printf("请输入身份证号:");
scanf_s("%s", Team[i].Rebounder[j].ID, sizeof(Team[i].Rebounder[j].ID));
printf("请输入本赛季进球数:");
scanf_s("%s", Team[i].Rebounder[j].goals_this_season, sizeof(Team[i].Rebounder[j].goals_this_season));
printf("请输入状态:");
scanf_s("%s", Team[i].Rebounder[j].condition, sizeof(Team[i].Rebounder[j].condition));
printf("\n");
}
printf("添加成功!");
system("pause");
system("cls");
}
Save();
printf("按任意键返回主菜单");
getchar(); getchar();
system("cls");
Menu();
}//
void Save()
{
FILE* fp;
int j, t;
if ((fp = fopen("file.txt", "wb")) != NULL)/*只打开或建立一个二进制文件,只允许写数据*/
{
for (j = 0; j < 20; j++)
for (t = 0; t < 20; t++)
{
fprintf(fp, "%s\t", Team[j].team_name);
fprintf(fp, "%s\t", Team[j].level);
fprintf(fp, "%s\t", Team[j].score);
fprintf(fp, "%s\t%s\t%s\t\n", Team[j].sponsor, Team[j].boss, Team[j].coach);
fprintf(fp, "%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t\n", Team[j].Rebounder[t].name, Team[j].Rebounder[t].age, Team[j].Rebounder[t].ball_age, Team[j].Rebounder[t].value, Team[j].Rebounder[t].position, Team[j].Rebounder[t].ID, Team[j].Rebounder[t].goals_this_season, Team[j].Rebounder[t].condition);
}
fclose(fp);
}
else
printf("文件输入错误!\n");
}
int Load()
{
FILE* fp;/*文件指针*/
int i, j = 0, k=0,t = 0;
if ((fp = fopen("file.txt", "rb")) != NULL)/*读入空文件,rb表示打开一个二进制文件,只允许读入数据*/
{
{
for (i = 0; !feof(fp); i++)/*处理到文件结尾*/
for (j = 0; j < 20; j++)
for (t = 0; t < 20; t++)
{
fscanf_s(fp, "%s\t", Team[j].team_name, sizeof(Team[j].team_name));
fscanf_s(fp, "%s\t", Team[j].level, sizeof(Team[j].level));
fscanf_s(fp, "%s\t", Team[j].score, sizeof(Team[j].score));
fscanf_s(fp, "%s\t", Team[j].sponsor, sizeof(Team[j].sponsor));
fscanf_s(fp, "%s\t", Team[j].boss, sizeof(Team[j].boss));
fscanf_s(fp, "%s\t", Team[j].coach, sizeof(Team[j].coach));
fscanf_s(fp, "%s\t", Team[j].Rebounder[t].name, sizeof(Team[j].Rebounder[t].name));
fscanf_s(fp, "%s\t", Team[j].Rebounder[t].age, sizeof(Team[j].Rebounder[t].age));
fscanf_s(fp, "%s\t", Team[j].Rebounder[t].ball_age, sizeof(Team[j].Rebounder[t].ball_age));
fscanf_s(fp, "%s\t", Team[j].Rebounder[t].value, sizeof(Team[j].Rebounder[t].value));
fscanf_s(fp, "%s\t", Team[j].Rebounder[t].position, sizeof(Team[j].Rebounder[t].position));
fscanf_s(fp, "%s\t", Team[j].Rebounder[t].ID, sizeof(Team[j].Rebounder[t].ID));
fscanf_s(fp, "%s\t", Team[j].Rebounder[t].goals_this_season, sizeof(Team[j].Rebounder[t].goals_this_season));
fscanf_s(fp, "%s\t", Team[j].Rebounder[t].condition, sizeof(Team[j].Rebounder[t].condition));
k++;
}
}
fclose(fp);
return (k-1);
}
else
{
printf("\n文件不存在!请输入:\n");
return 0;
}
}
void Find()
{
int i, j;
do
{
printf("\t---------------------\n");
printf("\t|按1球队队名搜索 |\n\t|按2球队赛季积分搜索|\n\t|按3球队老板搜索 |\n\t|按4返回主菜单 |\n\t");
printf("---------------------\t\n");
printf("请输入你的选择:");
scanf_s("%d", &i);
if (i >= 1 && i <= 4)
{
j = 1;
break;
}
else
{
j = 0;
printf("输入有误,请重新输入");
}
} while (j == 0);
while (j == 1)
{
switch (i)
{
case 1:printf("按球队队名搜索\n"); find_team(); break;
case 2:printf("按球队赛季积分搜索\n"); find_score(); break;
case 3:printf("按球队老板搜索\n"); find_score(); break;
case 4:system("cls"); Menu(); break;
default:break;
}
}
}
void find_team()
{
char find_team[20] = { 0 };
int i,j, m;
printf("请输入球队队名:");
scanf_s("%s", find_team, sizeof(find_team));
for (i = 0; i < 20; i++)
{
if (strcmp(find_team, Team[i].team_name) == 0)
{
printf("已找到该球队,其相关信息为:\n");
printf("-------------------------------------------------------------------------------------------------------------------\n");
printf("\t队名 \t球队级别 \t本赛季积分 \t冠名企业 \t老板 \t主教练\n");
printf("\t%5s \t%5s \t%5s \t%5s \t%5s \t%5s\t\n", Team[i].team_name, Team[i].level, Team[i].score, Team[i].sponsor, Team[i].boss,
Team[i].coach);
printf("球员信息:\n");
printf("\t姓名 \t年龄\t球龄\t身价 \t位置 \t身份证号\t赛季进球数 \t情况\t\n");
for (j = 0; j < 20; j++)
printf("\t%s \t%s \t%s \t%s \t%s \t%s \t%s \t%s\t\n", Team[i].Rebounder[j].name, Team[i].Rebounder[j].age, Team[i].Rebounder[j].ball_age, Team[i].Rebounder[j].value, Team[i].Rebounder[j].position, Team[i].Rebounder[j].ID, Team[i].Rebounder[j].goals_this_season, Team[i].Rebounder[j].condition);
printf("-------------------------------------------------------------------------------------------------------------------\n");
printf("\n");
system("pause");
system("cls");
Menu();
}
else
{
printf("抱歉,未找到相关球队\n\n");
printf("继续查询请按1,返回查询方式选择请按2\n");
scanf_s("%d", &m);
switch (m)
{
case 1:system("cls"); break;
case 2:system("cls"); Find(); break;
default:break;
}
}
}
}
void find_score()
{
char find_score[15] = { 0 };
int i,j, m;
int k = Load();
scanf_s("%s", find_score, sizeof(find_score));
for (i = 0; i < k; i++)
{
if (strcmp(find_team, Team[i].score) == 0)
{
printf("已找到该球队,其相关信息为:\n");
printf("------------------------------------------------------------------------------\n");
printf("\t队名 \t球队级别 \t本赛季积分 \t冠名企业 \t老板 \t主教练\n");
printf("\t%5s \t%5s \t%5s \t%5s \t%5s \t%5s\t\n", Team[i].team_name, Team[i].level, Team[i].score, Team[i].sponsor, Team[i].boss,
Team[i].coach);
printf("球员信息:\n");
printf("\t姓名 \t年龄\t球龄\t身价 \t位置 \t身份证号\t赛季进球数 \t情况\t\n");
for (j = 0; j < 20; j++)
printf("\t%s \t%s \t%s \t%s \t%s \t%s \t%s \t%s\t\n", Team[i].Rebounder[j].name, Team[i].Rebounder[j].age, Team[i].Rebounder[j].ball_age, Team[i].Rebounder[j].value, Team[i].Rebounder[j].position, Team[i].Rebounder[j].ID, Team[i].Rebounder[j].goals_this_season, Team[i].Rebounder[j].condition);
printf("------------------------------------------------------------------------------\n");
printf("\n");
system("pause");
system("cls");
Menu();
}
else
{
printf("抱歉,未找到相关球队\n\n");
printf("继续查询请按1,返回查询方式选择请按2\n");
scanf_s("%d", &m);
switch (m)
{
case 1:system("cls"); break;
case 2:system("cls"); Find(); break;
default:break;
}
}
}
}
void find_boss()
{
char find_boss[15] = { 0 };
int i,j, m;
int k = Load();
scanf_s("%s", find_boss, sizeof(find_boss));
for (i = 0; i < k; i++)
{
if (strcmp(find_team, Team[i].boss) == 0)
{
printf("已找到该球队,其相关信息为:\n");
printf("------------------------------------------------------------------------------\n");
printf("\t队名 \t球队级别 \t本赛季积分 \t冠名企业 \t老板 \t主教练\n");
printf("\t%5s \t%5s \t%5s \t%5s \t%5s \t%5s\t\n", Team[i].team_name, Team[i].level, Team[i].score, Team[i].sponsor, Team[i].boss,
Team[i].coach);
printf("球员信息:\n");
printf("\t姓名 \t年龄\t球龄\t身价 \t位置 \t身份证号\t赛季进球数 \t情况\t\n");
for (j = 0; j < 20; j++)
printf("\t%s \t%s \t%s \t%s \t%s \t%s \t%s \t%s\t\n", Team[i].Rebounder[j].name, Team[i].Rebounder[j].age, Team[i].Rebounder[j].ball_age, Team[i].Rebounder[j].value, Team[i].Rebounder[j].position, Team[i].Rebounder[j].ID, Team[i].Rebounder[j].goals_this_season, Team[i].Rebounder[j].condition);
printf("------------------------------------------------------------------------------\n");
printf("\n");
system("pause");
system("cls");
Menu();
}
else
{
printf("抱歉,未找到相关球队\n\n");
printf("继续查询请按1,返回查询方式选择请按2\n");
scanf_s("%d", &m);
switch (m)
{
case 1:system("cls"); break;
case 2:system("cls"); Find(); break;
default:break;
}
}
}
}
void Search()/*查询球员信息函数*/
{
int i, j;
do
{
printf("按1球员姓名搜索\n按2球员身份证号搜索\n按3年龄搜索\n按4球龄搜索\n按5返回球员菜单页面\n");
printf("你的选择是:");
scanf_s("%d", &i);
if (i >= 1 && i <= 5)
{
j = 1;
break;
}
else
{
j = 0;
printf("输入有误,请重新选择");
}
} while (j == 0);
while (j == 1)
{
switch (i)
{
case 1:printf("姓名搜索\n"); search_name(); break;
case 2:printf("身份证号搜索\n"); search_ID(); break;
case 3:printf("年龄搜索\n"); search_age(); break;
case 4:printf("球龄搜索\n"); search_ball_age(); break;
case 5:system("cls"); Menu1(); break;
default:break;
}
}
}
void search_name()
{
char search_name[20] = { 0 };
int i, j, m;
int k = Load();
scanf_s("%s", search_name, sizeof(search_name));
for (i = 0; i < 20; i++)
{
for (j = 0; j < 20; j++)
if (strcmp(search_name, Team[i].Rebounder[j].name) == 0)
{
printf("已找到该球员,其相关信息为:\n");
printf("\n \t姓名 \t年龄 \t球龄 \t身价 \t位置 \t身份证号 \t本赛季进球数 \t状态");
printf("\n \t%s \t%s \t%s \t%s \t%s \t%s \t%s \t%s\n",
Team[i].Rebounder[j].name, Team[i].Rebounder[j].age, Team[i].Rebounder[j].ball_age, Team[i].Rebounder[j].value, Team[i].Rebounder[j].position,
Team[i].Rebounder[j].ID, Team[i].Rebounder[j].goals_this_season, Team[i].Rebounder[j].condition);
system("pause");
system("cls");
Menu1();
}
if (i == k)
{
printf("\n 抱歉,未查到相关球员\n\n");
printf("继续该查询方式请按1,返回查询方式选择请按2");
scanf_s("%d", &m);
switch (m)
{
case 1:system("pause"); system("cls"); break;
case 2:Search(); break;
default:break;
}
}
}
}
void search_ID()
{
char search_ID[10] = { 0 };
int i, j, m;
int k = Load();
scanf_s("%s", search_ID, sizeof(search_ID));
for (i = 0; i < 20; i++)
{
for (j = 0; j < 20; j++)
if (strcmp(search_ID, Team[i].Rebounder[j].ID) == 0)
{
printf("已找到该球员,其相关信息为:\n");
printf("\n \t姓名 \t年龄 \t球龄 \t身价 \t位置 \t身份证号 \t本赛季进球数 \t状态");
printf("\n \t%s \t%s \t%s \t%s \t%s \t%s \t%s \t%s\n",
Team[i].Rebounder[j].name, Team[i].Rebounder[j].age, Team[i].Rebounder[j].ball_age, Team[i].Rebounder[j].value, Team[i].Rebounder[j].position,
Team[i].Rebounder[j].ID, Team[i].Rebounder[j].goals_this_season, Team[i].Rebounder[j].condition);
system("pause");
system("cls");
Menu1();
}
if (i = k)
{
printf("\n 抱歉,未查到相关球员\n\n");
printf("继续该查询方式请按1,返回查询方式选择请按2");
scanf_s("%d", &m);
switch (m)
{
case 1:system("pause"); system("cls"); break;
case 2:Search(); break;
default:break;
}
}
}
}
void search_age()
{
char search_age[5] = { 0 };
int i, j, m;
int k = Load();
scanf_s("%s", search_age, sizeof(search_age));
for (i = 0; i < 20; i++)
{
for (j = 0; j < 20; j++)
if (strcmp(search_age, Team[i].Rebounder[j].age) == 0)
{
printf("已找到该球员,其相关信息为:\n");
printf("\n \t姓名 \t年龄 \t球龄 \t身价 \t位置 \t身份证号 \t本赛季进球数 \t状态");
printf("\n \t%s \t%s \t%s \t%s \t%s \t%s \t%s \t%s\n",
Team[i].Rebounder[j].name, Team[i].Rebounder[j].age, Team[i].Rebounder[j].ball_age, Team[i].Rebounder[j].value, Team[i].Rebounder[j].position,
Team[i].Rebounder[j].ID, Team[i].Rebounder[j].goals_this_season, Team[i].Rebounder[j].condition);
system("pause");
system("cls");
Menu1();
}
if (i = k)
{
printf("\n 抱歉,未查到相关球员\n\n");
printf("继续该查询方式请按1,返回查询方式选择请按2");
scanf_s("%d", &m);
switch (m)
{
case 1:system("pause"); system("cls"); break;
case 2:Search(); break;
default:break;
}
}
}
}
void search_ball_age()
{
char search_ball_age[5] = { 0 };
int i, j, m;
int k = Load();
scanf_s("%s", search_ball_age, sizeof(search_ball_age));
for (i = 0; i < 20; i++)
{
for (j = 0; j < 20; j++)
if (strcmp(search_ball_age, Team[i].Rebounder[j].ball_age) == 0)
{
printf("已找到该球员,其相关信息为:\n");
printf("\n \t姓名 \t年龄 \t球龄 \t身价 \t位置 \t身份证号 \t本赛季进球数 \t状态");
printf("\n \t%s \t%s \t%s \t%s \t%s \t%s \t%s \t%s\n",
Team[i].Rebounder[j].name, Team[i].Rebounder[j].age, Team[i].Rebounder[j].ball_age, Team[i].Rebounder[j].value, Team[i].Rebounder[j].position,
Team[i].Rebounder[j].ID, Team[i].Rebounder[j].goals_this_season, Team[i].Rebounder[j].condition);
system("pause");
system("cls");
Menu1();
}
}
if (i = k)
{
printf("\n 抱歉,未查到相关球员\n\n");
printf("继续该查询方式请按1,返回查询方式选择请按2");
scanf_s("%d", &m);
switch (m)
{
case 1:system("pause"); system("cls"); break;
case 2:Search(); break;
default:break;
}
}
}
void Update()/*修改球员部分信息函数*/
{
system("cls");
int a = 0, b, i, j = 0;
char udt_name[20] = { 0 };
int loop = 0;
printf("请输入需要修改的球员姓名:");
scanf_s("%s", udt_name, sizeof(udt_name));
for (i = 0; i < 20; i++)
{
for (j = 0; j < 20; j++)
if (strcmp(Team[i].Rebounder[j].name, udt_name) == 0)
{
puts("\n\n1.姓名 2.年龄 3.球龄 4.身价 5.位置 6.身份证号 7.该赛季进球数 8.情况 9.所有信息 10.返回主菜单\n");
printf("%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t", Team[i].Rebounder[j].name, Team[i].Rebounder[j].age, Team[i].Rebounder[j].ball_age,
Team[i].Rebounder[j].value, Team[i].Rebounder[j].position, Team[i].Rebounder[j].ID, Team[i].Rebounder[j].goals_this_season, Team[i].Rebounder[j].position);
do
{
printf("请选择要修改的信息: ");
scanf_s("%d", &a);
if (a < 1 || a>10)
{
system("cls");
puts("\n选择错误,请重新选择");
system("pause");
}
} while (a > 1 || a < 10); break;
}
else
{
if (j == j + 20)
printf("无此球员,请重新选择!\n");
}
}
do
{
switch (a)
{
case 1: {printf("name:"); scanf_s("%s", Team[i].Rebounder[j].name, sizeof(Team[i].Rebounder[j].name)); break; }
case 2: {printf("age:"); scanf_s("%s", Team[i].Rebounder[j].age, sizeof(Team[i].Rebounder[j].age)); break; }
case 3: {printf("ball_age:"); scanf_s("%s", Team[i].Rebounder[j].ball_age, sizeof(Team[i].Rebounder[j].ball_age)); break; }
case 4: {printf("value:"); scanf_s("%s", Team[i].Rebounder[j].value, sizeof(Team[i].Rebounder[j].value)); break; }
case 5: {printf("position:"); scanf_s("%s", Team[i].Rebounder[j].position, sizeof(Team[i].Rebounder[j].position)); break; }
case 6: {printf("ID:"); scanf_s("%s", Team[i].Rebounder[j].ID, sizeof(Team[i].Rebounder[j].ID)); break; }
case 7: {printf("goals_this_season:"); scanf_s("%s", Team[i].Rebounder[j].goals_this_season, sizeof(Team[i].Rebounder[j].goals_this_season)); break; }
case 8: {printf("condition:"); scanf_s("%s", Team[i].Rebounder[j].condition, sizeof(Team[i].Rebounder[j].condition)); break; }
case 9:Update1(); break;
case 10:Menu();
}
Save();/*修改完成后保存*/
printf("修改后的信息为:\n");
printf("1.姓名:%s\n2.年龄:%s\n3.球龄:%s\n4.身价:%s\n5.位置:%s\n6.身份证号:%s\n7.该赛季进球数:%s\n8.情况:%s\n ", Team[i].Rebounder[j].name, Team[i].Rebounder[j].age, Team[i].Rebounder[j].ball_age, Team[i].Rebounder[j].value, Team[i].Rebounder[j].position, Team[i].Rebounder[j].ID, Team[i].Rebounder[j].goals_this_season, Team[i].Rebounder[j].condition);
puts("是否完成修改\n1.完成并退出 2.继续修改 3.修改其他球员信息");
printf("你的选择是:");
scanf_s("%d", &b);
system("cls");
} while (b == 2);
if (b == 1)
{
system("cls");
Menu1();
}
if (b == 3)
{
system("cls");
Update();
}
}
void Update1()/*整体修改球员信息函数*/
{
system("cls");
char udt_name[20] = { 0 };
int i, j;
int loop = 0;
printf("请再次输入需修改球员姓名:");
scanf_s("%s", udt_name, sizeof(udt_name));
for (i = 0; i < 20; i++)
{
for (j = 0; j < 20; j++)
if (strcmp(Team[i].Rebounder[j].name,udt_name)==0)
{
loop = 1;
printf("请输入该球员的新信息,依次输入 name age ball_age value position ID goals_this_season condition");
scanf_s("%s", Team[i].Rebounder[j].name, sizeof(Team[i].Rebounder[j].name));
scanf_s("%s", Team[i].Rebounder[j].age, sizeof(Team[i].Rebounder[j].age));
scanf_s("%s", Team[i].Rebounder[j].value, sizeof(Team[i].Rebounder[j].value));
scanf_s("%s", Team[i].Rebounder[j].position, sizeof(Team[i].Rebounder[j].position));
scanf_s("%s", Team[i].Rebounder[j].ID, sizeof(Team[i].Rebounder[j].ID));
scanf_s("%s", Team[i].Rebounder[j].goals_this_season, sizeof(Team[i].Rebounder[j].goals_this_season));
scanf_s("%s", Team[i].Rebounder[j].condition, sizeof(Team[i].Rebounder[j].condition));
break;
}
}
if (loop)
{
printf("修改成功!\n");
printf("返回主菜单");
system("pause");
Menu();
}
else
{
system("cls");
printf("不存在该球员!");
printf("\n");
Update();
}
}
void Alter()
{
system("cls");
int a, b, i;
char alt_team[20] = { 0 };
Show();
printf("\n请输入需要修改球队姓名:");
scanf_s("%s", alt_team, sizeof(alt_team));
for (i=0;i<20; i++)
{
if (strcmp(Team[i].team_name,alt_team)==0)
{
do
{
printf("可以对如下进行修改:\n");
puts("1.球队队名\n2.球队级别\n3.赛季积分\n4.赞助公司\n5.老板\n6.教练\n7.球员\n8.所有信息\n9.返回主菜单");
printf("你的选择是:");
scanf_s("%d", &a);
printf("\n");
if (a < 1 || a>9)
{
system("cls");
puts("\n选择错误,请重新选择");
getchar( ); getchar( );
}
}while(a < 1 || a>9); break;
}
else
{
if(i==i+20)
printf("查无此球队,请重新选择\n");
}
}
do
{
switch (a)
{
case 1: {printf("修改队名为:"); scanf_s("%s", Team[i].team_name, sizeof(Team[i].team_name)); break; }
case 2: {printf("修改级别为:"); scanf_s("%s", Team[i].level, sizeof(Team[i].level)); break; }
case 3: {printf("修改该赛季积分为:"); scanf_s("%s", Team[i].score, sizeof(Team[i].score)); break; }
case 4: {printf("修改赞助企业为:"); scanf_s("%s", Team[i].sponsor, sizeof(Team[i].sponsor)); break; }
case 5: {printf("修改老板为:"); scanf_s("%s", Team[i].boss, sizeof(Team[i].boss)); }
case 6: {printf("修改教练为:"); scanf_s("%s", Team[i].coach, sizeof(Team[i].coach)); break; }
case 7: {Update(); break; }
case 8: {Alter1(); break; }
case 9:system("cls"); Menu();
}
Save();
printf("修改后的信息为:\n");
printf("1.球队队名:%s\n2.球队级别:%s\n3.赛季积分:%s\n4.赞助企业:%s\n5.老板:%s\n6.教练:%s\n ",
Team[i].team_name, Team[i].level, Team[i].score, Team[i].sponsor, Team[i].boss, Team[i].coach);
puts("\n是否完成修改\n1.完成并退出\n2.继续修改\n3.修改其他球队信息\n");
printf("你的选择是:");
scanf_s("%d", &b);
system("cls");
} while (b == 2);
if (b == 1)
Menu();
if (b == 3)
Alter1();
}
void Alter1()
{
system("cls");
char alt_team[20] = { 0 };
int i,loop = 0;
printf("请在此输入需修改球队队名:");
scanf_s("%s", alt_team, sizeof(alt_team));
for (i=0; i < 20; i++)
{
if (strcmp(alt_team,Team[i].team_name)==0)
{
loop = 1;
printf("请输入球队新的信息,依次输入 球队队名 球队级别 赛季积分 赞助公司 老板 主教练\n");
scanf_s("%s", Team[i].team_name, sizeof(Team[i].team_name));
scanf_s("%s", Team[i].level, sizeof(Team[i].level));
scanf_s("%s", Team[i].score, sizeof(Team[i].score));
scanf_s("%s", Team[i].sponsor, sizeof(Team[i].sponsor));
scanf_s("%s", Team[i].boss, sizeof(Team[i].boss));
scanf_s("%s", Team[i].coach, sizeof(Team[i].coach));
break;
}
}
if (loop)
{
printf("修改成功\n");
printf("返回主菜单");
system("pause");
Menu();
}
else
{
system("cls");
printf("不存在该球队\n");
Alter();
}
}
void Delete()
{
int i, j, t, m, n, flag;
char Del_team[20] = { 0 };
Show();
printf("\n");
printf("请输入需要删除的球队姓名:\n");
scanf_s("%s", Del_team, sizeof(Del_team));
for (flag = 1, i = 0; flag && i < 20; i++)
{
if (strcmp(Del_team, Team[i].team_name) == 0)
{
printf("\n已找到该球队,其相关信息为:\n");
printf("\n \t队名 \t球队级别 \t本赛季积分 \t冠名企业 \t老板 \t主教练");
printf("\n \t%s \t%s \t%s \t%s \t%s \t%s\n",
Team[i].team_name, Team[i].level, Team[i].score, Team[i].sponsor, Team[i].boss,
Team[i].coach);
printf("是否删除该球队信息,确定按1,取消按2\n");
scanf_s("%d", &m);
if (m == 1)/*通过原下一行信息将上一行覆盖,进行删除,使得信息上移一行 */
{
for (j = i; j <19; j++)
{
strcpy(Team[j].team_name, Team[j + 1].team_name);
strcpy(Team[j].level, Team[j + 1].level);
strcpy(Team[j].score, Team[j + 1].score);
strcpy(Team[j].sponsor, Team[j + 1].sponsor);
strcpy(Team[j].boss, Team[j + 1].boss);
strcpy(Team[j].coach, Team[j + 1].coach);
for (t = 0; t < 20; t++)
{
strcpy(Team[j].Rebounder[t].name, Team[j + 1].Rebounder[t].name);
strcpy(Team[j].Rebounder[t].age, Team[j + 1].Rebounder[t].age);
strcpy(Team[j].Rebounder[t].ball_age, Team[j + 1].Rebounder[t].ball_age);
strcpy(Team[j].Rebounder[t].condition, Team[j + 1].Rebounder[t].condition);
strcpy(Team[j].Rebounder[t].goals_this_season, Team[j + 1].Rebounder[t].goals_this_season);
strcpy(Team[j].Rebounder[t].ID, Team[j + 1].Rebounder[t].ID);
strcpy(Team[j].Rebounder[t].position, Team[j + 1].Rebounder[t].position);
strcpy(Team[j].Rebounder[t].value, Team[j + 1].Rebounder[t].value);
}
}
flag = 0;
}
}
}
if (!flag)
{
system("cls");
printf("\n浏览删除该球队后所有信息\n");
Save();
Show();
printf("\n继续删除请按1,不再删除请按2\n");
scanf_s("%d", &n);
}
switch (n)
{
case 1:system("cls"); Delete(); break;
case 2:system("cls"); Menu(); break;
default:break;
}
}
void Delete1()
{
int i, j, m, n, t, flag;
char Del_name[20] = { 0 };
printf("现有所有球员信息:\n");
Show1();
printf("\n");
printf("请输入要删除的球员姓名:");
scanf_s("%s", Del_name, sizeof(Del_name));
for (flag = 1, i = 0; flag && i < 20; i++)
{
for (t = 0; t < 20; t++)
if (strcmp(Del_name, Team[i].Rebounder[t].name) == 0)
{
printf("\n已找到该球员,其相关信息为:\n");
printf("\n \t姓名 \t年龄 \t球龄 \t身价 \t位置 \t身份证号 \t本赛季进球数 \t状态");
printf("\n \t%s \t%s \t%s \t%s \t%s \t%s \t%s \t%s\n",
Team[i].Rebounder[t].name, Team[i].Rebounder[t].age, Team[i].Rebounder[t].ball_age, Team[i].Rebounder[t].value,
Team[i].Rebounder[t].position,
Team[i].Rebounder[t].ID, Team[i].Rebounder[t].goals_this_season, Team[i].Rebounder[t].condition);
printf("是否删除该球员信息,确定按1,取消按2\n");
scanf_s("%d", &m);
if (m == 1)/*通过原下一行信息将上一行覆盖,进行删除,使得信息上移一行 */
{
for (j = i; j < 19; j++)
{
strcpy(Team[i].Rebounder[t].name, Team[i].Rebounder[t + 1].name);
strcpy(Team[i].Rebounder[t].age, Team[i].Rebounder[t + 1].age);
strcpy(Team[i].Rebounder[t].ball_age, Team[i].Rebounder[t + 1].ball_age);
strcpy(Team[i].Rebounder[t].condition, Team[i].Rebounder[t + 1].condition);
strcpy(Team[i].Rebounder[t].goals_this_season, Team[i].Rebounder[t + 1].goals_this_season);
strcpy(Team[i].Rebounder[t].ID, Team[i].Rebounder[t + 1].ID);
strcpy(Team[i].Rebounder[t].position, Team[i].Rebounder[t + 1].position);
strcpy(Team[i].Rebounder[t].value, Team[i].Rebounder[t + 1].value);
}
flag = 0;
}
}
}
if(!flag)
printf("浏览删除该球员的所有信息\n");
Save();/*调用保存函数保存删除后的球员信息*/
Show1();
printf("\n继续删除请按1,不再删除请按2\n");
scanf_s("%d", &n);
switch (n)
{
case 1:system("cls"); Delete1(); break;
case 2:system("cls"); Menu1(); break;
default:break;
}
}
int main()
{
system("color f0");
Face();
Menu();/*调用Menu函数以展示功能菜单*/
return 0;
}
//作者:yogurt-//