求助 学生信息管理系统 不能执行
这个题目烦了我这个新手很长时间了 求高手指导现在的代码如下 求错误的地方
#include"stdio.h"
#include"malloc.h"
#include"stdlib.h"
#define LEN sizeof(struct student)
#define NULL 0
#define N 100
struct student//定义学生的基本信息的结构体
{
long num ;
char name[20];
char sex[4];
int sushe;
int phone;
};
struct chengji//定义学生的成绩的结构体
{
long num;
char bianhao[5];
char mingcheng[30];
int xuefen;
int pingshi;
int shiyan;
int juanmian;
float zonghe;
float sd_xuefen;
};
struct chengji *s2=NULL;
struct student *s1;
int count=0;//输入组数计数
void mainmenu();//主界面
void readdate();//读取文件里的内容
void writedate();//向文件写入信息
void display();//查询学生信息
void shxinxi();//查询学生基本信息
void shchengji();//查询学生成绩
void record();//记录数据
int main()
{
mainmenu();//显示主菜单
return 0;
}
void mainmenu()//主菜单
{
int choice;
choice=-1;
readdate();
do
{
system("cls");
printf("\n");
printf("\t\t------------欢迎使用此系统-----------\n");
printf("\n\n\n");
printf("\t\t+-----------------------------------+\n");
printf("\t\t| 学生信息管理系统 |\n");
printf("\t\t+-----------------------------------+\n");
printf("\t\t| [1]录入学生成绩 |\n");
printf("\t\t| [2]查询学生信息 |\n");
printf("\t\t| [3]删除学生信息 |\n");
printf("\t\t| [4]数据排序 |\n");
printf("\t\t| [0]退出系统 |\n");
printf("\t\t+-----------------------------------+\n");
printf("输入您的选择: ");
scanf("%d",&choice);
switch(choice)//输入不同功能编号调用相应函数来完成功能
{
case 0:
exit (0);
case 1:
record();
break;
case 2:
readdate();
display();
break;
case 3:
break;
case 4:
break;
default:
printf("\n无此选项!");
break;
}
}
while(choice!=0);
}
void record()//成绩输入
{
char ch;
struct chengji *p=s2;
do
{
if(count>N-1)
{
printf("超过100个。");
break;
}
system("cls");
printf("请输入学生的学号:");
scanf("%ld",&p[count].num);
printf("请输入课程编号:");
scanf("%s",p[count].bianhao);
printf("请输入课程名称:");
scanf("%d",&p[count].mingcheng);
printf("请输入学分:");
scanf("%d",&p[count].xuefen);
printf("请输入平时成绩:");
scanf("%d",&p[count].pingshi);
printf("请输入实验成绩:");
scanf("%d",&p[count].shiyan);
printf("请输入卷面成绩:");
scanf("%d",&p[count].juanmian);
if(p[count].shiyan==-1)
p[count].zonghe=p[count].pingshi*3/10+p[count].juanmian*7/10;
else
p[count].zonghe=p[count].pingshi*15/100+p[count].juanmian*7/10+p[count].shiyan*15/100;
if(p[count].zonghe=90)
p[count].sd_xuefen=p[count].xuefen;
else if(p[count].sd_xuefen>=80)
p[count].sd_xuefen=p[count].xuefen*0.8;
else if(p[count].sd_xuefen>=70)
p[count].sd_xuefen=p[count].xuefen*0.75;
else if(p[count].sd_xuefen>=60)
p[count].sd_xuefen=p[count].xuefen*0.6;
else
p[count].sd_xuefen=0;
count++;
printf("是否继续(N/Y)\n");
ch=getchar();
}while(ch=='Y'||ch=='y');
writedate();
}
void writedate()
{
int i;
struct chengji *p=s2;
FILE *fp;
fp=fopen("chengji","w");
if(!fp)
{
printf("文件打开错误。");
return;
}
for(i=0;i<=count;i++)
{
fprintf(fp,"%ld\t%s\t%s\t%d\t%d\t%d\t%d\t%f\t%f",p[count].num,p[count].bianhao,p[count].mingcheng,p[count].xuefen,p[count].pingshi,p[count].shiyan,p[count].zonghe,p[count].sd_xuefen);
}
fclose(fp);
return ;
}
void readdate()
{
FILE *fp1,*fp2;
struct student *p1=s1;
struct chengji *p2=s2;
if((fp1=fopen("student","rb"))=NULL)
{
printf("文件打不开\n");
return;
}
else
{
fread(p1,sizeof(student),N,fp1);
}
if((fp2=fopen("chengji","rb"))=NULL)
{
printf("文件打不开\n");
return;
}
else
{
fread(&count, sizeof(int), 1, fp2);
fread(p2, sizeof(chengji), count, fp2);
}
fclose(fp1);
fclose(fp2);
}
void display()
{
system("cls");
int a;
printf("选择要查询的内容:\n1 学生基本信息\n2 学生成绩\n");
scanf("&d",&a);
if(a==1)
shxinxi();
else if(a==2)
shchengji();
else
printf("请输入正确的值。");
}
void shxinxi()
{
long n;
struct student *p1;
printf("请输入学号或宿舍号:\t");
scanf("%ld",&n);
p1=s1;
while(p1=NULL)
{
if(p1->num==n||p1->sushe==n)
printf("%d\t%s\t%s\t%d\t%d",p1->num,p1->name,p1->sex,p1->sushe,p1->phone);
}
}
void shchengji()
{
long n,i=0;float sum=0;
struct chengji *p2;
struct student *p1;
p1=s1;
p2=s2;
printf("请输入学号;\t");
scanf("%ld",&n);
while(p1->num==n)
p1++;
printf("学 号:%d\t",n);
printf("姓 名:%s\n",p1->name);
while(p2=NULL)
{
if(p2->num==n)
{
printf("课程编号:%s\t课程名称:%s\t综合成绩:%d\t实得学分:%d\n",p2->bianhao,p2->mingcheng,p2->zonghe,p2->sd_xuefen);
i++;
sum=p2->sd_xuefen+sum;
}
p2++;
}
printf("共修:%d科,实得总学分为:%d\n",i,sum);
}
[ 本帖最后由 qrjw123 于 2011-6-7 12:28 编辑 ]