歌手比赛系统 c语言 代码出错了 发邮箱到cyylogo@163.com就谢谢了,一定要在VC++上运行
#include<stdio.h>#include<stdlib.h>#include<time.h>#include<string.h>#defineN3#define...
#include<stdio.h>
#include<stdlib.h>
#include<time.h>
#include<string.h>
#define N 3
#define M 10
int add = N-1;
int sum[N]={0},Max[N],Min[N];
float aver[N]={0};
struct player
{int num;
char name[8];
int score[M];
};
void Inistplayer(struct player a[],int n)
{int i;
for(i=0;i<n;i++)
scanf("%d %s",&a[i].num,&a[i].name);
}
void Inputscore(int score[],int n)
{int i;
for(i=0;i<n;i++)
score[i]=1+(int)10*rand()/(RAND_MAX+1);
}
void sort(struct player a[],float b[],int n)
{int i,k,j,t;
float temp;
char str[8];
for(i=0;i<n;i++)
{k=i;
for(j=i+1;j<n;j++)
if(b[k]>b[j]) k=j;
if(k!=i)
{temp=b[i];
b[i]=b[k];
b[k]=temp;
strcpy(str,a[i].name);
strcpy(a[i].name,a[k].name);
strcpy(a[k].name,str);
t=a[i].num;
a[i].num=a[k].num;
a[k].num=t;
}
}
}
void main()
{int flag=1,n,i,m,j;
FILE *fp;
fp = fopen("data.txt","w+");
struct player a[20];
printf("**********1.输入选手数据***********\n");
printf("**********2.评委打分***************\n");
printf("**********3.成绩排序***************\n");
printf("**********4.数据查询***************\n");
printf("**********5.追加学生数据***********\n");
printf("**********6.写入数据文件***********\n");
printf("**********7.退出系统***************\n");
while(flag)
{printf("你想进行的操作:");
scanf("%d",&n);
switch(n)
{
case 1:Inistplayer(a,N);break;
case 2:srand((unsigned)time(NULL));
for(i=0;i<N;i++)
{
printf("%d位选手的成绩:",i+1);
Inputscore(a[i].score,M);
for(j=0;j<M;j++)
printf("%d ",a[i].score[j]);
printf("\n");
}
break;
case 3:for(i=0;i<N;i++)
{Max[i]=a[i].score[0];
Min[i]=a[i].score[0];
for(j=0;j<M;j++)
{
sum[i]+=a[i].score[j];
if(Max[i]<a[i].score[j]) Max[i]=a[i].score[j];
if(Min[i]>a[i].score[j]) Min[i]=a[i].score[j];
}
aver[i]=(float)(sum[i]-Max[i]-Min[i])/(M-2);
}
sort(a,aver,N);
for(i=0;i<N;i++)
printf("%s %5.2f\n",a[i].name,aver[i]);
break;
case 4:printf("你想查询选手的数据:");
scanf("%d",&m);
for(i=0;i<N;i++)
if(a[i].num==m)
{
printf("%d号选手%s总分:%d,最高分%d,最低分%d,平均分%5.2f",a[i].num,a[i].name,sum[i],Max[i],Min[i],aver[i]);
printf("\n");
}
break;
case 5:printf("请输入要追加的选手数据:\n");
add += 1;
scanf("%d %s",&a[add].num,&a[add].name);
break;
case 6:printf("将数据写入文件中:\n");
for (i = 0 ; i < add+1 ; i++)
{
fprintf(fp,"%d ",a[i].num);
fprintf(fp,"%s ",a[i].name);
fprintf(fp,"%d\n",a[i].score);
}
break;
case 7:exit(0);
break;
default:flag=0;
}
}
} 展开
#include<stdlib.h>
#include<time.h>
#include<string.h>
#define N 3
#define M 10
int add = N-1;
int sum[N]={0},Max[N],Min[N];
float aver[N]={0};
struct player
{int num;
char name[8];
int score[M];
};
void Inistplayer(struct player a[],int n)
{int i;
for(i=0;i<n;i++)
scanf("%d %s",&a[i].num,&a[i].name);
}
void Inputscore(int score[],int n)
{int i;
for(i=0;i<n;i++)
score[i]=1+(int)10*rand()/(RAND_MAX+1);
}
void sort(struct player a[],float b[],int n)
{int i,k,j,t;
float temp;
char str[8];
for(i=0;i<n;i++)
{k=i;
for(j=i+1;j<n;j++)
if(b[k]>b[j]) k=j;
if(k!=i)
{temp=b[i];
b[i]=b[k];
b[k]=temp;
strcpy(str,a[i].name);
strcpy(a[i].name,a[k].name);
strcpy(a[k].name,str);
t=a[i].num;
a[i].num=a[k].num;
a[k].num=t;
}
}
}
void main()
{int flag=1,n,i,m,j;
FILE *fp;
fp = fopen("data.txt","w+");
struct player a[20];
printf("**********1.输入选手数据***********\n");
printf("**********2.评委打分***************\n");
printf("**********3.成绩排序***************\n");
printf("**********4.数据查询***************\n");
printf("**********5.追加学生数据***********\n");
printf("**********6.写入数据文件***********\n");
printf("**********7.退出系统***************\n");
while(flag)
{printf("你想进行的操作:");
scanf("%d",&n);
switch(n)
{
case 1:Inistplayer(a,N);break;
case 2:srand((unsigned)time(NULL));
for(i=0;i<N;i++)
{
printf("%d位选手的成绩:",i+1);
Inputscore(a[i].score,M);
for(j=0;j<M;j++)
printf("%d ",a[i].score[j]);
printf("\n");
}
break;
case 3:for(i=0;i<N;i++)
{Max[i]=a[i].score[0];
Min[i]=a[i].score[0];
for(j=0;j<M;j++)
{
sum[i]+=a[i].score[j];
if(Max[i]<a[i].score[j]) Max[i]=a[i].score[j];
if(Min[i]>a[i].score[j]) Min[i]=a[i].score[j];
}
aver[i]=(float)(sum[i]-Max[i]-Min[i])/(M-2);
}
sort(a,aver,N);
for(i=0;i<N;i++)
printf("%s %5.2f\n",a[i].name,aver[i]);
break;
case 4:printf("你想查询选手的数据:");
scanf("%d",&m);
for(i=0;i<N;i++)
if(a[i].num==m)
{
printf("%d号选手%s总分:%d,最高分%d,最低分%d,平均分%5.2f",a[i].num,a[i].name,sum[i],Max[i],Min[i],aver[i]);
printf("\n");
}
break;
case 5:printf("请输入要追加的选手数据:\n");
add += 1;
scanf("%d %s",&a[add].num,&a[add].name);
break;
case 6:printf("将数据写入文件中:\n");
for (i = 0 ; i < add+1 ; i++)
{
fprintf(fp,"%d ",a[i].num);
fprintf(fp,"%s ",a[i].name);
fprintf(fp,"%d\n",a[i].score);
}
break;
case 7:exit(0);
break;
default:flag=0;
}
}
} 展开
1个回答
展开全部
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <string.h>
#define N 3
#define M 10
int add = N - 1;
int sum[N] = {0},Max[N],Min[N];
float aver[N] = {0};
struct player {
int num;
char name[12];
int score[M];
};
void Inistplayer(struct player a[],int n) {
int i;
for(i = 0;i < n;i++) {
printf("(%d/%d)签号 姓名 : ",i + 1,n);
scanf("%d %s",&a[i].num,a[i].name);
}
}
void Inputscore(int score[],int n) {
int i;
for(i = 0;i < n;i++)
score[i] = 1 + (int)10*rand()/(RAND_MAX + 1);
}
void sort(struct player a[],float b[],int n) {
int i,k,j,t;
float temp;
char str[12];
for(i = 0;i < n - 1;i++) {
k = i;
for(j = i + 1;j < n;j++)
if(b[k] > b[j]) k = j;
if(k != i) {
temp = b[i];
b[i] = b[k];
b[k] = temp;
strcpy(str,a[i].name);
strcpy(a[i].name,a[k].name);
strcpy(a[k].name,str);
t = a[i].num;
a[i].num = a[k].num;
a[k].num = t;
}
}
}
void main() {
int flag = 1,n,i,m,j;
FILE *fp;
fp = fopen("data.txt","w+");
struct player a[20];
printf("\t\t1、输入选手数据\n");
printf("\t\t2、评委打分\n");
printf("\t\t3、成绩排序*\n");
printf("\t\t4、数据查询\n");
printf("\t\t5、追加学生数据\n");
printf("\t\t6、写入数据文件\n");
printf("\t\t7、退出系统\n");
while(flag) {
printf("你想进行的操作:");
scanf("%d",&n);
switch(n) {
case 1:Inistplayer(a,N);break;
case 2:srand((unsigned)time(NULL));
for(i = 0;i < N;i++) {
printf("%d位选手的成绩:",i + 1);
Inputscore(a[i].score,M);
for(j = 0;j < M;j++) printf("%d ",a[i].score[j]);
printf("\n");
}
break;
case 3:for(i = 0;i < N;i++) {
Max[i] = a[i].score[0];
Min[i] = a[i].score[0];
for(j = 0;j < M;j++) {
sum[i] += a[i].score[j];
if(Max[i] < a[i].score[j])
Max[i] = a[i].score[j];
if(Min[i] > a[i].score[j])
Min[i] = a[i].score[j];
}
aver[i] = (float)(sum[i] - Max[i] - Min[i])/(M - 2);
}
sort(a,aver,N);
for(i = 0;i < N;i++)
printf("%s %5.2f\n",a[i].name,aver[i]);
break;
case 4:printf("你想查询选手的数据:");
scanf("%d",&m);
for(i = 0;i < N;i++) {
if(a[i].num == m) {
printf("%d号选手%s总分:%d,最高分%d,最低分%d,平均分%5.2f",a[i].num,a[i].name,sum[i],Max[i],Min[i],aver[i]);
printf("\n");
}
}
break;
case 5:printf("请输入要追加的选手数据:\n");
add += 1;
scanf("%d %s",&a[add].num,&a[add].name);
break;
case 6:printf("将数据写入文件中:\n");
for (i = 0 ; i < add + 1 ; i++) {
fprintf(fp,"%d ",a[i].num);
fprintf(fp,"%s ",a[i].name);
fprintf(fp,"%d\n",a[i].score);
}
break;
case 7:exit(0);
break;
default:flag = 0;
}
}
}
#include <stdlib.h>
#include <time.h>
#include <string.h>
#define N 3
#define M 10
int add = N - 1;
int sum[N] = {0},Max[N],Min[N];
float aver[N] = {0};
struct player {
int num;
char name[12];
int score[M];
};
void Inistplayer(struct player a[],int n) {
int i;
for(i = 0;i < n;i++) {
printf("(%d/%d)签号 姓名 : ",i + 1,n);
scanf("%d %s",&a[i].num,a[i].name);
}
}
void Inputscore(int score[],int n) {
int i;
for(i = 0;i < n;i++)
score[i] = 1 + (int)10*rand()/(RAND_MAX + 1);
}
void sort(struct player a[],float b[],int n) {
int i,k,j,t;
float temp;
char str[12];
for(i = 0;i < n - 1;i++) {
k = i;
for(j = i + 1;j < n;j++)
if(b[k] > b[j]) k = j;
if(k != i) {
temp = b[i];
b[i] = b[k];
b[k] = temp;
strcpy(str,a[i].name);
strcpy(a[i].name,a[k].name);
strcpy(a[k].name,str);
t = a[i].num;
a[i].num = a[k].num;
a[k].num = t;
}
}
}
void main() {
int flag = 1,n,i,m,j;
FILE *fp;
fp = fopen("data.txt","w+");
struct player a[20];
printf("\t\t1、输入选手数据\n");
printf("\t\t2、评委打分\n");
printf("\t\t3、成绩排序*\n");
printf("\t\t4、数据查询\n");
printf("\t\t5、追加学生数据\n");
printf("\t\t6、写入数据文件\n");
printf("\t\t7、退出系统\n");
while(flag) {
printf("你想进行的操作:");
scanf("%d",&n);
switch(n) {
case 1:Inistplayer(a,N);break;
case 2:srand((unsigned)time(NULL));
for(i = 0;i < N;i++) {
printf("%d位选手的成绩:",i + 1);
Inputscore(a[i].score,M);
for(j = 0;j < M;j++) printf("%d ",a[i].score[j]);
printf("\n");
}
break;
case 3:for(i = 0;i < N;i++) {
Max[i] = a[i].score[0];
Min[i] = a[i].score[0];
for(j = 0;j < M;j++) {
sum[i] += a[i].score[j];
if(Max[i] < a[i].score[j])
Max[i] = a[i].score[j];
if(Min[i] > a[i].score[j])
Min[i] = a[i].score[j];
}
aver[i] = (float)(sum[i] - Max[i] - Min[i])/(M - 2);
}
sort(a,aver,N);
for(i = 0;i < N;i++)
printf("%s %5.2f\n",a[i].name,aver[i]);
break;
case 4:printf("你想查询选手的数据:");
scanf("%d",&m);
for(i = 0;i < N;i++) {
if(a[i].num == m) {
printf("%d号选手%s总分:%d,最高分%d,最低分%d,平均分%5.2f",a[i].num,a[i].name,sum[i],Max[i],Min[i],aver[i]);
printf("\n");
}
}
break;
case 5:printf("请输入要追加的选手数据:\n");
add += 1;
scanf("%d %s",&a[add].num,&a[add].name);
break;
case 6:printf("将数据写入文件中:\n");
for (i = 0 ; i < add + 1 ; i++) {
fprintf(fp,"%d ",a[i].num);
fprintf(fp,"%s ",a[i].name);
fprintf(fp,"%d\n",a[i].score);
}
break;
case 7:exit(0);
break;
default:flag = 0;
}
}
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询