2022-03-06 07:05:17 +00:00
|
|
|
|
#include<stdio.h>
|
|
|
|
|
#include<stdlib.h>
|
|
|
|
|
#include<conio.h>
|
2022-03-06 08:20:25 +00:00
|
|
|
|
#include<string.h>
|
2022-03-06 07:05:17 +00:00
|
|
|
|
#define MAX 100
|
|
|
|
|
#define MAX_1 100
|
|
|
|
|
typedef struct singer{
|
2022-03-06 07:22:25 +00:00
|
|
|
|
int num; // 序号
|
|
|
|
|
char name[10]; // 姓名
|
|
|
|
|
char xb[10]; // 性别
|
|
|
|
|
float aver; // 平均分
|
|
|
|
|
int score[MAX_1]; // 原始成绩
|
2022-03-06 07:05:17 +00:00
|
|
|
|
}SING;
|
|
|
|
|
void inarray(SING sing[MAX], int *pnum){
|
2022-03-06 07:22:25 +00:00
|
|
|
|
// 输入歌手信息:序号、姓名、性别
|
2022-03-06 07:05:17 +00:00
|
|
|
|
int n=0;
|
|
|
|
|
printf("输入歌手人数:");
|
|
|
|
|
scanf("%d", &n);
|
|
|
|
|
printf("请输入%d个歌手的信息:\n",n);
|
|
|
|
|
printf("序号\t姓名\t性别\n");
|
|
|
|
|
for(int i=0;i<n;i++){
|
|
|
|
|
scanf("%d%s%s",&sing[i].num,sing[i].name,sing[i].xb);
|
|
|
|
|
}
|
|
|
|
|
*pnum = n;
|
|
|
|
|
}
|
2022-03-06 08:25:13 +00:00
|
|
|
|
void outarrry(SING sing[MAX], int n, int n_){
|
|
|
|
|
// 输出歌手信息:序号、姓名、性别、平均分、原始成绩
|
|
|
|
|
printf("序号\t姓名\t性别\t平均分\t原始成绩\n");
|
2022-03-06 07:05:17 +00:00
|
|
|
|
for(int i=0;i<n;i++){
|
2022-03-06 08:25:13 +00:00
|
|
|
|
printf("%d\t%s\t%s\t%.2f",sing[i].num,sing[i].name,sing[i].xb,sing[i].aver);
|
|
|
|
|
for(int j=0;j<n_;j++){
|
|
|
|
|
printf("\t%d",sing[i].score[j]);
|
|
|
|
|
}
|
|
|
|
|
printf("\n");
|
2022-03-06 07:05:17 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
void insert(SING sing[MAX], int *pnum){
|
2022-03-06 07:22:25 +00:00
|
|
|
|
// 新增歌手信息:序号、姓名、性别(增加到最后)
|
2022-03-06 07:05:17 +00:00
|
|
|
|
int n=*pnum;
|
2022-03-06 07:43:01 +00:00
|
|
|
|
printf("请输入第%d个歌手的信息:\n",n+1);
|
2022-03-06 07:05:17 +00:00
|
|
|
|
printf("序号\t姓名\t性别\n");
|
|
|
|
|
scanf("%d%s%s",&sing[n].num,sing[n].name,sing[n].xb);
|
|
|
|
|
*pnum=n+1;
|
|
|
|
|
}
|
2022-03-06 07:22:25 +00:00
|
|
|
|
void save(SING sing[MAX], int num, int num_){
|
|
|
|
|
// 保存数据到文件
|
|
|
|
|
FILE *fp;
|
|
|
|
|
char filename[10];
|
2022-03-06 07:05:17 +00:00
|
|
|
|
|
2022-03-06 07:22:25 +00:00
|
|
|
|
printf("请输入文件名:");
|
|
|
|
|
scanf("%s", filename);
|
|
|
|
|
|
|
|
|
|
// 打开文件
|
|
|
|
|
if((fp=fopen(filename, "w"))==NULL){
|
|
|
|
|
printf("无法打开该文件,可能是文件名有误!\n");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
// 写入文件
|
|
|
|
|
fprintf(fp, "当前共有%d个歌手,%d个评委:\n",num,num_);
|
2022-03-06 07:43:01 +00:00
|
|
|
|
fprintf(fp, "序号\t姓名\t性别\t平均分\t原始成绩\n");
|
2022-03-06 07:22:25 +00:00
|
|
|
|
for(int i=0;i<num;i++){
|
2022-03-06 07:43:01 +00:00
|
|
|
|
fprintf(fp,"%d\t%s\t%s\t%.2f",sing[i].num,sing[i].name,sing[i].xb,sing[i].aver);
|
2022-03-06 07:22:25 +00:00
|
|
|
|
for(int n=0;n<num_;n++){
|
|
|
|
|
fprintf(fp,"\t%d",sing[i].score[n]);
|
|
|
|
|
}
|
|
|
|
|
fprintf(fp,"\n");
|
|
|
|
|
}
|
2022-03-06 07:43:01 +00:00
|
|
|
|
printf("导出完成\n");
|
|
|
|
|
// 关闭文件
|
|
|
|
|
fclose(fp);
|
|
|
|
|
}
|
|
|
|
|
void load(SING sing[MAX], int *num, int *num_){
|
|
|
|
|
// 从文件读取数据
|
|
|
|
|
FILE *fp;
|
|
|
|
|
char filename[10],temp[10];
|
|
|
|
|
|
|
|
|
|
printf("请输入文件名:");
|
|
|
|
|
scanf("%s", filename);
|
|
|
|
|
// 打开文件
|
|
|
|
|
if((fp=fopen(filename, "r"))==NULL){
|
|
|
|
|
printf("无法打开该文件,可能是文件名有误!\n");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
// 读取数据
|
|
|
|
|
fscanf(fp,"当前共有%d个歌手,%d个评委:",num,num_);
|
|
|
|
|
// 过滤多余文本
|
|
|
|
|
for(int i=0;i<5;i++){
|
|
|
|
|
fscanf(fp,"%s",temp);
|
|
|
|
|
}
|
|
|
|
|
// 读取歌手信息
|
|
|
|
|
for(int i=0;i<*num;i++){
|
|
|
|
|
fscanf(fp,"%d%s%s%f",&sing[i].num,sing[i].name,sing[i].xb,&sing[i].aver);
|
|
|
|
|
for(int n=0;n<*num_;n++){
|
|
|
|
|
fscanf(fp,"%d",&sing[i].score[n]);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
printf("读取完成。\n");
|
|
|
|
|
// 关闭文件
|
|
|
|
|
fclose(fp);
|
2022-03-06 07:22:25 +00:00
|
|
|
|
}
|
2022-03-06 08:20:25 +00:00
|
|
|
|
void aver(SING sing[MAX], int num, int num_){
|
|
|
|
|
int temp,data[MAX_1];
|
|
|
|
|
for(int k=0;k<num;k++){
|
|
|
|
|
memcpy(data,sing[k].score,sizeof(int)*MAX_1);
|
|
|
|
|
// 对分数按从小到大排序
|
|
|
|
|
for(int i=0;i<num_-1;i++){
|
|
|
|
|
for(int j=0;j<num_-1-i;j++){
|
|
|
|
|
if(data[j]>data[j+1]){
|
|
|
|
|
// 交换元素
|
|
|
|
|
temp=data[j];
|
|
|
|
|
data[j]=data[j+1];
|
|
|
|
|
data[j+1]=temp;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
// 计算平均分
|
|
|
|
|
temp=0;
|
|
|
|
|
for(int j=1;j<num_-1;j++){
|
|
|
|
|
temp+=data[j];
|
|
|
|
|
}
|
|
|
|
|
sing[k].aver = temp / (float)(num_-2);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
void mark(SING sing[MAX], int num, int *num_){
|
|
|
|
|
// 输入评委个数
|
|
|
|
|
printf("请输入评委个数:");
|
|
|
|
|
scanf("%d",num_);
|
|
|
|
|
// 逐个评分
|
|
|
|
|
for(int i=0;i<num;i++){
|
|
|
|
|
system("cls");
|
|
|
|
|
printf("当前正在对第 %d 个歌手进行评分:\n\n",i+1);
|
|
|
|
|
printf("歌手信息如下:\n");
|
|
|
|
|
printf("序号\t姓名\t性别\n");
|
|
|
|
|
printf("%d\t%s\t%s\n\n",sing[i].num,sing[i].name,sing[i].xb);
|
|
|
|
|
for(int n=0;n<*num_;n++){
|
|
|
|
|
printf("现在请第 %d 个评委进行评分(0-10分):",n+1);
|
|
|
|
|
scanf("%d",&sing[i].score[n]);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
// 计算平均分
|
|
|
|
|
aver(sing,num,*num_);
|
|
|
|
|
printf("评分完成。\n");
|
|
|
|
|
}
|
2022-03-06 09:16:39 +00:00
|
|
|
|
int find_xuhao(SING sing[MAX], int num){
|
|
|
|
|
// 按序号查找
|
|
|
|
|
int x;
|
|
|
|
|
printf("请输入需要查找的序号: ");
|
|
|
|
|
scanf("%d",&x);
|
|
|
|
|
for(int i=0;i<num;i++){
|
|
|
|
|
if(x==sing[i].num){
|
|
|
|
|
return i;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
int find_xingming(SING sing[MAX],int num){
|
|
|
|
|
// 按姓名查找
|
|
|
|
|
char x[10];
|
|
|
|
|
printf("请输入需要查找的姓名: ");
|
|
|
|
|
scanf("%s",x);
|
|
|
|
|
for(int i=0;i<num;i++){
|
|
|
|
|
if(strcmp(x,sing[i].name)==0){
|
|
|
|
|
return i;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
void find(SING sing[MAX],int num, int num_){
|
|
|
|
|
// 查找
|
|
|
|
|
printf("请选择查找方式\n");
|
|
|
|
|
int x,n;
|
|
|
|
|
printf("\t1.序号查找\n");
|
|
|
|
|
printf("\t2.姓名查找\n");
|
|
|
|
|
printf("\t0.退出\n");
|
|
|
|
|
scanf("%d",&x);
|
|
|
|
|
switch(x){
|
|
|
|
|
case 1:
|
|
|
|
|
n=find_xuhao(sing,num);
|
|
|
|
|
break;
|
|
|
|
|
case 2:
|
|
|
|
|
n=find_xingming(sing,num);
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if(n==-1){
|
|
|
|
|
printf("未找到该人\n");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
printf("序号\t姓名\t性别\t平均分\t原始成绩\n");
|
|
|
|
|
printf("%d\t%s\t%s\t%.2f",sing[n].num,sing[n].name,sing[n].xb,sing[n].aver);
|
|
|
|
|
for(int j=0;j<num_;j++){
|
|
|
|
|
printf("\t%d",sing[n].score[j]);
|
|
|
|
|
}
|
|
|
|
|
printf("\n");
|
|
|
|
|
}
|
|
|
|
|
void edit(SING sing[MAX],int num){
|
|
|
|
|
// 修改信息
|
|
|
|
|
int x,n;
|
|
|
|
|
printf("请选择修改方式\n");
|
|
|
|
|
printf("\t1.按序号修改\n");
|
|
|
|
|
printf("\t2.按姓名修改\n");
|
|
|
|
|
printf("\t0.退出\n");
|
|
|
|
|
scanf("%d",&x);
|
|
|
|
|
switch(x){
|
|
|
|
|
case 1:
|
|
|
|
|
n=find_xuhao(sing,num);
|
|
|
|
|
break;
|
|
|
|
|
case 2:
|
|
|
|
|
n=find_xingming(sing,num);
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if(n==-1){
|
|
|
|
|
printf("未找到该歌手\n");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
system("cls");
|
|
|
|
|
printf("该歌手原信息如下:\n");
|
|
|
|
|
printf("序号\t姓名\t性别\n");
|
|
|
|
|
printf("%d\t%s\t%s\n\n",sing[n].num,sing[n].name,sing[n].xb);
|
|
|
|
|
|
|
|
|
|
printf("输入修改后的信息:\n");
|
|
|
|
|
printf("序号\t姓名\t性别\n");
|
|
|
|
|
scanf("%d%s%s",&sing[n].num,sing[n].name,sing[n].xb);
|
|
|
|
|
}
|
|
|
|
|
void Delete(SING sing[MAX], int *num){
|
|
|
|
|
// 删除信息
|
|
|
|
|
int x,n;
|
|
|
|
|
printf("请选择删除方式\n");
|
|
|
|
|
printf("\t1.按序号删除\n");
|
|
|
|
|
printf("\t2.按姓名删除\n");
|
|
|
|
|
printf("\t0.退出\n");
|
|
|
|
|
scanf("%d",&x);
|
|
|
|
|
switch(x){
|
|
|
|
|
case 1:
|
|
|
|
|
n=find_xuhao(sing,*num);
|
|
|
|
|
break;
|
|
|
|
|
case 2:
|
|
|
|
|
n=find_xingming(sing,*num);
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if(n==-1){
|
|
|
|
|
printf("未找到该歌手\n");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
// 删除
|
|
|
|
|
for(int i=n;i<*num;i++){
|
|
|
|
|
sing[i]=sing[i+1];
|
|
|
|
|
}
|
|
|
|
|
*num=*num-1;
|
|
|
|
|
}
|
|
|
|
|
void sort_xuhao(SING sing[MAX], int num){
|
|
|
|
|
SING temp;
|
|
|
|
|
for(int i=0;i<num-1;i++){
|
|
|
|
|
for(int j=0;j<num-1-i;j++){
|
|
|
|
|
if(sing[j].num>sing[j+1].num){
|
|
|
|
|
// 交换
|
|
|
|
|
temp=sing[j];
|
|
|
|
|
sing[j]=sing[j+1];
|
|
|
|
|
sing[j+1]=temp;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
void sort_aver(SING sing[MAX], int num){
|
|
|
|
|
SING temp;
|
|
|
|
|
for(int i=0;i<num-1;i++){
|
|
|
|
|
for(int j=0;j<num-1-i;j++){
|
|
|
|
|
if(sing[j].aver>sing[j+1].aver){
|
|
|
|
|
// 交换
|
|
|
|
|
temp=sing[j];
|
|
|
|
|
sing[j]=sing[j+1];
|
|
|
|
|
sing[j+1]=temp;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2022-03-06 09:49:10 +00:00
|
|
|
|
void sort(SING sing[MAX], int num, int num_){
|
|
|
|
|
int x,n;
|
2022-03-06 09:16:39 +00:00
|
|
|
|
printf("请选择排序方式\n");
|
|
|
|
|
printf("\t1.按序号排序\n");
|
|
|
|
|
printf("\t2.按成绩排序\n");
|
|
|
|
|
printf("\t0.退出\n");
|
|
|
|
|
scanf("%d",&x);
|
2022-03-06 09:49:10 +00:00
|
|
|
|
printf("请选择升/降序方式\n");
|
|
|
|
|
printf("\t1.升序\n");
|
|
|
|
|
printf("\t2.降序\n");
|
|
|
|
|
printf("\t0.退出\n");
|
|
|
|
|
scanf("%d",&n);
|
2022-03-06 09:16:39 +00:00
|
|
|
|
switch(x){
|
|
|
|
|
case 1:
|
|
|
|
|
sort_xuhao(sing, num);
|
|
|
|
|
break;
|
|
|
|
|
case 2:
|
|
|
|
|
sort_aver(sing, num);
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
return;
|
|
|
|
|
}
|
2022-03-06 09:49:10 +00:00
|
|
|
|
printf("\n排序后排名如下:\n");
|
|
|
|
|
outarrry(sing,num,num_);
|
2022-03-06 09:16:39 +00:00
|
|
|
|
}
|
2022-03-06 07:05:17 +00:00
|
|
|
|
int main(){
|
|
|
|
|
SING sing[MAX];
|
2022-03-06 07:43:01 +00:00
|
|
|
|
// num 为歌手数,num_ 为评委数
|
2022-03-06 07:22:25 +00:00
|
|
|
|
int num=0,num_=0;
|
2022-03-06 07:05:17 +00:00
|
|
|
|
int choice;
|
|
|
|
|
|
|
|
|
|
while(1){
|
|
|
|
|
// 1.菜单
|
2022-03-06 09:39:49 +00:00
|
|
|
|
system("color fc");
|
|
|
|
|
// 额外
|
|
|
|
|
printf(" o8o . oooo \n");
|
|
|
|
|
printf(" `'' .o8 `888 \n");
|
|
|
|
|
printf(" .oooo.o oooo ooo. .oo. .oooooooo .ooooo. oooo d8b .o888oo .ooooo. .ooooo. 888 \n");
|
|
|
|
|
printf("d88( '8 `888 `888P'Y88b 888' `88b d88' `88b `888""8P 888 d88' `88b d88' `88b 888 \n");
|
|
|
|
|
printf("`'Y88b. 888 888 888 888 888 888ooo888 888 888 888 888 888 888 888 \n");
|
|
|
|
|
printf("o. )88b 888 888 888 `88bod8P' 888 .o 888 888 . 888 888 888 888 888 \n");
|
|
|
|
|
printf("8''888P' o888o o888o o888o `8oooooo. `Y8bod8P' d888b '888' `Y8bod8P' `Y8bod8P' o888o \n");
|
|
|
|
|
printf(" d' YD \n");
|
|
|
|
|
printf(" 'Y88888P' \n");
|
2022-03-06 09:49:10 +00:00
|
|
|
|
printf("\n");
|
|
|
|
|
printf("\t\t\t *************** 歌词比赛评分系统 ***************\n\n");
|
|
|
|
|
printf("\t\t\t\t1.输入歌手信息\t\t2.输出歌手信息\n"); // 已完成
|
|
|
|
|
printf("\t\t\t\t3.新增一个歌手\t\t4.查找歌手信息\n"); // 已完成
|
|
|
|
|
printf("\t\t\t\t5.修改歌手信息\t\t6.删除歌手信息\n"); // 已完成
|
|
|
|
|
printf("\t\t\t\t7.排序歌手\t\t8.评委评分\n"); // 已完成
|
|
|
|
|
printf("\t\t\t\t9.保存歌手信息\t\t10.加载歌手信息\n"); // 已完成
|
|
|
|
|
printf("\t\t\t\t\t\t0.退出\n"); // 已完成
|
2022-03-06 09:39:49 +00:00
|
|
|
|
printf("\n");
|
|
|
|
|
printf("请选择(0-10):");
|
2022-03-06 07:05:17 +00:00
|
|
|
|
|
|
|
|
|
// 2.输入
|
|
|
|
|
scanf("%d", &choice);
|
|
|
|
|
|
|
|
|
|
// 3.退出
|
|
|
|
|
if(choice==0) break;
|
|
|
|
|
|
|
|
|
|
// 4.调用子函数功能
|
|
|
|
|
switch (choice) {
|
|
|
|
|
case 1:
|
|
|
|
|
inarray(sing,&num);
|
|
|
|
|
break;
|
|
|
|
|
case 2:
|
2022-03-06 08:25:13 +00:00
|
|
|
|
outarrry(sing,num,num_);
|
2022-03-06 07:05:17 +00:00
|
|
|
|
break;
|
|
|
|
|
case 3:
|
|
|
|
|
insert(sing,&num);
|
|
|
|
|
break;
|
2022-03-06 09:16:39 +00:00
|
|
|
|
case 4:
|
|
|
|
|
find(sing,num,num_);
|
|
|
|
|
break;
|
|
|
|
|
case 5:
|
|
|
|
|
edit(sing,num);
|
|
|
|
|
break;
|
|
|
|
|
case 6:
|
|
|
|
|
Delete(sing,&num);
|
|
|
|
|
break;
|
|
|
|
|
case 7:
|
2022-03-06 09:49:10 +00:00
|
|
|
|
sort(sing,num,num_);
|
2022-03-06 09:16:39 +00:00
|
|
|
|
break;
|
2022-03-06 08:20:25 +00:00
|
|
|
|
case 8:
|
|
|
|
|
mark(sing,num,&num_);
|
2022-03-06 07:22:25 +00:00
|
|
|
|
break;
|
2022-03-06 08:25:13 +00:00
|
|
|
|
case 9:
|
2022-03-06 08:20:25 +00:00
|
|
|
|
save(sing,num,num_);
|
|
|
|
|
break;
|
2022-03-06 08:25:13 +00:00
|
|
|
|
case 10:
|
2022-03-06 07:22:25 +00:00
|
|
|
|
load(sing,&num,&num_);
|
2022-03-06 07:05:17 +00:00
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
printf("调用输入错误函数\n");
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 5.清屏
|
|
|
|
|
printf("按任意键继续...\n");
|
|
|
|
|
getch();
|
|
|
|
|
system("cls");
|
|
|
|
|
}
|
|
|
|
|
printf("感谢使用,再见!\n");
|
|
|
|
|
return 0;
|
2022-03-06 07:22:25 +00:00
|
|
|
|
}
|