C语言程序设计学生成绩查询系统

2024-11-17 15:29:33
推荐回答(5个)
回答1:

#include"stdio.h"
#include"string.h"
#define N 1000
void menu();
int password();
int dedao();

int uninque(struct STUDENT shu[],int len,int xuehao);
void shuchu(struct STUDENT shu[],int len);
void send(struct STUDENT shu[],int len);
int readFromFile(struct STUDENT shu[]);
void chaxun(struct STUDENT shu[],int len);
void paixu(struct STUDENT shu[],int len);

struct STUDENT
{
int num;
char name[10];
int score;
} shu[N];
main()
{ int len=0,key,choice;

do {
key=password();

}while(key==0);

while(1)

{ menu();
printf("请输入选项<1,2,3,4,5,6,7>\n");
scanf("%d",&choice);
switch(choice)
{
case 1:printf("输入信息函数\n"); len=dedao(shu,len); break;
case 2:printf("输出函数被调用\n"); shuchu(shu,len); break;
case 3:printf("保存到文件函数被调用\n"); send(shu,len); break;
case 4:printf("从文件读函数被调用\n"); len=readFromFile( shu); break;
case 5:printf("按学号查询函数被调用\n"); chaxun(shu,len); break;
case 6:printf("按成绩排序函数被调用\n"); paixu(shu,len); break ;
case 7:exit(0);break;
}

}

}

void menu()
{
printf("\n");
printf(" *******************************************\n");
printf(" * 学生成绩管理系统2.0 *\n");
printf(" * 1.输入信息 *\n");
printf(" * 2.输出信息 *\n");
printf(" * 3.保存到文件 *\n");
printf(" * 4.从文件读 *\n");
printf(" * 5.按学号查询 *\n");
printf(" * 6.按成绩排序(由大到小) *\n");
printf(" * 7.程序结束 *\n");
printf(" *******************************************\n");

}
int password()
{
char a[100];
char key[]="asd";
printf("请输入密码\n");
scanf("%s",&a);
if(strcmp(a,key)==0)
return 1;
else
return 0;

}

