这是自己我编出的程序
但是 后面真的不清楚
怎么将其他条件加入进去#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define
SIZE
100
struct stud_type
{
char bh[10];
char name[20];
char xb[2];
int
nl;
int
sx;
int
yy;
int
wy;
int
cyy;
int
jsj;
int
zcj;
int
pjcj;
};
struct stud_type
arrange,student[SIZE];
FILE *fp;
char numstr[20];
int
n=0;
void menu();
//菜单
void shuru();
//输入
void shuchu();
//输出
void chazhao();
//查找
void xiugai();
//修改
void charu();
//插入
void shanchu();
//删除
void tongji();
//统计
void paixu();
//排序
void tianjia();
//添加
int main()
{
menu();
//调用菜单
}
void menu()
{
char choice;
int k=1;
while(k)
{
system("cls");
printf("\n");
printf("\t
---------------------------------------------------------\n");
printf("\t
||
~~~~~~~~~********学生成绩管理系统********~~~~~~~~
||\n");
printf("\t
=========================================================\n");
printf("\t
||
||\n");
printf("\t
||
1. 输入信息
2. 输出信息
||\n");
printf("\t
||
||\n");
printf("\t
||
3. 查找信息
4. 修改信息
||\n");
printf("\t
||
||\n");
printf("\t
||
5. 插入信息
6. 删除信息
||\n");
printf("\t
||
||\n");
printf("\t
||
7. 统计、处理
8. 筛选排序
||\n");
printf("\t
||
||\n");
printf("\t
||
9. 添加信息
0. 退出系统
||\n");
printf("\t
||
||\n");
printf("\t
=========================================================\n");
printf("\t
|
请选择以上项目:
|\n");
printf("\t
---------------------------------------------------------\n");
choice=getchar();getchar();
switch(choice)
{
case'1':shuru(); break;
case'2':shuchu(); break;
case'3':chazhao(); break;
case'4':xiugai(); break;
case'5':charu(); break;
case'6':shanchu(); break;
case'7':tongji(); break;
case'8':paixu(); break;
case'9':tianjia(); break;
case'0':k=0;
}
}
}
void shuru()//输入信息
{
int a,b;
char ch;
int n;
if((fp=fopen("xuesheng.txt","wb"))==NULL)
{
printf("不能打开 xuesheng.txt");
exit(0);
}
system("cls");
printf("\t\t\t请输入学生信息\n");
for(n=0;n<=SIZE;)
{
printf(" 请输入学号:",n+1);
gets(student[n].bh);
printf(" 请输入姓名:",n+1);
gets(student[n].name);
printf(" 请输入性别:",n+1);
gets(student[n].xb);
printf("请输入数学成绩:");
gets(numstr);
student[n].sx=atof(numstr);
printf("请输入外语成绩:");
gets(numstr);
student[n].yy=atof(numstr);
printf("请输入网页成绩:");
gets(numstr);
student[n].wy=atof(numstr);
printf("请输入c语言成绩:");
gets(numstr);
student[n].cyy=atof(numstr);
printf("请输入计算机基础成绩:");
gets(numstr);
student[n].jsj=atof(numstr);
a=1.0*(student[n].sx+student[n].yy+student[n].wy+student[n].cyy+student[n].jsj)/4;
student[n].pjcj=a;
b=(student[n].sx+student[n].yy+student[n].wy+student[n].cyy+student[n].jsj);
student[n].zcj=b;
n++;
printf("是否继续输入(y/n)\n");
ch=getchar();getchar();
if(ch=='n')
break;
}
fwrite(student,sizeof(student[0]),n,fp);
fclose(fp);
}
void shuchu()//输出信息
{
n=0;
if((fp=fopen("xuesheng.txt","rb"))==NULL)
{
printf("不能打开 xuesheng.txt");
exit(0);
}
system("cls");
printf("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n");
printf("学号
姓名
性别
数学
外语
网页
c语言
计算机 平均成绩
总成绩 \n");
printf("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n");
while(fread(&student[n],sizeof(student[n]),1,fp)==1)
{
printf("%-7s%-7s%-7s%-7d%-7d%-7d%-7d%-12.2d%-10d\n",
student[n].bh,student[n].name,student[n].xb,
student[n].sx,student[n].yy,student[n].wy,
student[n].cyy,student[n].jsj, student[n].pjcj,student[n].zcj);
n++;
}
getchar();getchar();
fclose(fp);
}
void chazhao()//查找信息
{
int a=0,b,c; char cz; n=0;
if((fp=fopen("xuesheng.txt","rb"))==NULL)
{
printf("不能打开文件\n ");
exit(0);
}
while(fread(&student[n],sizeof(student[n]),1,fp)==1)
n++;
a=n;
printf("\t\t
---------------------------\n");
printf("\t\t
|| ********查询********* ||\n");
printf("\t\t
===========================\n");
printf("\t\t
||
||\n");
printf("\t\t
||
1. 按学号查询
||\n");
printf("\t\t
||
||\n");
printf("\t\t
||
2. 按姓名查询
||\n");
printf("\t\t
||
||\n");
printf("\t\t
||
3. 按总成绩查询
||\n");
printf("\t\t
||
||\n");
printf("\t\t
===========================\n");
printf("\t\t
按其它数字键退出
\n");
cz=getchar();getchar();
switch(cz)
{
case '1':
printf(" 请输入您要查找的学号:\n");
gets(numstr);
for(n=0;n<a;)
{
if(!strcmp(numstr,student[n].bh)) break;
n++;
}
break;
case '2':
printf("请输入您要查找的姓名\n");
gets(numstr);
for(n=0;n<a;)
{
if(!strcmp(numstr,student[n].name)) break;
n++;
}
break;
case '3':
printf("请输入您要查找的总成绩\n");
gets(numstr);
for(n=0;n<a;)
{
if(atol(numstr)==student[n].zcj) break;
n++;
}
break;
}
printf("--\n");
printf("%-7s%-7s%-7s%-7d%-7d%-7d%-7d%-12.2d%-10d\n",
student[n].bh,student[n].name,student[n].xb,
student[n].sx,student[n].yy,student[n].wy,student[n].cyy,student[n].jsj,
student[n].pjcj,student[n].zcj);
getchar();getchar();
fclose(fp);
}
void xiugai()//修改信息
{
char xg;int i=0;
printf("如果你想修改必须先找到文件\n");
chazhao();
if((fp=fopen("xuesheng.txt","rb+"))==NULL)
{
printf("can not open the file.\n ");
exit(0);
}
while(fread(&student[i],sizeof(student[i]),1,fp)==1)
i++;
printf("
请选择您要修改的内容:
\n");
printf(" ============================ \n");
printf("||
学
号
请按 1 ||\n");
printf("||
姓
名
请按 2 ||\n");
printf("||
性
别
请按 3 ||\n");
printf("||
数
学
请按 4 ||\n");
printf("||
外
语
请按 5 ||\n");
printf("||
网
页
请按 6 ||\n");
printf("||
C 语言
请按 7 ||\n");
printf("||
计算机
请按 8 ||\n");
printf("||
退
出
请按 0 ||\n");
printf("+===========================+\n");
printf("请输入您的选择:");
xg=getchar();getchar();
switch(xg)
{
case '0':break;
case '1':
printf("请输入要修改的学号:");
gets(student[n].bh);
printf("%s\n",student[n].bh);
break;
case '2':
printf("请输入要修改的姓名:");
gets(student[n].name);
break;
case '3':
printf("请输入要修改的性别:");
gets(student[n].xb);
break;
case '4':
printf("请输入要修改的数学分数:");
gets(numstr);
student[n].sx=atoi(numstr);
break;
case '5':
printf("请输入要修改的外语语分数:");
gets(numstr);
student[n].yy=atoi(numstr);
break;
case '6':
printf("请输入要修改的网页分数:");
gets(numstr);
student[n].wy=atoi(numstr);
break;
case '7':
printf("请输入要修改的c语言分数:");
gets(numstr);
student[n].cyy=atoi(numstr);
break;
case '8':
printf("请输入要修改的计算机分数:");
gets(numstr);
student[n].jsj=atoi(numstr);
break;
default:
break;
}
printf("%-7s%-7s%-7s%-7d%-7d%-7d%-7d\n",
student[n].bh,student[n].name,student[n].xb,
student[n].sx,student[n].yy,
student[n].wy,student[n].cyy,
student[n].jsj);
rewind(fp);
fwrite(student,sizeof(student[0]),i,fp);
getchar();getchar();
fclose(fp);
}
void charu()//插入信息
{
int i=0, a=0;
printf("如果你想插入一条记录. ");
printf("请在插入之前查找记录.\n");
chazhao();
if((fp=fopen("xuesheng.txt","rb+"))==NULL)
{
printf("不能打开 xuesheng.txt");
exit(0);
}
while (fread(&student[i],sizeof(student[0]),1,fp)==1)
i++;
a=i;
for(i=a-1;i>n-1;i--)
student[i+1]=student[i];
printf("请输入插入的学号:");
gets(student[n].bh);
printf("请输入插入的姓名:");
gets(student[n].name);
printf("请输入插入的性别:");
gets(student[n].xb);
printf("请输入插入的数学成绩:");
gets(numstr);
student[n].sx=atof(numstr);
printf("请输入插入的外语成绩:");
gets(numstr);
student[n].yy=atof(numstr);
printf("请输入插入的网页成绩:");
gets(numstr);
student[n].wy=atof(numstr);
printf("请输入插入的c语言成绩:");
gets(numstr);
student[n].cyy=atof(numstr);
printf("请输入插入的计算机成绩:");
gets(numstr);
student[n].sx=atof(numstr);
rewind(fp);
fwrite(student,sizeof(student[0]),a+1,fp);
getchar();getchar();
fclose(fp);
}
void shanchu()// 删除信息
{
int i=0, a=0;
printf("如果你想删除信息** 必须先找到.\n");
chazhao();
if((fp=fopen("xuesheng.txt","rb+"))==NULL)
{
printf("不能打开 xuesheng.txt");
exit(0);
}
while (fread(&student[n],sizeof(student[0]),1,fp)==1)
i++;
a=i;
for(i=n;i<a;i++)
student[n]=student[i+1];
fp=fopen("xuesheng.txt","wb");
printf("删除记录成功!");
fwrite(student,sizeof(student[0]),a-1,fp);
getchar();getchar();
fclose(fp);
}
void tongji()//统计、处理
{
int i=0;int a=0;double sum=0;char tj;
if((fp=fopen("xuesheng.txt","rb"))==NULL)
{
printf("不能打开 xuesheng.txt");
exit(0);
}
while (fread(&student[n],sizeof(student[0]),1,fp)==1)
i++;
a=i;
printf("\t\t
----------------------------\n");
printf("\t\t
|| ********统计********* ||\n");
printf("\t\t
===========================\n");
printf("\t\t
||
||\n");
printf("\t\t
||
你想统计哪科成绩:
||\n");
printf("\t\t
||
1:平均成绩
||\n");
printf("\t\t
||
1:总成绩
||\n");
printf("\t\t
||
||\n");
printf("\t\t
===========================\n");
tj=getchar();getchar();
switch(tj)
{
case '1':
printf("如果想统计,请先寻找.\n");
chazhao();
sum=student[n].sx+student[n].yy+student[n].wy+student[n].cyy+student[n].jsj;
printf("%s 平均成绩是 %f",student[n].name,sum/4);
break;
case '2':
printf("如果想统计,请先寻找.\n");
chazhao();
sum=student[n].sx+student[n].yy+student[n].wy+student[n].cyy+student[n].jsj;
printf("%s总成绩是 %f\n",student[n].name,sum);
break;
}
getchar();getchar();
fclose(fp);
}
void paixu()//筛选排序
{
char px;
int i=0, a=0,m=0,k=0;
if((fp=fopen("xuesheng.txt","rb+"))==NULL)
{
printf("不能打开 xuesheng.txt");
exit(0);
}
while (fread(&student[n],sizeof(student[0]),1,fp)==1)
i++;
a=i;
printf("你想用什么方式排序?\n");
printf("1.学号 2.成绩\n");
px=getchar();getchar();
switch(px)
{
case '1':
for(i=0;i<a-1;i++)
for(k=i+1;k<a;k++)
if(student[i].bh>student[k].bh)
{
arrange=student[k];
student[k]=student[i];
student[i]=arrange;
}
break;
case '2':
printf("1.数学 2.外语 3.网页 4.c语言 5.计算机\n");
px=getchar();getchar();
switch(px)
{
case '1':
for(i=0;i<a-1;i++)
for(k=i+1;k<a;k++)
if(student[i].sx>student[k].sx)
{
arrange=student[k];
student[k]=student[i];
student[i]=arrange;
}
break;
case '2':
for(i=0;i<a-1;i++)
for(k=i+1;k<a;k++)
if(student[i].yy>student[k].yy)
{
arrange=student[k];
student[k]=student[i];
student[i]=arrange;
}
break;
case '3':
for(i=0;i<a-1;i++)
for(k=i+1;k<a;k++)
if(student[i].wy>student[k].wy)
{
arrange=student[k];
student[k]=student[i];
student[i]=arrange;
}
break;
case '4':
for(i=0;i<a-1;i++)
for(k=i+1;k<a;k++)
if(student[i].cyy>student[k].cyy)
{
arrange=student[k];
student[k]=student[i];
student[i]=arrange;
}
break;
}
break;
}
rewind(fp);
fwrite(student,sizeof(student[0]),a,fp);
fclose(fp);
}
void tianjia()//添加信息
{
n=0;
if((fp=fopen("xuesheng.txt","ab"))==NULL)
{ printf("不能打开 xuesheng.txt file\n");
exit(0);
}
while (fread(&student[n],sizeof(student[0]),1,fp)==1)
n++;
fclose(fp);
if((fp=fopen("xuesheng.txt","ab"))==NULL)
{
exit(0);
}
printf("\t\t\t请输入所要添加的信息\n");
printf("请输入学号:",n+1);
gets(student[n].bh);
printf("请输入姓名:",n+1);
gets(student[n].name);
printf("请输入性别:",n+1);
gets(student[n].xb);
printf("请输入数学成绩:");
gets(numstr);
student[n].sx=atof(numstr);
printf("请输入外语成绩:");
gets(numstr);
student[n].yy=atof(numstr);
printf("请输入网页成绩:");
gets(numstr);
student[n].wy=atof(numstr);
printf("请输入c语言成绩:");
gets(numstr);
student[n].cyy=atof(numstr);
printf("请输入计算机成绩:");
gets(numstr);
student[n].jsj=atof(numstr);
fwrite(&student[n],sizeof(student[n]),1,fp);
fclose(fp);
}