用C语言编写学生信息管理程序(给出五个主要函数就OK啦!)
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了用C语言编写学生信息管理程序(给出五个主要函数就OK啦!)相关的知识,希望对你有一定的参考价值。
参考技术A /*接上一楼*/struct
Student
*create()
/*create函数定义,此函数实现创建单向动态链表*/
struct
Student
*head=NULL,*p1,*p2;
/*head,链表的头指针;*p1,*p2,中间指针变量*/
puts("\n现在请输入学院名:");
scanf("%s",college);
puts("\n年级:");
scanf("%s",grade);
puts("\n专业和班级:");
scanf("%s",classname);
puts("\n下面请按提示依次输入数据:\n(如果要结束输入,请输入学号0)");
p1=p2=(struct
Student
*)malloc(LEN);
puts("输入第一个学生的学号:");
scanf("%ld",&p1->num);
puts("输入此学生成绩:\n英语:");
scanf("%f",&p1->score.english);
puts("数学:");
scanf("%f",&p1->score.math);
puts("计算机:");
scanf("%f",&p1->score.computer);
total_and_aver(p1);/*计算总分和平均分*/
p1->grade=mark_grade(p1);
for(;p1->num!=0;)
len++;
if(len==1)
head=p1;
else
p2->next=p1;
p2=p1;
p1=(struct
Student
*)malloc(LEN);
puts("输入下一个学生的学号:");
scanf("%ld",&p1->num);
puts("输入此学生成绩:\n英语:");
scanf("%f",&p1->score.english);
puts("数学:");
scanf("%f",&p1->score.math);
puts("计算机:");
scanf("%f",&p1->score.computer);
total_and_aver(p1);/*计算总分和平均分*/
p1->grade=mark_grade(p1);
p2->next=NULL;
return
(head);
struct
Student
*del(struct
Student
*head,long
del_num)
/*del函数定义,此函数实现从现有链表中删除一个结点*/
struct
Student
*p1,*p2;
if(head==NULL)
puts("空表,没有任何数据记录。\n");
else
for(p1=head;!(del_num==p1->num||p1->next==NULL);p2=p1,p1=p1->next);
if(del_num==p1->num)
if(p1==head)head=p1->next;
else
p2->next=p1->next;
printf("学号为%ld学生的数据删除成功。\n",del_num);
--len;
else
printf("未找到学号为%ld学生的记录。\n",del_num);
return
(head);
struct
Student
*insert(struct
Student
*head,struct
Student
*new_student)
/*insert函数定义,此函数实现向现有链表中插入一个结点或覆盖相同学号的数据*/
struct
Student
*p0=new_student,*p1=head,*p2;
char
control;
if(head==NULL)
head=p0;
p0->next=NULL;
puts("数据插入成功。\n");
else
for(;((*p0).num>(*p1).num)&&(p1->next!=NULL);p2=p1,p1=p1->next);
if((*p0).num==(*p1).num)
printf("已经存在一个学号为%ld的学生的数据,要覆盖原有数据吗?\n输入
Y
=覆盖原有数据\n输入其它=保留原有数据\n",p0->num);
FFLUSH;
scanf("%c",&control);
FFLUSH;
switch
(control)
case
'Y':
case
'y':if(p1==head)head=p0;p0->next=p1->next;
else
p2->next=p0;p0->next=p1->next;
puts("数据已经更新\n");break;
default:break;
len--;
else
if((*p0).num<(*p1).num)
if(p1==head)head=p0;
else
p2->next=p0;
p0->next=p1;
puts("数据插入成功。\n");
else
p1->next=p0;
p0->next=NULL;
puts("数据插入成功。\n");
++len;
return
(head);
struct
Student
*sort(struct
Student
*head)
/*sort函数定义,此函数实现对链表中的数据按照平均分高低排序*/
struct
Student
*p1,*p2;
for(p1=head;p1->next!=NULL;p1=p1->next)
for(p2=p1->next;p2!=NULL;p2=p2->next)
if(p1->score.average<p2->score.average)
SWAP(p1->num,p2->num);
SWAP(p1->grade,p2->grade);
SWAP(p1->score.english,p2->score.english);
SWAP(p1->score.math,p2->score.math);
SWAP(p1->score.computer,p2->score.computer);
SWAP(p1->score.total,p2->score.total);
SWAP(p1->score.average,p2->score.average);
return
head;
/*接下一楼*/
用C语言编写学生信息管理系统,十万火急!
用链表或结构体数组开发一个学生管理系统.功能包括:
一.自行设计一个用户交互界面.由用户界面进入相应操作,主要有:
1.添加学生信息输入.
每个学生信息包括:学号,姓名,班级,性别,课程成绩(课程名可自拟)不重复.
2,学生信息修改.
3,删除学生信息.删除指定学生的所有信息.
4,学生信息查询.
(1)按姓名查询:输入学生姓名,显示该学生的所有信息.学生姓名可用前方一致查找.如查找"张?",即表示查找所有姓张的学生.当查找到的学生信息大于一幅屏幕,应该分屛显示.
(2)按学号查找:允许用>,>=,=,<,<=查找,能够分屛显示.
(3)按某一门课程的成绩查询:允许用>,>=,=,<,<=查找,能够分屛显示.
(4)按班级查询:查询某一班级的所有学生信息,能够分屛显示.
(5)查循某一门课程的平均成绩:总平均及按班级求平均成绩.
二.以上输入的所有学生信息及修改后的更新信息都可以文件的形式保存,以便今后直接调用.
最好可以把每句代码的功能说明一下.
#include "stdio.h" /*I/O函数*/
#include "stdlib.h" /*其它说明*/
#include "string.h" /*字符串函数*/
#include "conio.h" /*屏幕操作函数*/
#include "mem.h" /*内存操作函数*/
#include "ctype.h" /*字符操作函数*/
#include "alloc.h" /*动态地址分配函数*/
struct score
int mingci;
char xuehao[8];
char mingzi[20];
float score[6];
data,info[1000];
int i,j,k=0;
char temp[20],ch;
FILE *fp,*fp1;
void shuru()
if((fp=fopen("s_score.txt","ab+"))==NULL)
printf("cannot open this file.\n");
getch();exit(0);
for(i=0;i<=1000;i++)
printf("\nPlease shuru xuehao:");
gets(data.xuehao);
printf("Please shuru mingzi:");
gets(data.mingzi);
printf("Please shuru yuwen score:");
gets(temp);data.score[0]=atof(temp);
printf("Please shuru shuxue score:");
gets(temp);data.score[1]=atof(temp);
printf("Please input yingyu score:");
gets(temp);data.score[2]=atof(temp);
printf("Please shuru wuli score:");
gets(temp);data.score[3]=atof(temp);
printf("Please shur huaxue score:");
gets(temp);data.score[4]=atof(temp);
data.score[5]=data.score[0]+data.score[1]+data.score[2]+data.score[3]+data.score[4];
fwrite(&data,sizeof(data),1,fp);
printf("another?y/n");
ch=getch();
if(ch=='n'||ch=='N')
break;
fclose(fp);
void xianshi()
float s;int n;
if((fp=fopen("s_score.txt","rb+"))==NULL)
printf("Cannot reading this file.\n");
exit(0);
for(i=0;i<=1000;i++)
if((fread(&info[i],sizeof(info[i]),1,fp))!=1)
break;
printf("\nxuehao mingzi yuwen shuxue yingyu wuli huauxue zhongfen\n");
for(j=0,k=1;j<i;j++,k++)
info[j].mingci=k;
printf("%6s %8s %3.1f %3.1f %3.1f %3.1f %3.1f %3.1f\n",info[j].xuehao,info[j].mingzi,info[j].score[0],info[j].score[1],info[j].score[2],info[j].score[3],info[j].score[4],
info[j].score[5]);
getch();
fclose(fp);
void xiugai()
if((fp=fopen("s_score.txt","rb+"))==NULL||(fp1=fopen("temp.txt","wb+"))==NULL)
printf("Cannot open this file.\n");
exit(0);
printf("\nPLease shuru xiugai xuehao:");
scanf("%d",&i); getchar();
while((fread(&data,sizeof(data),1,fp))==1)
j=atoi(data.xuehao);
if(j==i)
printf("xuehao:%s\nmingzi:%s\n",data.xuehao,data.mingzi);
printf("Please shuru mingzi:");
gets(data.mingzi);
printf("Please shuru yuwen score:");
gets(temp);data.score[0]=atof(temp);
printf("Please shuru shuxue score:");
gets(temp);data.score[1]=atof(temp);
printf("Please input yingyu score:");
gets(temp);data.score[2]=atof(temp);
printf("Please input wuli score:");
gets(temp);data.score[3]=atof(temp);
printf("Please input huaxue score:");
gets(temp);data.score[4]=atof(temp);
data.score[5]=data.score[0]+data.score[1]+data.score[2]+data.score[3]+data.score[4];
fwrite(&data,sizeof(data),1,fp1);
fseek(fp,0L,0);
fseek(fp1,0L,0);
while((fread(&data,sizeof(data),1,fp1))==1)
fwrite(&data,sizeof(data),1,fp);
fclose(fp);
fclose(fp1);
void chazhao()
if((fp=fopen("s_score.txt","rb"))==NULL)
printf("\nCannot open this file.\n");
exit(0);
printf("\nPLease shuru xuehao chakan:");
scanf("%d",&i);
while(fread(&data,sizeof(data),1,fp)==1)
j=atoi(data.xuehao);
if(i==j)
printf("xuehao:%s mingzi:%s\nyuwen:%f\n shuxue:%f\n yingyu:%f\n wuli:%f\n huaxue:%f\n ",data.xuehao,data.mingzi,data.score[0],data.score[1],data.score[2],data.score[3],data.score[4],data.score[5]);
getch();
void shanchu()
if((fp=fopen("s_score.txt","rb+"))==NULL||(fp1=fopen("temp.txt","wb+"))==NULL)
printf("\nopen score.txt was failed!");
getch();
exit(0);
printf("\nPlease input ID which you want to del:");
scanf("%d",&i);getchar();
while((fread(&data,sizeof(data),1,fp))==1)
j=atoi(data.xuehao);
if(j==i)
printf("Anykey will delet it.\n");
getch();
continue;
fwrite(&data,sizeof(data),1,fp1);
fclose(fp);
fclose(fp1);
remove("s_score.txt");
rename("temp.txt","s_score.txt");
printf("Data delet was succesful!\n");
printf("Anykey will return to main.");
getch();
main()
while(1)
clrscr(); /*清屏幕*/
gotoxy(1,1); /*移动光标*/
textcolor(YELLOW); /*设置文本显示颜色为黄色*/
textbackground(BLUE); /*设置背景颜色为蓝色*/
window(1,1,99,99); /* 制作显示菜单的窗口,大小根据菜单条数设计*/
clrscr();
printf("*************welcome to use student manage******************\n");
printf("*************************menu********************************\n");
printf("* ========================================================= * \n");
printf("* 1>shuru 2>xiugai * \n");
printf("* 3>shanchu 4>chazhao * \n");
printf("* 5>xianshi 6>exit * \n");
printf("* * \n");
printf("* --------------------------------------------------------- * \n");
printf(" Please input which you want(1-6):");
ch=getch();
switch(ch)
case '1':shuru();break;
case '2':xiugai(); break;
case '3':shanchu(); break;
case '4':chazhao(); break;
case '5':xianshi(); break;
case '6':exit(0);
default: continue;
本回答被提问者采纳
以上是关于用C语言编写学生信息管理程序(给出五个主要函数就OK啦!)的主要内容,如果未能解决你的问题,请参考以下文章