int dedao(struct STUDENT shu[],int len)
{ int i=len;
int flag=0;
int xuehao,bank,chengji;
while(i {
while(1)
{
printf("学号");
scanf("%d",&xuehao);
if(xuehao==0)
{ flag=1;
break;
}

bank=uninque(shu,i,xuehao);
if(bank==0)
{ shu[i].num=xuehao;
break;}

}
if(flag==1)
break;

printf("姓名");
scanf("%s",&shu[i].name);

while (1)
{
printf("成绩");

if(scanf("%d",&chengji)==1)
{break;}
printf("输入格式错误,请重新输入!");
while(getchar()!='\n')
continue;

}
while(getchar()!='\n')
continue;
shu[i].score=chengji;
i++;

}
return i;
}
int uninque(struct STUDENT shu[],int len,int xuehao)
{ int i;
int bank=0;
for (i=0;i {
if(xuehao==shu[i].num)
bank=1;

}

return bank;

}

void shuchu(struct STUDENT shu[],int len)
{

int i;

printf("%-4s %-10s %-3s","学号","姓名","成绩\n\n");
for(i=0;i {
printf("%-4d %-10s %-3d",shu[i].num,shu[i].name,shu[i].score);
printf("\n");
}
printf("\n\n");

}

void send(struct STUDENT shu[],int len)
{
int i;

FILE *fp;
fp=fopen("d:\\chegnji.txt","wb");
if(fp==NULL)
{
printf("打开文件出错!\n");
exit(0);
}

for(i=0;i
fwrite(shu+i,sizeof(struct STUDENT),1,fp);

fclose(fp);
}

int readFromFile(struct STUDENT shu[])
{
FILE *fp=NULL;
int i=0;

fp=fopen("d:\\chegnji.txt","rb");

if(fp!=NULL)
{
printf("%-4s %-10s %-3s","学号","姓名","成绩\n\n");

while(!feof(fp))
{

if(i>=N)
break;
if(fread(shu+i,sizeof(struct STUDENT),1,fp))

printf("%-4d %-10s %-3d",shu[i].num,shu[i].name,shu[i].score);
printf("\n");
i++;
}

fclose(fp);
}
i=i-1;
return i;
}

void chaxun(struct STUDENT shu[],int len)

{
int i,nue,b=0;

while(1)

{printf("input the student number (input'0' close) ");
scanf("%d",&nue);
b=0;
if(nue==0)
break;
for (i=0;i {
if(nue==shu[i].num)
{ printf("%-4s %-10s %-3s","学号","姓名","成绩\n\n");
printf("%-4d %-10s %-3d\n",shu[i].num,shu[i].name,shu[i].score);
b=1;

}

}
if(b==0)
printf("The number is not exist!\n");
}

}

void paixu(struct STUDENT shu[],int len)
{
int i,j;
struct STUDENT temp;
printf("%-4s %-10s %-3s","学号","姓名","成绩\n\n");
for(i=0;i {
for(j=i;j {
if(shu[j].score>shu[i].score)
{
temp=shu[j];
shu[j]=shu[i];
shu[i]=temp;
}

}

printf("%-4d %-10s %-3d\n",shu[i].num,shu[i].name,shu[i].score);

}

}

回答2:

#include"stdio.h"
#include"string.h"
#define
N
1000
void
menu();
int
password();
int
dedao();
int
uninque(struct
STUDENT
shu[],int
len,int
xuehao);
void
shuchu(struct
STUDENT
shu[],int
len);
void
send(struct
STUDENT
shu[],int
len);
int
readFromFile(struct
STUDENT
shu[]);
void
chaxun(struct
STUDENT
shu[],int
len);
void
paixu(struct
STUDENT
shu[],int
len);
struct
STUDENT
{
int
num;
char
name[10];
int
score;
}
shu[N];
main()
{
int
len=0,key,choice;
do
{
key=password();
}while(key==0);
while(1)
{
menu();
printf("请输入选项<1,2,3,4,5,6,7>\n");
scanf("%d",&choice);
switch(choice)
{
case
1:printf("输入信息函数\n");
len=dedao(shu,len);
break;
case
2:printf("输出函数被调用\n");
shuchu(shu,len);
break;
case
3:printf("保存到文件函数被调用\n");
send(shu,len);
break;
case
4:printf("从文件读函数被调用\n");
len=readFromFile(
shu);
break;
case
5:printf("按学号查询函数被调用\n");
chaxun(shu,len);
break;
case
6:printf("按成绩排序函数被调用\n");
paixu(shu,len);
break
;
case
7:exit(0);break;
}
}
}
void
menu()
{
printf("\n");
printf("
*******************************************\n");
printf("
*
学生成绩管理系统2.0
*\n");
printf("
*
1.输入信息
*\n");
printf("
*
2.输出信息
*\n");
printf("
*
3.保存到文件
*\n");
printf("
*
4.从文件读
*\n");
printf("
*
5.按学号查询
*\n");
printf("
*
6.按成绩排序(由大到小)
*\n");
printf("
*
7.程序结束
*\n");
printf("
*******************************************\n");
}
int
password()
{
char
a[100];
char
key[]="asd";
printf("请输入密码\n");
scanf("%s",&a);
if(strcmp(a,key)==0)
return
1;
else
return
0;
}
int
dedao(struct
STUDENT
shu[],int
len)
{
int
i=len;
int
flag=0;
int
xuehao,bank,chengji;
while(i{
while(1)
{
printf("学号");
scanf("%d",&xuehao);
if(xuehao==0)
{
flag=1;
break;
}
bank=uninque(shu,i,xuehao);
if(bank==0)
{
shu[i].num=xuehao;
break;}
}
if(flag==1)
break;
printf("姓名");
scanf("%s",&shu[i].name);
while
(1)
{
printf("成绩");
if(scanf("%d",&chengji)==1)
{break;}
printf("输入格式错误,请重新输入!");
while(getchar()!='\n')
continue;
}
while(getchar()!='\n')
continue;
shu[i].score=chengji;
i++;
}
return
i;
}
int
uninque(struct
STUDENT
shu[],int
len,int
xuehao)
{
int
i;
int
bank=0;
for
(i=0;i{
if(xuehao==shu[i].num)
bank=1;
}
return
bank;
}
void
shuchu(struct
STUDENT
shu[],int
len)
{
int
i;
printf("%-4s
%-10s
%-3s","学号","姓名","成绩\n\n");
for(i=0;i{
printf("%-4d
%-10s
%-3d",shu[i].num,shu[i].name,shu[i].score);
printf("\n");
}
printf("\n\n");
}
void
send(struct
STUDENT
shu[],int
len)
{
int
i;
FILE
*fp;
fp=fopen("d:\\chegnji.txt","wb");
if(fp==NULL)
{
printf("打开文件出错!\n");
exit(0);
}
for(i=0;ifwrite(shu+i,sizeof(struct
STUDENT),1,fp);
fclose(fp);
}
int
readFromFile(struct
STUDENT
shu[])
{
FILE
*fp=NULL;
int
i=0;
fp=fopen("d:\\chegnji.txt","rb");
if(fp!=NULL)
{
printf("%-4s
%-10s
%-3s","学号","姓名","成绩\n\n");
while(!feof(fp))
{
if(i>=N)
break;
if(fread(shu+i,sizeof(struct
STUDENT),1,fp))
printf("%-4d
%-10s
%-3d",shu[i].num,shu[i].name,shu[i].score);
printf("\n");
i++;
}
fclose(fp);
}
i=i-1;
return
i;
}
void
chaxun(struct
STUDENT
shu[],int
len)
{
int
i,nue,b=0;
while(1)
{printf("input
the
student
number
(input'0'
close)
");
scanf("%d",&nue);
b=0;
if(nue==0)
break;
for
(i=0;i{
if(nue==shu[i].num)
{
printf("%-4s
%-10s
%-3s","学号","姓名","成绩\n\n");
printf("%-4d
%-10s
%-3d\n",shu[i].num,shu[i].name,shu[i].score);
b=1;
}
}
if(b==0)
printf("The
number
is
not
exist!\n");
}
}
void
paixu(struct
STUDENT
shu[],int
len)
{
int
i,j;
struct
STUDENT
temp;
printf("%-4s
%-10s
%-3s","学号","姓名","成绩\n\n");
for(i=0;i{
for(j=i;j{
if(shu[j].score>shu[i].score)
{
temp=shu[j];
shu[j]=shu[i];
shu[i]=temp;
}
}
printf("%-4d
%-10s
%-3d\n",shu[i].num,shu[i].name,shu[i].score);
}
}

回答3:

#defanie N 5
main()
{
int i,sum=0,high,score[N];
float average;
printf("input everyone's score.\n");
for(i=0;i scanf("%d",&score[i]);
for(high=score[0],i=0;i {
sum+=score[i];
if(score[i]>high)high=score[i];
}
average=(float)sum/N;
printf("average=%f\n",average);
printf("highest=%d\n",high);

}

回答4:

使用易查分三分钟就可以满足你的要求哦。

回答5:

发消息给你了