C语言程序设计按学号查询成绩
答案:1信息版本:手机版
解决时间 -10-05 15:03
已解决
-10-05 09:05
#include void main()
{int x,k,r;
int xh[50],yy[50],jsj[50],gdsx[50],wl[50];
int i=0;
char yn;
do
{printf("\n======================================================\n");
printf("\n|****欢迎使用成绩管理系统,请选择以下数字进行操作****|\n");
printf("\n|====================================================|\n");
printf("\n|1.录入学生成绩 |\n");
printf("\n|2.显示学生成绩 |\n");
printf("\n|3.查询学生成绩 |\n");
printf("\n|4.修改学生成绩 |\n");
printf("\n|0.退出管理系统 |\n");
printf("\n|====================================================|\n");
printf("\n| 制作人:张杰(车辆-2-1764152228)|");
printf("\n|====================================================|\n");
printf("\n\n");
printf("请选择:");
scanf("%d",&x);
if(x==1)
{printf("您选择了录入学生成绩\n");
do
{printf("学号:");
scanf("%d",&xh[i]);
printf("英语:");
scanf("%d",&yy[i]);
printf("计算机:");
scanf("%d",&jsj[i]);
printf("高等数学:");
scanf("%d",&gdsx[i]);
printf("物理");
scanf("%d",&wl[i]);
i++;
printf("继续录入请按任意键,结束请按*键\n");
fflush(stdin);
scanf("%c",&yn);
}while(yn!='*');
}
if(x==2)
{
printf("您选择了显示学生成绩!\n");
printf("学号 英语 计算机高等数学物理\n");
for(k=0;kprintf("%d\t%d\t%d\t%d\t%d\n",xh[k],yy[k],jsj[k],gdsx[k],wl[k]);
}
if(x==3)
{
printf("您选择了查询学生成绩\n");
printf("请输入需要查询的学号:");
scanf("%d",&xh[r]);
for(r=0;r<=i;r++)
if((xh[i])==xh[r])
{
printf("学号 英语 计算机高等数学物理\n");
printf("%d\t%d\t%d\t%d\t%d\n",xh[i],yy[i],jsj[i],gdsx[i],wl[i]);
break;
}
}
if(x==4)
{printf("您选择了修改学生成绩\n");
printf("请输入需要修改的学号:");
}
if(x==0)
printf("您选择了退出管理系统");
}while(x>0);
}
求大神帮我做一下这个按学号查询和按学号修改,我大一会的不多麻烦用最基础的做,谢谢
全部回答
1楼
-10-05 09:55
#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);
}
}
我要举报
如果感觉以上信息为低俗/不良/侵权的信息,可以点下面链接进行举报,我们会做出相应处理,感谢你的支持!
大家都在看
推荐资讯