用c语言制作一个学生成绩管理系统

2024-12-17 04:10:19
推荐回答(3个)
回答1:

下面的程序是个相类似的程序,你稍微修改一下,即可达到要求:
#include
#include
#include
#include

struct student
{ char num[10];
char name[20];
char sex[5];
float grade[3];
float v;
float sum;
}stu[50];
int k=0;

void input();
void display();
void lookandchange();
void average();
void paixu();
void save();

void main()
{
int a;
do
{

printf("\n\n ******************************************************************\n");
printf(" *"); printf("\t\twelcome enter the student management system"); printf("\t*");
printf("\n ******************************************************************\n");

printf(" *"); printf("\t 1.Access student information"); printf("\t\t\t\t*\n");
printf(" *"); printf("\t 2.Display student information"); printf("\t\t\t\t*\n");
printf(" *"); printf("\t 3.LookandChange student information"); printf("\t\t\t*\n");
printf(" *"); printf("\t 4.By sum Sort student information and output"); printf("\t\t*\n");
printf(" *"); printf("\t 5.save the student information"); printf("\t\t\t*\n");
printf(" *"); printf("\t 6. exit "); printf("\t\t\t\t\t*\n");
printf(" ******************************************************************\n");

printf(" Enter you choice : ");
scanf("%d",&a);

switch(a)
{

case 1:printf("\n");input();break;
case 2:printf("\n");display();break;
case 3:printf("\n");lookandchange();break;
case 4:printf("\n");paixu();break;
case 5:printf("\n");save();break;
case 6:printf("\n");exit(0);break;
default:printf("\nThe choice is between 1 to 6.\n");
}
}while(a!=0);

}

void input()
{ int j;
char ch[20];
printf("\nenter student information:\n");
do
{ printf("\nnum: ");
scanf("%s",stu[k].num);
printf("\nname: ");
scanf("%s",stu[k].name);
printf("\nsex: ");
scanf("%s",stu[k].sex);
for(j=0;j<3;j++)
{ printf("\ngrade%d: ",j+1);
scanf("%f",&stu[k].grade[j]); }
k++;
printf("\nif want continue input student information(y/n): ");
scanf("%s",ch);
}while(strcmp(ch,"y")==0||strcmp(ch,"Y")==0);
average();
display();
}

void display()
{ int i;
printf(" the student information is:\n");
for(i=0;i { printf("%-10s %-10s %-5s %.2f %.2f %.2f %8f %8f\n",stu[i].num,stu[i].name,stu[i].sex,stu[i].grade[0],stu[i].grade[1],stu[i].grade[2],stu[i].sum,stu[i].v);
printf("\n"); }
}

void average()
{ int i,j;
for(i=0;i { stu[i].sum=0;
for(j=0;j<3;j++)
stu[i].sum=stu[i].sum+stu[i].grade[j] ;
stu[i].v=stu[i].sum/5; }
}

void lookandchange()

{ int pass[4]; int i,j,l,flag;
char a[20],ch[10],c[20];
printf("This is a database management system:\n");
for(l=0;l<3;l++)
{ flag=0;
printf(" please enter the password: ");
scanf("%1d%1d%1d%1d",&pass[0],&pass[1],&pass[2],&pass[3]);
for(i=0;i<4;i++)
if(pass[i]==i+1) flag=flag+1;
if(flag==4)
{ printf("\nenter you want look student num:");
scanf("%s",a);
for(i=0;i if(strcmp(stu[i].num,a)==0) printf("%-10s %-10s %-5s %.2f %.2f %.2f %8f %8f\n",stu[i].num,stu[i].name,stu[i].sex,stu[i].grade[0],stu[i].grade[1],stu[i].grade[2],stu[i].sum,stu[i].v);
printf("\nenter you want look student name:");
scanf("%s",a);
for(i=0;i if(strcmp(stu[i].name,a)==0) printf("%-10s %-10s %-5s %.2f %.2f %.2f %8f %8f\n",stu[i].num,stu[i].name,stu[i].sex,stu[i].grade[0],stu[i].grade[1],stu[i].grade[2],stu[i].sum,stu[i].v);
printf("\nenter you want change student num:");
scanf("%s",a);
for(i=0;i {
if(strcmp(stu[i].num,a)==0)
{ printf("\nyou sure want change student num(y/n): ");
scanf("%s",ch);
if(strcmp(ch,"y")==0||strcmp(ch,"Y")==0)
printf("\nyou sure want change student name(y/n): ");
scanf("%s",ch);
if(strcmp(ch,"y")==0||strcmp(ch,"Y")==0)
printf("\nyou sure want change student sex(y/n): ");
scanf("%s",ch);
if(strcmp(ch,"y")==0||strcmp(ch,"Y")==0)
printf("\nyou sure want change student grade(y/n): ");
scanf("%s",ch);
if(strcmp(ch,"y")==0||strcmp(ch,"Y")==0)
for(j=0;j<3;j++)

stu[i].sum=0;
for(j=0;j<5;j++)
stu[i].sum=stu[i].sum+stu[i].grade[j] ;
stu[i].v=stu[i].sum/5;
}
} printf("\nyou sure want delete student information(y/n): ");
scanf("%s",ch);
if(strcmp(ch,"y")==0||strcmp(ch,"Y")==0)
{ printf("\nenter you want delete num :\n");
printf("num:");
scanf("%s",&c);
for(i=0;i if(strcmp(c,stu[i].num)==0) break;
for(j=i;j<=2;j++)
stu[j]=stu[j+1];
printf("\t\t\tyou had delete %s\n",c);
k--; }
}
else printf("\nyou enter password is wrong.\n"); }
display();
}

void paixu()
{ struct student temp;
int i,j;
for(i=0;i{
for(j=i+1;j {
if(stu[i].sum {
temp=stu[i];
stu[i]=stu[j];
stu[j]=temp;
}
} }
display();
}

void save()
{ FILE *fp; int i;
if((fp=fopen("xinxi.txt","w"))==NULL)
{ printf("cannot write the file.\n");
exit(0);}
for(i=0;strlen(stu[i].num)!=0;i++)
fprintf(fp,"%-10s %-10s %-5s %.2f %.2f %.2f %8f %8f\n",stu[i].num,stu[i].name,stu[i].sex,stu[i].grade[0],stu[i].grade[1],stu[i].grade[2],stu[i].sum,stu[i].v);
fclose(fp);
}

进入修改数据的密码是1234 你有三次机会输入密码

回答2:

用化繁为简的思路去做会比较简单的,看别人的程序不如自己做

回答3:

http://tieba.baidu.com/f?kz=1109535412