请详细点啊 谢谢啊
这是关于学生成绩管理
输入学生成绩 输出最低分 最高分 平均分 及一定分数段的所占的比例.. 一定详细啊
#include
#include
#include
#define NULL 0
#define SIZE sizeof(struct student)
struct student
{
int num;
char name[10];
int age;
char addr[15];
float score[3];
float zf,pjf;
struct student *next;
};
struct student *head=NULL,*tail=NULL;
int n=0;
void load();
void save();
void add();
void input(struct student *p);
void list();
void main()
{ int ch;
int loop=1;
while(loop)
{
printf("\n\n");
printf("========== main menu ============\n");
printf(" 1---load\n");
printf(" 2---save\n");
printf(" 3---add\n");
printf(" 4---insert\n");
printf(" 5---delete\n");
printf(" 6---update\n");
printf(" 7---locate\n");
printf(" 8---list\n");
printf(" 9---calc\n");
printf(" 10---sort\n");
printf(" 11---tj\n");
printf(" 0---quit\n");
printf("=================================\n");
printf("input your choice:");
scanf("%d",&ch); getchar();
switch(ch)
{
case 1:
load();
break;
case 2:
save();
break;
case 3:
add();
break;
case 4:
case 5:
case 6:
case 7:
case 8:
list();
break;
case 9:
case 10:
case 0:
loop=0;
break;
default:
printf("input choice error!");
}
}
}
void load()
{
FILE *fp;
struct student *p1,*p2;
int i;
if ((fp=fopen("stu.dat","rb"))==NULL)
{
printf("cannot open file!\n");
return;
}
p2=tail;
while(1)
{
p1=(struct student *)malloc(SIZE);
if (p1==NULL)
{
printf("malloc failed!\n");
break;
}
if (fread(p1,SIZE,1,fp)!=1)
break;
n++;
if (n==1)
head=p1;
else
p2->next=p1;
p2=p1;
}
fclose(fp);
p2->next=NULL;
tail=p2;
}
void save()
{
FILE *fp;
struct student *p;
if ((fp=fopen("stu.dat","wb"))==NULL)
{
printf("cannot open file!\n");
return;
}
p=head;
while(p!=NULL)
{
if (fwrite(p,SIZE,1,fp)!=1)
{
printf("file write error!\n");
break;
}
p=p->next;
}
fclose(fp);
}
void add()
{
struct student *p1,*p2;
int i;
p2=tail;
p1=(struct student *)malloc(SIZE);
if (p1==NULL)
{
printf("malloc failed!\n");
return;
}
input(p1);
while(p1->num!=0)
{
n++;
if (n==1)
head=p1;
else
p2->next=p1;
p2=p1;
p1=(struct student *)malloc(SIZE);
input(p1);
}
p2->next=NULL;
tail=p2;
}
void input(struct student *p)
{
int i;
printf("\n");
printf("num: "); scanf("%d",&p->num); getchar();
if (p->num==0)
return;
printf("name: "); gets(p->name);
printf("age: "); scanf("%d",&p->age); getchar();
printf("addr: "); gets(p->addr);
printf("three scores: ");
for(i=0;i<3;i++)
scanf("%f",&(p->score[i]));
p->zf=0;
p->pjf=0;
}
void list()
{
struct student *p;
int i;
p=head;
i=1;
printf(" mnameageaddrywsxyyzfpjf\n"); printf("----------------------------------------------------------------------\n");
while (p!=NULL)
{
printf("%2d %5d %-10s %3d %-10s %7.2f %7.2f %7.2f %7.2f %7.2f\n",i,p->num,p->name,
p->age,p->addr,p->score[0],p->score[1],p->score[2],
p->zf,p->pjf);
p=p->next;
i++;
}
}
#26;
#include
#include
#include
#define NULL 0 /*定义常量*/
#define SIZE sizeof(struct student) /*定义SIZE sizeof函数*/
struct student
{
int num;
char name[10];
int age;
char addr[15];
float score[3];
float zf,pjf;
struct student *next;
}; /*构造student的数据类型*/
struct student *head=NULL,*tail=NULL;
/*定义开头,结尾数值...全部
#include
#include
#include
#define NULL 0 /*定义常量*/
#define SIZE sizeof(struct student) /*定义SIZE sizeof函数*/
struct student
{
int num;
char name[10];
int age;
char addr[15];
float score[3];
float zf,pjf;
struct student *next;
}; /*构造student的数据类型*/
struct student *head=NULL,*tail=NULL;
/*定义开头,结尾数值为空*/
int n=0;
void load();
void save();
void add();
void input(struct student *p);
void list();
/*调用一大串函数load*/
void main()
{ int ch;
int loop=1;
while(loop)
{
printf("\n\n");
printf("========== main menu ============\n");
printf(" 1---load\n");
printf(" 2---save\n");
printf(" 3---add\n");
printf(" 4---insert\n");
printf(" 5---delete\n");
printf(" 6---update\n");
printf(" 7---locate\n");
printf(" 8---list\n");
printf(" 9---calc\n");
printf(" 10---sort\n");
printf(" 11---tj\n");
printf(" 0---quit\n");
printf("=================================\n");
/*打印主菜单*/
printf("input your choice:"); /*提示输入操作*/
scanf("%d",&ch); getchar(); /*读取输入命令*/
switch(ch)
{
case 1:
load();
break;
case 2:
save();
break;
case 3:
add();
break;
case 4:
case 5:
case 6:
case 7:
case 8:
list();
break;
case 9:
case 10:
case 0:
loop=0;
break;
default: /*switch语句做判断*/
printf("input choice error!");
} /*提示错误*/
}
}
void load() /*load函数*/
{
FILE *fp;
struct student *p1,*p2;
int i; /*定义文件以及文件指针*/
if ((fp=fopen("stu。
dat","rb"))==NULL)
{
printf("cannot open file!\n");
return;
}
p2=tail;
while(1)
{
p1=(struct student *)malloc(SIZE);
if (p1==NULL)
{
printf("malloc failed!\n");
break;
}
if (fread(p1,SIZE,1,fp)!=1)
break;
n++;
if (n==1)
head=p1;
else
p2->next=p1;
p2=p1;
}
fclose(fp);
p2->next=NULL;
tail=p2;
}
void save()
{
FILE *fp;
struct student *p;
if ((fp=fopen("stu。
dat","wb"))==NULL)
{
printf("cannot open file!\n");
return;
}
p=head;
while(p!=NULL)
{
if (fwrite(p,SIZE,1,fp)!=1)
{
printf("file write error!\n");
break;
}
p=p->next;
}
fclose(fp);
}
void add()
{
struct student *p1,*p2;
int i;
p2=tail;
p1=(struct student *)malloc(SIZE);
if (p1==NULL)
{
printf("malloc failed!\n");
return;
}
input(p1);
while(p1->num!=0)
{
n++;
if (n==1)
head=p1;
else
p2->next=p1;
p2=p1; /*将指针p1的指向赋给p2*/
p1=(struct student *)malloc(SIZE);
input(p1); /*定义p1的指向*/
}
p2->next=NULL;
tail=p2; /*文件尾部指向p2*/
}
void input(struct student *p)
{
int i;
printf("\n");
printf("num: "); scanf("%d",&p->num); getchar();
if (p->num==0)
return;
printf("name: "); gets(p->name);
printf("age: "); scanf("%d",&p->age); getchar();
printf("addr: "); gets(p->addr);
printf("three scores: ");
for(i=0;iscore[i]));
p->zf=0;
p->pjf=0;
}
void list()
{
struct student *p; /*指针指向 student*/
int i;
p=head; /*指针指向文件开头 */
i=1;
printf(" mnameageaddrywsxyyzfpjf\n");printf("----------------------------------------------------------------------\n");
while (p!=NULL)
{
printf("%2d %5d %-10s %3d %-10s %7。
2f %7。2f %7。2f %7。2f %7。
2f\n",i,p->num,p->name,
p->age,p->addr,p->score[0],p->score[1],p->score[2],
p->zf,p->pjf);
/*输出文件中对应的学号,姓名,年龄,地址,最低分 ,最高分 ,平均分*/
p=p->next;
i++;
}
}
。收起