求剩余部分
除了查询功能 其他的一模一样 给分后 其他隐藏的才能够显示
#include
#include
#include
#include
struct student_info
{ char number[15]; /*学号*/
char name[20]; /*姓名*/
char gender[8]; /*性别*/
char sushe_no[10]; /*宿舍号*/
char tel[20];
};
struct student_grade
{
char number[15];
char courseno[10]; /*课程号*/
char coursename[20]; /*课程名称*/
int xuefen;
int pingshicj;
int shiyancj;
int juanmiancj;
float zonghecj;
float shidecj;
};
typedef struct student_info stu_info;
typedef struct student_grade stu_grade;
int CourseInfoIndex=0;
int StudentInfoIndex=0;
stu_info *StuInfo=NULL;
stu_grade *StuCour=NULL;
int ReadStuInfo(void) //从原有的学生信息文件中读取信息
{
FILE *fp;
StudentInfoIndex=0;
if((fp=fopen("a.txt","rb"))==NULL)
{
return -1;
}
else
{
while(!feof(fp))
{
if(fread(&StuInfo[StudentInfoIndex],sizeof(stu_info),1,fp)==1)
{
StudentInfoIndex++;
}
}
fclose(fp);
return 0;
}
}
int WriteStuInfo(void) //将学生信息写入到文件中
{
FILE *fp;
if(StudentInfoIndex>=0)
{
if((fp=fopen("a.txt","wb"))==NULL)
{
return -1;
}
else
{
fwrite(StuInfo,sizeof(stu_info)*StudentInfoIndex,1,fp);
fclose(fp);
return 0;
}
}
return 0;
}
void PrintStuInfo(int index)
{
int i=0;
ReadStuInfo();
printf("\nNow print the data of student infomation:\n");
printf("StuNO StuName Gender SuSheHao Telphone\n");
if (index==-1)
{
for(i=0;i<=StudentInfoIndex-1;i++)
{
printf("%s ",StuInfo[i].number);
printf("%s ",StuInfo[i].name);
printf("%s ",StuInfo[i].gender);
printf("%s ",StuInfo[i].sushe_no);
printf("%s\n",StuInfo[i].tel);
}
}
else
{
printf("%s ",StuInfo[index].number);
printf("%s ",StuInfo[index].name);
printf("%s ",StuInfo[index].gender);
printf("%s ",StuInfo[index].sushe_no);
printf("%s\n",StuInfo[index].tel);
}
}
void InStuInfo(void) //添加学生信息
{
int t=0;
char str[20];
ReadStuInfo();
//PrintStuInfo(-1); //测试代码,打印学生信息
printf("Now you will input some new student infomation records,\n end with a * for begin of a record.\n");
while(str[0]!='*')
{
t++;
printf("-------------------------------------\n");
printf("Now Please input the %dth record:\n",t);
printf(" Student no:");
gets(str);
if(str[0]=='*')
{
continue;
} //如果碰到结束标志
strcpy(StuInfo[StudentInfoIndex].number,str);
printf("\n Student name:");
gets(StuInfo[StudentInfoIndex].name);
printf("\n Student gender:");
gets(StuInfo[StudentInfoIndex].gender);
printf("\n sushe_no:");
gets(StuInfo[StudentInfoIndex].sushe_no);
printf("\n tel:");
gets(StuInfo[StudentInfoIndex].tel);
StudentInfoIndex++;
}
WriteStuInfo();
}
int ReadCourseInfo(void) //从原有的学生成绩信息文件中读取信息
{
FILE *fp;
CourseInfoIndex=0;
if((fp=fopen("b.txt","rb"))==NULL)
{
return -1;
}
else
{
while(!feof(fp))
{
if(fread(&StuCour[CourseInfoIndex],sizeof(stu_grade),1,fp)==1)
{
CourseInfoIndex++;
}
}
fclose(fp);
return 0;
}
}
int WriteCourseInfo(void) //将成绩信息写入到文件中
{
FILE *fp;
if(CourseInfoIndex>=0)
{
if((fp=fopen("b.txt","wb"))==NULL)
{
return -1;
}
else
{
fwrite(StuCour,sizeof(stu_grade)*CourseInfoIndex,1,fp);
fclose(fp);
return 0;
}
}
return 0;
}
void PrintCourseInfo(int index)
{
int i=0;
ReadCourseInfo();
printf("\nNow print the data of course infomation:\n");
printf("StuNO CourseNo CourseName XueFen PingShiCJ ShiYanCJ JuanMianCJ ZongHeCJ ShiDeCJ\n");
if (index==-1)
{
for(i=0;i<=CourseInfoIndex-1;i++)
{
printf("%s ",StuCour[i].number);
printf("%s ",StuCour[i].courseno);
printf("%s ",StuCour[i].coursename);
printf("%d ",StuCour[i].xuefen);
printf("%d ",StuCour[i].pingshicj);
printf("%d ",StuCour[i].shiyancj);
printf("%d ",StuCour[i].juanmiancj);
printf("%f ",StuCour[i].zonghecj);
printf("%f\n",StuCour[i].shidecj);
}
}
else
{
printf("%s ",StuCour[index].number);
printf("%s ",StuCour[index].courseno);
printf("%s ",StuCour[index].coursename);
printf("%d ",StuCour[index].xuefen);
printf("%d ",StuCour[index].pingshicj);
printf("%d ",StuCour[index].shiyancj);
printf("%d ",StuCour[index].juanmiancj);
printf("%f ",StuCour[index].zonghecj);
printf("%f\n",StuCour[index].shidecj);
}
}
void InStuCourseInfo(void) //输入新的学生成绩信息
{
int t=0;
char str[20];
ReadCourseInfo(); //先把原先文件中存在的记录读到内存中
// PrintCourseInfo(-1); //测试代码过程
printf("Now you will input some new student course records,\n end with a * for begin of a record.\n");
while(str[0]!='*')
{
t++;
printf("-------------------------------------\n");
printf("Now Please input the %dth record:\n",t);
printf(" Student no:");
gets(str);
if(str[0]=='*')
{
//if(CourseInfoIndex!=0) CourseInfoIndex--;
continue;
} //如果碰到结束标志
strcpy(StuCour[CourseInfoIndex].number,str);
printf("\n Course no:");
gets(StuCour[CourseInfoIndex].courseno);
printf("\n Course name:");
gets(StuCour[CourseInfoIndex].coursename);
printf("\n XueFen:");
gets(str);
StuCour[CourseInfoIndex].xuefen=(int)atof(str);
printf("\n PingShiChengJi:");
gets(str);
StuCour[CourseInfoIndex].pingshicj=(int)atof(str);
printf("\n ShiYanChengJi:");
gets(str);
StuCour[CourseInfoIndex].shiyancj=(int)atof(str);
printf("\n JuanMianChengJi:");
gets(str);
StuCour[CourseInfoIndex].juanmiancj=(int)atof(str);
//下面计算综合成绩和实得成绩
if(StuCour[CourseInfoIndex].shiyancj==-1)
{
StuCour[CourseInfoIndex].zonghecj=StuCour[CourseInfoIndex].pingshicj*0.3+StuCour[CourseInfoIndex].juanmiancj*0.7;
}
else
{
StuCour[CourseInfoIndex].zonghecj=StuCour[CourseInfoIndex].shiyancj*0.15+StuCour[CourseInfoIndex].pingshicj*0.15+StuCour[CourseInfoIndex].juanmiancj*0.7;
}
if(StuCour[CourseInfoIndex].zonghecj>=90)
{
StuCour[CourseInfoIndex].shidecj=StuCour[CourseInfoIndex].xuefen*1.0;
}
else
{
if(StuCour[CourseInfoIndex].zonghecj>=70)
{
StuCour[CourseInfoIndex].shidecj=StuCour[CourseInfoIndex].xuefen*0.8;
}
else
{
if(StuCour[CourseInfoIndex].zonghecj>=60)
{
StuCour[CourseInfoIndex].shidecj=StuCour[CourseInfoIndex].xuefen*0.6;
}
else
{
StuCour[CourseInfoIndex].shidecj=0.0;
}
}
}
CourseInfoIndex++;
}
WriteCourseInfo();// 保存到文件中
}
/* 将src指向的一条记录复制给dest指向的记录 */
void CopyStuInfo(stu_info *src,stu_info *dest)
{
int j;
strcpy(dest->number,src->number);
strcpy(dest->name,src->name);
strcpy(dest->gender,src->gender);
strcpy(dest->sushe_no,src->sushe_no);
strcpy(dest->tel,src->tel);
}
void Del(void)
{
char strdel[15];
int p=0;
int flag=0;
int t=StudentInfoIndex;
printf("Delete a student infomation record:\n");
ReadCourseInfo();
ReadStuInfo();
PrintStuInfo(-1); //打印学生信息
printf("Please input the student number which you will delete:");
gets(strdel);
while(p<=t && flag==0)
{
if(strcmp(strdel,StuInfo[p].number)==0)
{
flag=1; //找到该学号的记录
CopyStuInfo(&StuInfo[t-1],&StuInfo[p]); //将最后一个记录覆盖当前记录,如果找到的是最后一个记录,则直接丢失
t--;
StudentInfoIndex--;
}
else
{
p++;
}
}
if(flag==1) //如果删除了a文件的记录,则应相应的删除b文件的记录
{
p=0;
t=CourseInfoIndex;
while(p<=t && CourseInfoIndex>=0 )
{
if(strcmp(strdel,StuCour[p].number)==0)
{
CopyStuInfo(&StuCour[CourseInfoIndex-1],&StuCour[p]);
CourseInfoIndex--;
t--;
}
else
{
p++;
}
}
}
WriteStuInfo();
WriteCourseInfo();
PrintStuInfo(-1);
PrintCourseInfo(-1);
}
/* 将src指向的一条记录复制给dest指向的记录 */
void CopyCourseInfo(stu_grade *src,stu_grade *dest)
{
int j;
strcpy(dest->number,src->number);
strcpy(dest->courseno,src->courseno);
strcpy(dest->coursename,src->coursename);
dest->xuefen=src->xuefen;
dest->pingshicj=src->pingshicj;
dest->juanmiancj=src->juanmiancj;
dest->zonghecj=src->zonghecj;
dest->shidecj=src->shidecj;
}
void SortInfo(void)
{
char str[5];
int i,j;
stu_grade tmps;
printf("Pease select a sorting way:\n");
printf("1.with zonghecj in inc order\n");
printf("2.with zonghecj in desc order\n");
printf("3.with shidecj in inc order\n");
printf("4.with shidecj in desc order\n");
gets(str);
ReadCourseInfo();//读取文件的信息
if(str[0]<'1'||str[0]>'4') return; /*进行排序*/
for(i=0;i<=CourseInfoIndex-2;i++)
{
for(j=i+1;j<=CourseInfoIndex-1;j++)
{
if((str[0]=='1' && StuCour[i].zonghecj>StuCour[j].zonghecj)||
(str[0]=='2' && StuCour[i].zonghecj
(str[0]=='4' && StuCour[i].shidecj
CopyCourseInfo(&StuCour[i],&tmps);
CopyCourseInfo(&StuCour[j],&StuCour[i]);
CopyCourseInfo(&tmps,&StuCour[j]);
}
}
}
WriteCourseInfo(); //将排序好的写入到文件中
PrintCourseInfo(-1); //显示信息
}
void ShowMenu(void)
{
char select[5];
printf("\n\n\nPlease Select a operate:\n");
printf("1.Insert some student information records;\n");
printf("2.Insert some student course records;\n");
printf("3.Delete a record from student information file;\n");
printf("4.Sort student course records;\n");
printf("5.Print student information records;\n");
printf("6.Print student course records;\n");
printf("0.exit\n");
gets(select);
while(select[0]!='0')
{
if(select[0]=='1') InStuInfo();
if(select[0]=='2') InStuCourseInfo();
if(select[0]=='3') Del();
if(select[0]=='4') SortInfo();
if(select[0]=='5') PrintStuInfo(-1);
if(select[0]=='6') PrintCourseInfo(-1);
printf("\n\n\nPlease Select an operater:\n");
printf("1.Insert some student information records;\n");
printf("2.Insert some student course records;\n");
printf("3.Delete a record from student information file;\n");
printf("4.Sort student course records;\n");
printf("5.Print student information records;\n");
。。
。。。此部分被隐藏
}