C语言程序设计学生成绩管理系统

#include <stdio.h>
#include <string.h>
#include <stdlib.h>
typedef struct LNode
{
long no;
char name[10];
int math;
int chinese;
int English;
int total;
struct LNode next;
}LNode;
void ma1in()
{
int i,j,a=1,b=1,c,d;
struct LNode s[100];
FILE fp=NULL;
char ch;
fp=fopen(“D:\student.date”,“w”);/以写的方式打开文件/
if(fpNULL)/判断是否打开成功/
{
printf(“Failure to open student.txt!\n”);
exit(0);
}
for(i=0;b
1;i++)/数据的输入/
{
printf(“please input stduent number ID:”);
scanf("%ld",&s[i].no);
printf(“plese input name:”);
//测试代码printf(“111111”);
scanf("%s",s[i].name);
printf(“math:”);
scanf("%d",&s[i].math);
printf(“chinese”);
scanf("%d",&s[i].chinese);
printf(“Engkish:”);
scanf("%d",&s[i].English);
printf(“if thinking continue Please input 1,else other number”);
scanf("%d",&b);
s[i].total=s[i].math+s[i].English+s[i].chinese;
}/致辞位置进行数据输入/
c=i;
printf(" no name[10] math chinese English total\n");/基本框架打印好/
for(i=0;i<c;i++)/文件的写入与屏幕显示此程序可以进行优化一下,化为一个单独的小块在五个大模块中多次用到/
{
fprintf(fp,"%10ld %3s %3d %3d %3d %3d",s[i].no,s[i].name,s[i].math,s[i].chinese,s[i].English,s[i].total);
fprintf(fp,"\n");
printf("%10ld %3s %3d %3d %3d %3d",s[i].no,s[i].name,s[i].math,s[i].chinese,s[i].English,s[i].total);
putchar(’\n’);
}
fclose(fp);
}
void ma2in()
{
int n,i=0,j,w;
struct LNode a[100],q;
FILE fp=NULL;
fp=fopen(“D:\student.date”,“r”);/只单单以读的方式打开文件/
if(fpNULL)
{
printf(“Failure to open student.txt!\n”);
exit(0);
}
while(1)/从文件中读取数据到结构体中/
{
fscanf(fp,"%10ld%s%3d%3d%3d%3d\n",&a[i].no,&a[i].name,&a[i].math,&a[i].chinese,&a[i].English,&a[i].total);
i++;
if(feof(fp))
break;
}
w=i;
for(i=0;i<w;i++)/利用选择排序法,通过改变结构体的内存地址改变,其他想法可以通过定义指针在结构体中用指针联系/
{
for(j=1+i;j<w;j++)
{
if(a[i].no>a[j].no)
{
q=a[i];
a[i]=a[j];
a[j]=q;
}
}
}
fclose(fp);
fp=fopen(“D:\s_no.date”,“w”);
if(fp
NULL)
{
printf(“Failure to open student.txt!\n”);
exit(0);
}
printf(" no name[10] math chinese English total\n");/基本框架打印好/
for(j=0;j<w;j++)
{
fprintf(fp,"%10ld %3s %3d %3d %3d %3d\n",a[j].no,a[j].name,a[j].math,a[j].chinese,a[j].English,a[j].total);
printf("%ld %s %d %d %d %d\n",a[j].no,a[j].name ,a[j].math ,a[j].chinese,a[j].English,a[j].total);
}
fclose(fp);
}
void ma3in()
{
int i=0, j,w;
LNode a[100],q;
FILE fp;
fp=fopen(“D:\student.date”,“r”);
if(fp==NULL)
{
printf(“Failure to open student.txt!\n”);
exit(0);
}
while(1)
{
fscanf(fp,"%10ld%s%3d%3d%3d%3d\n",&a[i].no,&a[i].name,&a[i].math,&a[i].chinese,&a[i].English,&a[i].total);
i++;
if(feof(fp))
break;
}
w=i;
for (j = 0; j < w; j++)
for (i = 1+j; i < w; i++)
if (strcmp((char
)a[j].name, (char
)a[i].name) > 0)
{
q=a[i];
a[i]=a[j];
a[j]=q;
}
fclose(fp);
fp=fopen(“D:\s_name.date”,“w”);
if(fpNULL)
{
printf(“Failure to open s_name.txt!\n”);
exit(0);
}
printf(" no name[10] math chinese English total\n");/基本框架打印好/
for(j=0;j<w;j++)
{
fprintf(fp,"%10ld %3s %3d %3d %3d %3d\n",a[j].no,a[j].name,a[j].math,a[j].chinese,a[j].English,a[j].total);
printf("%ld %s %d %d %d %d\n",a[j].no,a[j].name ,a[j].math ,a[j].chinese,a[j].English,a[j].total);
}
fclose(fp);
}
void ma4in()
{
int i=0,b=1,w,j;
struct LNode s[100],q;
FILE *fp=NULL;
fp=fopen(“D:\s_no.date”,“r”);
if(fp
NULL)
{
printf(“Failure to open student.txt!\n”);
exit(0);
}
while(1)
{
fscanf(fp,"%10ld%s%3d%3d%3d%3d\n",&s[i].no,&s[i].name,&s[i].math,&s[i].chinese,&s[i].English,&s[i].total);
i++;
if(feof(fp))
break;
}
fclose(fp);
//测试代码printf(“7777777777777777777777\n”);
for(;b1;i++)
{
printf(“please input stduent number ID:”);
scanf("%ld",&s[i].no);
printf(“plese input name:”);
//测试代码printf(“111111”);
scanf("%s",s[i].name);
printf(“math:”);
scanf("%d",&s[i].math);
printf(“chinese”);
scanf("%d",&s[i].chinese);
printf(“Engkish:”);
scanf("%d",&s[i].English);
printf(“if thinking continue Please input 1,else other number”);/这两行进行了小小的优化可以一次插入多组数据/
scanf("%d",&b);
s[i].total=s[i].math+s[i].English+s[i].chinese;
}/致辞位置进行数据输入/
w=i;
//测试代码printf(“33333333333333333333\n”);
for(i=0;i<w;i++)
{
for(j=1+i;j<w;j++)
{
if(s[i].no>s[j].no)
{
q=s[i];
s[i]=s[j];
s[j]=q;
}
}
}
//测试代码printf(“8888888888888888888888888888\n”);
fp=fopen(“D:\s_no.date”,“w”);
if(fp
NULL)
{
printf(“Failure to open student.txt!\n”);
exit(0);
}
printf(" no name[10] math chinese English total\n");/基本框架打印好/
for(i=0;i<w;i++)/文件的写入/
{
fprintf(fp,"%10ld %3s %3d %3d %3d %3d",s[i].no,s[i].name,s[i].math,s[i].chinese,s[i].English,s[i].total);
fprintf(fp,"\n");
printf("%ld %s %d %d %d %d\n",s[i].no,s[i].name ,s[i].math ,s[i].chinese,s[i].English,s[i].total);
}
fclose(fp);
}
void ma5in()
{
long z;
int i=0,b=1,w,j;
struct LNode s[100];
FILE fp=NULL;
fp=fopen(“D:\s_no.date”,“r”);
if(fpNULL)
{
printf(“Failure to open student.txt!\n”);
exit(0);
}
while(1)
{
fscanf(fp,"%10ld%s%3d%3d%3d%3d\n",&s[i].no,&s[i].name,&s[i].math,&s[i].chinese,&s[i].English,&s[i].total);
i++;
if(feof(fp))
break;
}
fclose(fp);
printf(“please input delate stduent number ID:”);
scanf("%ld",&z);
w=i;
for(i=0;i<w;i++)/由题意得不可能存在两个相同的学号故而可以考虑将两个相同需要删除连在一骑的情况/
{
if(s[i].no
z)
{
printf(“处于第:%d位数据为[%ld %s %d %d %d %d]\n”,i,s[i].no,s[i].name ,s[i].math ,s[i].chinese,s[i].English,s[i].total);
for(j=i;j<w;j++)
{
s[j]=s[j+1];
}
–i;/考虑前后代号一样/
–w;
}
}
fp=fopen(“D:\s_no.date”,“w”);
if(fp==NULL)
{
printf(“Failure to open student.txt!\n”);
exit(0);
}
printf(" no name[10] math chinese English total\n");/基本框架打印好/
for(i=0;i<w;i++)/文件的写入/
{
fprintf(fp,"%10ld %3s %3d %3d %3d %3d",s[i].no,s[i].name,s[i].math,s[i].chinese,s[i].English,s[i].total);
fprintf(fp,"\n");
printf("%ld %s %d %d %d %d\n",s[i].no,s[i].name ,s[i].math ,s[i].chinese,s[i].English,s[i].total);
}
fclose(fp);
}
void main()
{
int a=1,i,b;
printf("
\n菜单一:创建源数据文件\n菜单二:按学号由大到小排序\n菜单三:按姓名排序\n菜单四:插入成绩\n菜单五:删除特定学号\n*******************\n");
for(i=0;a==1;i++)
{
printf(“input your selecte:”);
scanf("%d",&b);
getchar();
switch(b)
{
case 1:
ma1in();
break;
case 2:
ma2in();
break;
case 3:
ma3in();
break;
case 4:
ma4in();
break;
case 5:
ma5in();
break;
default:
printf(“miss miss miss chaochufanwei”);
}
printf(“If your think continue Please input 1 else other number:”);
scanf("%d",&a);
}
}

  • 1
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值