学生成绩管理系统C语言代码

2024-11-24 20:01:22
推荐回答(5个)
回答1:

#include"stdio.h"
#include
#include

#define N 30
struct student
{
int num;
char name[20];
int age;
int Math;
int English;
int Physical;
long int sum;
}stu[N];

enter()
{int i,n;
printf("How many students(1-%d)?:",N);
scanf("%d",&n);
printf("\nEnter data now\n\n");
for(i=0;i {printf("\n Input %dth student record.\n",i+1);
input(i);
}
if(i!=0) save(n);
printf_back(); /* browse or back */
}

add()
{int i,n,m,k;
FILE *fp;
n=load();
printf("How many students are you want to add(1-%d)?:",N-n);
scanf("%d",&m);
k=m+n;
for(i=n;i {printf("\n Input %dth student record.\n",i+1);
input(i);
}
if((fp=fopen("score.txt","ab"))==NULL)
{printf("Cannot open file.\n");
}
for(i=n;i if(fwrite(&stu[i],sizeof(struct student),1,fp)!=1)
printf("file write error.\n");
fclose(fp);
printf_back();
}

/* insert()
{int n,c;
struct student s;
n=load();
puts("\n Input one data.\n");
do
{input(n);
printf_face();
printf_one(n);
printf("\n\nAre you sure?\n\n\t 1.Sure\t2.cancel and again\t3.Back without save [ ]\b\b");
scanf("%d",&c);
if(c==1)
{
save(n+1);
printf_back();
}
else if(c!=2) menu();
}
while(c==2);
} */

modify()
{struct student s;
FILE *fp;
int i,n,k,w0=1,w1,w2=0;
n=load();
do
{
k=-1;
printf_face();
for(i=0;i {if((i!=0)&&(i%10==0))
{printf("\n\nRemember NO.031073- which needed modify.Pass any key to continue ...");
getch();
puts("\n\n");
}
printf_one(i);
printf("\n");
}
do
{printf("\n\nEnter NO.031073- that you want to modify! NO.:031073-");
scanf("%d",&s.num);
for(i=0;i if(s.num==stu[i].num)
{k=i;
s=stu[i]; /* chengji beifei */
}
if(k==-1) printf("\n\nNO exist!please again");
}
while(k==-1);
printf_face();
printf_one(k);
w1=modify_data(k,n);
if(w1==1)
{printf("\nSuccessful ^_^.\n\nAre you modify another?\n\n\t1.Yes2.Back with save\t[ ]\b\b");
scanf("%d",&w0);
w2=1;
}
else
{w0=0; /* end */
if(w2==1)
stu[k]=s;
}
if(w0!=1&&w2==1) save(n); /* w0!=1 return w2==1 modify */
}
while(w0==1);
menu();
}

delete()
{struct student s;
FILE *fp;
int i,n,k,w0=1,w1,w2=0;
n=load();
do
{
k=-1;
printf_face();
for(i=0;i {if((i!=0)&&(i%10==0))
{printf("\n\nRemember NO.031073- which needed delete.Pass any key to continue ...");
getch();
puts("\n\n");
}
printf_one(i);
printf("\n");
}
do
{printf("\n\nEnter NO.031073- that you want to delete! NO.:031073-");
scanf("%d",&s.num);
for(i=0;i if(s.num==stu[i].num)
{k=i;
s=stu[i]; /* chengji beifei */
}
if(k==-1) printf("\n\nNO exist!please again");
}
while(k==-1);
printf_face();
printf_one(k);
printf("\nAre you sure?\n\n\t1.Sure2.Back without save in this time [ ]\b\b");
scanf("%d",&w1);
if(w1==1)
{
stu[k].sum=0;
printf("\nSuccessful ^_^.\n\nAre you delete another?\n\n\t1.Yes2.Back with save\t[ ]\b\b");
scanf("%d",&w0);
w2=1;
}
else
{w0=0; /* end */
if(w2==1)
stu[k]=s;
}
if(w0!=1&&w2==1) save(n);
}
while(w0==1);
menu();
}

modify_score()
{struct student s;
FILE *fp;
int i,n,k,w0=1,w1,w2=0;
n=load();
do
{
k=-1;
printf_face();
for(i=0;i {if((i!=0)&&(i%10==0))
{printf("\n\nRemember NO.031073 which score needed modify.Pass any key to continue ...");
getch();
puts("\n\n");
}
printf_one(i);
printf("\n");
}
do
{printf("\n\nEnter NO.031073- that you want to modify! NO.:031073-");
scanf("%d",&s.num);
for(i=0;i if(s.num==stu[i].num)

{k=i;
s=stu[i]; /* chengji beifei */
}
if(k==-1) printf("\n\nNO exist!please again");
}
while(k==-1);
printf_face();
printf_one(k);
w1=modify_score1(k);
if(w1==1)
{printf("\nSuccessful ^_^.\n\nAre you modify another score?\n\n\t1.Yes2.Back with save\t[ ]\b\b");
scanf("%d",&w0);
w2=1;
}
else
{w0=0; /* end */
if(w2==1)
stu[k]=s;
}
if(w0!=1&&w2==1) save(n); /* w0!=1 return w2==1 modify */
}
while(w0==1);
menu();
}

order()
{int i,j,k,n;
struct student s;
n=load();
for(i=0;i {k=i;
for(j=i+1;j if(stu[j].num s=stu[i];stu[i]=stu[k];stu[k]=s;
}
save(n);
puts("\n\n");
printf_back();
}

browse()
{int i,j,n;
n=load();
printf_face();
for(i=0;i {if((i!=0)&&(i%10==0))
{printf("\n\nPass any key to contiune ...");
getch();
puts("\n\n");
}
printf_one(i);
printf("\n");
}
printf("\tThere are %d record.\n",n);
printf("\nPass any key to back...");
getch();
menu();
}

save(int n)
{FILE *fp;
int i;
if((fp=fopen("score.txt","wb"))==NULL)
{printf("\nCannot open file\n");
return NULL;
}
for(i=0;i if(stu[i].sum!=0)
if(fwrite(&stu[i],sizeof(struct student),1,fp)!=1)
printf("file write error\n");
fclose(fp);
}

load()
{FILE *fp;
int i;
if((fp=fopen("score.txt","rb"))==NULL)
{printf("\nCannot open file\n");
return NULL;
}
for(i=0;!feof(fp);i++)
fread(&stu[i],sizeof(struct student),1,fp);
fclose(fp);
return(i-1);
}

no_input(int i,int n)
{int k,w1;
do
{w1=0;
printf("NO.:031073-");
scanf("%d",&stu[i].num);
if(stu[i].num<1 || stu[i].num>N)
{puts("Input error! Only be made up of(1-N).Please reinput!\n");
w1=1;
}
if(w1!=1)
for(k=0;k if(k!=i&&(stu[k].num==stu[i].num))
{puts("This record is exist. Please reinput!\n");
w1=1;break;
}
}
while(w1==1);
}

enter_score(int i)
{printf("Math English Physical");
scanf("%d %d %d",&stu[i].Math,&stu[i].English,&stu[i].Physical);
}
sum(int i)
{
stu[i].sum=stu[i].Math+stu[i].English+stu[i].Physical;
}

input(int i)
{no_input(i,i);
printf("name: age:");
scanf("%s %d",stu[i].name,&stu[i].age);
enter_score(i);
sum(i);
}

modify_score1(int i)
{int c,w1;
do
{
puts("\nmodify by=>\n\n 1.Math 2.English 3.Physical4.all score 5.cancel and back");
printf("Which you needed?:[ ]\b\b");
scanf("%d",&c);
if(c>5||c<1)
{puts("\nChoice error! Please again!");
getchar();
}
}
while(c>5||c<1);
do
{switch(c)
{
case 1:printf("Math:");scanf("%d",&stu[i].Math);break;
case 2:printf("English:");scanf("%d",&stu[i].English);break;
case 3:printf("Physical:");scanf("%d",&stu[i].Physical);break;
case 4:enter_score(i);break;
case 5:break;
}
if(c>0&&c<5) sum(i);
puts("\nNow:\n");
printf_face();
printf_one(i);
printf("\nAre you sure?\n\n\t1.Sure 2.No and remodify3.Back without save in this time [ ]\b\b");
scanf("%d",&w1);
}
while(w1==2);
return(w1);
}

modify_data(int i,int n)
{int c,w1;
do
{
puts("\nmodify by=>\n\n 1.NO. 2.name 3.age 4.Math 5.English 6.Physical7.all score 8.all data 9.cancel and back");
printf("Which you needed?:[ ]\b\b");
scanf("%d",&c);
if(c>9||c<1)
{puts("\nChoice error! Please again!");
getchar();
}
}
while(c>9||c<1);
do
{switch(c)
{case 1:no_input(i,n);break;
case 2:printf("name:");scanf("%s",stu[i].name);break;
case 3:printf("age:");scanf("%d",&stu[i].age);break;
case 4:printf("Math:");scanf("%d",&stu[i].Math);break;
case 5:printf("English:");scanf("%d",&stu[i].English);break;
case 6:printf("Physical:");scanf("%d",&stu[i].Physical);break;
case 7:enter_score(i);break;
case 8:input(i);break;
case 9:break;
}
if(c>3&&c<8) sum(i);
puts("\nNow:\n");
printf_face();
printf_one(i);
printf("\nAre you sure?\n\n\t1.Sure 2.No and remodify3.Back without save in this time [ ]\b\b");
scanf("%d",&w1);
}
while(w1==2);
return(w1);
}

printf_face()
{printf("\nNO.031073 name age Math English Physical sum\n");
}

printf_one(int i)
{
printf("%6d %8s %4d",stu[i].num,stu[i].name,stu[i].age);
printf("%5d %5d %8d %10d",stu[i].Math,stu[i].English,stu[i].Physical,stu[i].sum);
}

printf_back()
{int k,w;
printf("\n\n\tSuccessful.^_^\n\n");
printf("What do you want to do?\n\n\t1.Browse all now\t2.Back:[ ]\b\b");
scanf("%d",&w);
if(w==1) browse();
else menu();
}
menu()
{int w1;
char n;
do
{
puts("\t\t****************MENU****************\n\n");
puts("\t\t\t\tA.Enter new data");
puts("\t\t\t\tB.Addition data");
puts("\t\t\t\tC.Modify data");
puts("\t\t\t\tD.Delete data");
puts("\t\t\t\tE.Modify score");
puts("\t\t\t\tF.Order by number");
puts("\t\t\t\tG.Browse all");
puts("\t\t\t\tH.Exit");
puts("\n\n\t\t************************************\n");
printf("Choice your number(A-H):[ ]\b\b");
n=getchar();
printf("\n");
if(n<'A'||n>'H')
w1=1;
else w1=0;
}
while(w1==1);
switch(n)
{case 'A':enter();break;
case 'B':add();break;
case 'C':modify();break;
case 'D':delete();break;
case 'E':modify_score();break;
case 'F':order();break;
case 'G':browse();break;
case 'H':exit(0);
}
}
char password[7]="123456";
main()
{
char s[7];
printf("\t\t请输入密码:\n\t\t\n\t\t");
scanf("%s",s);
if(!strcmp(s,password))
{
printf("\n\t\t恭喜你进入学生成绩管理系统\n");
menu();
}
else
{
printf("\t\t 密码错误\n\n");
main();
}
}

回答2:

头文件:::
#ifndef H_STUDENT_HH
#define H_STUDENT_HH

#include "stdio.h"
#include "string.h"
#include "malloc.h"

#define LEN sizeof(struct message_student) /*一个结构体数组元素的长度*/
#define numsubs 5 /*学科数目*/
typedef struct message_student /*结构体定义*/
{
char number[6];
char name[20];
char sex[4];
float subject[numsubs];
float score;
float average;
int index;
}student;

extern int numstus; /*学生数目*/
extern student *pointer; /*指向结构体数组*/
extern int lens;

int menu_select(); /*函数声明*/
int openfile(student stu[]);
int findrecord(student stud[]);
int writetotext(student stud[]);
void welcome();
void display1();
void showtable();
void sort(student stu[]);
void deleterecord(student stu[],int i);
void addrecord(student stud[]);
void display(student stud[],int n1,int n2);
void amendrecord(student stud[]);
void count(student stud[]);
void sortnum(student stud[]);
void sortnum2(student stud[]);
void sortname(student stud[]);
void sortname2(student stud[]);
void sortcount(student stud[]);
void sortcount2(student stud[]);
void statistic(student stud[]);
void display1();

#endif

#include "head.h"
int menu_select()
{
char c;
printf("\n\n");
printf(" | 1. 增加学生记录 5.统计信息 |\n");
printf(" | 2. 查询学生记录 6.打开文件 |\n");
printf(" | 3. 修改学生记录 7.保存文件 |\n");
printf(" | 4. 学生纪录排序 8.显示记录 |\n");
printf(" | 0.退出系统 |\n");
printf("\n\n");
printf("请选择(0-8):");
c=getchar();
getchar();
return (c-'0');
}

#include "head.h"
int findrecord(student stud[]) /*查找信息*/
{
char str[2];
int i,num;
if(numstus==0)
{
printf("没有可被查找的记录\n");
return -1;
}
else
{
printf("以何种方式查找?\n1.学号\t2.姓名\t3.名次\n");
gets(str);
if(str[0]=='1') /*按学号查找*/
{
printf("请输入学号:");
gets(str);
for(i=0;i<=numstus;i++)
if(strcmp(str,stud[i].number)==0)
{
display(stud,i,i);
break;
}
else continue;
}
else if(str[0]=='2') /*按姓名查找*/
{
printf("请输入姓名:");
gets(str);
for(i=0;i<=numstus;i++)
if(strcmp(str,stud[i].name)==0)
{
display(stud,i,i);
break;
}
else continue;
}
else if(str[0]=='3') /*按名次查找*/
{
printf("请输入名次:");
scanf("%d",&num);
getchar();
for(i=0;i<=numstus;i++)
if(num==stud[i].index)
{
display(stud,i,i);
break;
}
else continue;
}
if(i>numstus)
{
printf("没有查找所要的信息。\n");
return -1;
}
return i;
}
}

#include"head.h"
int openfile(student stu[])
{
int i=0,j;
FILE *fp;
char filename[20],str[2];
if(numstus!=0)
{
printf("已经有记录存在,是否保存?(y/n)");
gets(str);
if(str[0]=='y'||str[0]=='Y')
writetotext(stu);
}
printf("请输入文件名:");
gets(filename);
numstus=0;
if((fp=fopen(filename,"rb+"))==NULL)
{
printf("无法打开该文件\n");
return(-1);
}
fscanf(fp,"%d",&numstus);
fgetc(fp);
while(i {
fscanf(fp,"%s",stu[i].number);
fscanf(fp,"%s",stu[i].name);
fscanf(fp,"%s",stu[i].sex);
for(j=0;j fscanf(fp,"%f",&stu[i].subject[j]);
fscanf(fp,"%f",&stu[i].score);
fscanf(fp,"%f",&stu[i].average);
fscanf(fp,"%d",&stu[i].index);
i++;
}
fclose(fp);
printf("文件读取成功\n");
printf("是否显示纪录?(y/n)");
gets(str);
if(str[0]=='y'||str[0]=='Y')
display(stu,0,numstus-1);
return(0);
}
#include "head.h"
void sort(student stud[])
{
int i,j=0;
char str[5];
student *p;
p=stud;
if(numstus==0)
{
printf("没有可供查询的记录!");
}
while(1)
{
for(i=0;;i++)
{
printf(" 请输入查询方式:");
printf("(直接输入回车则结束查询操作)\n");
printf("1.按照学号\t");
printf("2.按照姓名\t");
printf("3.按照名次\n");
gets(str);
if(strlen(str)==0) break;
if(str[0]=='1')
{
printf("请输入排序次序:\n");
printf("1.升序排列\t");
printf("2.降序排列\n");
gets(str);
if(str[0]=='1')
sortnum2(p);
else
sortnum(p);
display(stud,0,numstus-1);
}
else if(str[0]=='2')
{
printf("请输入排序次序:\n");
printf("1.升序排列\t");
printf("2.降序排列\n");
gets(str);
if(str[0]=='1')
sortname2(p);
else
sortname(p);
display(stud,0,numstus-1);
}
else if(str[0]=='3')
{
printf("请输入排序次序:\n");
printf("1.升序排列\t");
printf("2.降序排列\n");
gets(str);
if(str[0]=='1')
sortcount2(p);
else
sortcount(p);
display(stud,0,numstus-1);
}
else printf("请输入1~3");
printf("是否退出排序?(y/n)");
gets(str);
if(str[0]=='y'||str[0]=='Y') break;
}
return;
}
}
void sortnum(student stud[])
{
int i,j;
student temp;
student *p;
p=stud;
for(i=0;i for(j=0;j {
if(strcmp(stud[j+1].number,stud[j].number)>0)
{
temp=*(p+j);
*(p+j)=*(p+j+1);
*(p+j+1)=temp;
}
}
}
void sortnum2(student stud[])
{
int i,j;
student temp;
student *p;
p=stud;
for(i=0;i for(j=0;j {
if(strcmp(stud[j].number,stud[j+1].number)>0)
{
temp=*(p+j);
*(p+j)=*(p+j+1);
*(p+j+1)=temp;
}
}
}
void sortname(student stud[])
{
int i,j;
student temp;
student *p;
p=stud;
for(i=0;i for(j=0;j {
if(strcmp(stud[j+1].name,stud[j].name)>0)
{
temp=*(p+j);
*(p+j)=*(p+j+1);
*(p+j+1)=temp;
}
}
}
void sortname2(student stud[])
{
int i,j;
student temp;
student *p;
p=stud;
for(i=0;i for(j=0;j {
if(strcmp(stud[j].name,stud[j+1].name)>0)
{
temp=*(p+j);
*(p+j)=*(p+j+1);
*(p+j+1)=temp;
}
}
}
void sortcount(student stud[])
{
int i,j;
student temp;
student *p;
p=stud;
for(i=0;i for(j=0;j {
if(stud[j+1].index>stud[j].index)
{
temp=*(p+j);
*(p+j)=*(p+j+1);
*(p+j+1)=temp;
}
}
}
void sortcount2(student stud[])
{
int i,j;
student temp;
student *p;
p=stud;
for(i=0;i for(j=0;j {
if(stud[j].index>stud[j+1].index)
{
temp=*(p+j);
*(p+j)=*(p+j+1);
*(p+j+1)=temp;
}
}
}
#include"head.h"
void statistic(student stud[]) /*新增功能,输出统计信息*/
{
int i,j=0,k=0;
char c1,str[2];
float average[numsubs],sum=0;
if(numstus==0)
printf("没有可被查找的记录\n");
else
{
while(1)
{
printf("下面将统计考试成绩\n");
printf("请选择你要统计哪科的成绩 1.A\t2.B\t3.C\t4.D\t5.E\n");
c1=getchar();
printf("\t一共有个%d记录\n",numstus); /*总共记录数*/
switch(c1)
{
case '1':
for(i=0;i {
sum+=stud[i].subject[0];
if(stud[k].subject[0]>stud[i].subject[0]) k=i;
if(stud[j].subject[0] }
average[0]=sum/numstus;
printf("\t科目A的最高分:\n"); /*最高分*/
printf("\t\t学号:%s 姓名:%s 分数:%.2f\n",stud[j].number,stud[j].name,stud[j].subject[0]);
printf("\t科目A的最低分是:\n"); /*最低分*/
printf("\t\t学号:%s 姓名:%s 分数:%.2f\n",stud[k].number,stud[k].name,stud[k].subject[0]);
printf("\t科目A的平均分是 %5.2f\n",average[0]); /*平均分*/
break;
case '2':
for(i=0;i {
sum+=stud[i].subject[1];
if(stud[k].subject[1]>stud[i].subject[1]) k=i;
if(stud[j].subject[1] }
average[1]=sum/numstus;
printf("\t科目B的最高分:\n"); /*最高分*/
printf("\t\t学号:%s 姓名:%s 分数:%.2f\n",stud[j].number,stud[j].name,stud[j].subject[1]);
printf("\t科目B的最低分是:\n"); /*最低分*/
printf("\t\t学号:%s 姓名:%s 分数:%.2f\n",stud[k].number,stud[k].name,stud[k].subject[1]);
printf("\t科目B的平均分是 %5.2f\n",average[1]); /*平均分*/
break;
case '3':
for(i=0;i {
sum+=stud[i].subject[2];
if(stud[k].subject[2]>stud[i].subject[2]) k=i;
if(stud[j].subject[2] }
average[2]=sum/numstus;
printf("\t科目C的最高分:\n"); /*最高分*/
printf("\t\t学号:%s 姓名:%s 分数:%.2f\n",stud[j].number,stud[j].name,stud[j].subject[2]);
printf("\t科目C的最低分是:\n"); /*最低分*/
printf("\t\t学号:%s 姓名:%s 分数:%.2f\n",stud[k].number,stud[k].name,stud[k].subject[2]);
printf("\t科目C的平均分是 %5.2f\n",average[2]); /*平均分*/
break;
case '4':
for(i=0;i {
sum+=stud[i].subject[3];
if(stud[k].subject[3]>stud[i].subject[3]) k=i;
if(stud[j].subject[3] }
average[3]=sum/numstus;
printf("\t科目D的最高分:\n"); /*最高分*/
printf("\t\t学号:%s 姓名:%s 分数:%.2f\n",stud[j].number,stud[j].name,stud[j].subject[3]);
printf("\t科目D的最低分是:\n"); /*最低分*/
printf("\t\t学号:%s 姓名:%s 分数:%.2f\n",stud[k].number,stud[k].name,stud[k].subject[3]);
printf("\t科目D的平均分是 %5.2f\n",average[3]); /*平均分*/
break;
case '5':
for(i=0;i {
sum+=stud[i].subject[4];
if(stud[k].subject[4]>stud[i].subject[4]) k=i;
if(stud[j].subject[4] }
average[4]=sum/numstus;
printf("\t科目E的最高分:\n"); /*最高分*/
printf("\t\t学号:%s 姓名:%s 分数:%.2f\n",stud[j].number,stud[j].name,stud[j].subject[4]);
printf("\t科目E的最低分是:\n"); /*最低分*/
printf("\t\t学号:%s 姓名:%s 分数:%.2f\n",stud[k].number,stud[k].name,stud[k].subject[4]);
printf("\t科目E的平均分是 %5.2f\n",average[4]); /*平均分*/
break;
default:printf("输入错误!请输入1~5之间的数\n");
}
sum=0;
getchar();
printf("是否继续进行统计?(y/n)");
gets(str);
if(str[0]=='y'||str[0]=='Y') ;
else break;
}
}
}

#include"head.h"
int writetotext(student stud[]) /*将所有记录写入文件*/
{
int i=0,j;
FILE *fp;
char filename[20];
printf("输入文件名称:");
gets(filename);
fp=fopen(filename,"w");
fprintf(fp,"%d\n",numstus);
while(i {
fprintf(fp,"%s %s %s ",stud[i].number,stud[i].name,stud[i].sex);
for(j=0;j fprintf(fp,"%f ",stud[i].subject[j]);
fprintf(fp,"%f %f %d ",stud[i].score,stud[i].average,stud[i].index);
i++;
}
fclose(fp);
printf("已成功存储!\n");
display(stud,0,numstus-1);
numstus=0;
return 0;
}

#include"head.h"
void welcome()
{
printf("\t*************************************************************\n");
printf("\t\t\t\t这是一个学生成绩管理系统\n\t\t\t\t 倾情奉献 欢迎使用!\n");
printf("\t*************************************************************\n");

}

void showtable()
{
printf("---------------------------------------------------------------------------------------\n");
printf("学号\t姓名\t性别\tA\tB\tC\tD\tE\t总分\t平均分\t名次\n");
printf("---------------------------------------------------------------------------------------\n");
}

void display(student stud[],int n1,int n2)
{
int i;
showtable(); /*显示表头*/
for(i=n1;i<=n2;i++)
printf("%s\t%s\t%s\t%.2f\t%.2f\t%.2f\t%.2f\t%.2f\t%.2f\t%.2f\t%d\t\n",stud[i].number,stud[i].name,stud[i].sex,stud[i].subject[0],stud[i].subject[1],stud[i].subject[2],stud[i].subject[3],stud[i].subject[4],stud[i].score,stud[i].average,stud[i].index);
/*通过循环输出数据*/

}
void display1()
{
printf("\t\t本系统由计应精英一组亲情制作\n\n");
printf("\t\t制作人员列表: (按比划)\n");
printf("\t\t王庆斌\t\t\t张威\n\t\t李智\t\t\t周在峰\n\t\t杨凯\t\t\t胡杨\n");
printf("\n\n");
getchar();
}

#include"head.h"
#include
void amendrecord(student stud[])
{
char str[5]; /*供用户输入*/
int i=-1,j;

if(numstus==0) /*没有记录返回*/
printf("没有可供修改的记录!");
while(i<0)
{
i=findrecord(stud);
if(i>=0)
{
printf("要删除这个学生的信息吗?(y/n)");
gets(str);
if(str[0]=='y'||str[0]=='Y')
{
deleterecord(stud,i);
count(stud);
}
else
{
printf("确定要修改这个学生的信息吗?(y/n)");
gets(str);
if(str[0]=='y'||str[0]=='Y')
{

printf("下面请重新输入学生的信息:\n");
printf("请输入学号:");
gets(stud[i].number);
printf("请输入姓名:");
gets(stud[i].name);
printf("请输入性别(男/女 1/0):");
gets(str);
if(str[0]=='0')
strcpy(stud[i].sex,"女");
else
strcpy(stud[i].sex,"男");
stud[i].score=0;
printf("请按顺序输入成绩:");
for(j=0;j {
scanf("%f",&stud[i].subject[j]);
stud[i].score+=stud[i].subject[j];
}
getchar();
stud[i].average=stud[i].score/numsubs;
}
count(stud);
}
display(stud,0,numstus-1);
}
printf("是否继续进行其他修改?(y/n)\n");
gets(str);
if(str[0]=='y'||str[0]=='Y')
i=-1;
else i=1;
}
}

void deleterecord(student stu[],int i) /*删除信息*/
{
int j;

while(i>=0)
{
for(j=i;j stu[j]=stu[j+1];
numstus--;
printf("删除成功!\n");

}
}

void count(student stud[])
{
int i,j;
for(i=0;i {
stud[i].index=1;
for(j=0;j if(stud[j].score>stud[i].score)
stud[i].index++;
}
}

#include "head.h"
void addrecord(student stud[])
{
int i=0,j,num;
char str[5];
if(numstus!=0)
{
printf("已有记录存在是否覆盖?(y/n)\n");
gets(str);
if(str[0]=='Y'||str[0]=='y')
i=0;
else i=numstus;
}

printf("请输入增加的学生信息条目数:");
scanf("%d",&num);
if(i==0)
numstus=num;
else numstus+=num;
if(numstus>lens)
{
lens+=50;
pointer=(student *)realloc(pointer,lens*LEN);
}
printf("请输入学生信息:\n");
for(;i {
getchar();
printf("请输入学号:");
gets(pointer[i].number);
printf("请输入姓名:");
gets(pointer[i].name);
printf("请输入性别(男/女 1/0):");
gets(pointer[i].sex);
if(pointer[i].sex[0]=='0') strcpy(pointer[i].sex,"女");
else strcpy(pointer[i].sex,"男");
printf("请输入各科成绩:(按ABCDE的顺序):");
stud[i].score=0;
for(j=0;j {
scanf("%f",&stud[i].subject[j]); /*计算总分*/
stud[i].score+=stud[i].subject[j];
}
stud[i].average=stud[i].score/numsubs; /*计算平均分*/
}
count(stud); /*附名次*/
display(stud,0,numstus-1);
getchar();
}#include "head.h"
int numstus;
int lens;
student *pointer;
void main()
{
int i=1;
char str[2];
lens=100;
pointer=(student *)malloc(lens*LEN); /*分配内存*/
numstus=0;
welcome(); /*欢迎界面*/
while(i>0)
{
i=menu_select(); /*控制菜单*/
switch(i)
{
case 1:addrecord(pointer);break; /*增加学生信息*/
case 2:findrecord(pointer);break; /*查询学生信息*/
case 3:amendrecord(pointer);break; /*修改学生信息*/
case 4:sort(pointer);break; /*学生信息排序*/
case 5:statistic(pointer);break; /*统计信息*/
case 6:openfile(pointer);break; /*打开文件*/
case 7:writetotext(pointer);break; /*保存文件*/
case 8:display(pointer,0,numstus-1);break; /*显示记录*/
case 0:
if(numstus!=0) printf("是否保存当前记录?(y/n)");
gets(str);
if(str[0]=='y'||str[0]=='Y')
writetotext(pointer);
i=-1;break; /*退出系统*/
default:printf("请输入数字0~8:\n");i=1; /*输入错误*/
}
}
printf("\t\t欢迎再次使用本系统。\n\n");
display1();
}

自己一改就能用,给我加分哈!

回答3:

发过去了,我的地址是blackbat86@163.com

回答4:

分太少 看来没人帮了你

回答5:

晕 如果你的题目不是考试而是希望能够得到这个功能来应用的话,请使用EXCEL!

他能解决你的一切问题! 呵呵