永发信息网

学生档案管理系统C语言程序设计的功能

答案:2  悬赏:80  手机版
解决时间 2021-02-27 10:35
学生档案管理系统C语言程序设计的功能
最佳答案
我自己写的
#include
#include
#include
#include
#include
#include
#define LEN sizeof(STUDENT)
typedef struct stu
{char num[6];
char name[5];
int score[3];
int sum;
float average;
int order;
struct stu *next;
}STUDENT;
STUDENT *init();
int menu_select();
STUDENT *create();
void print(STUDENT *head);
void search(STUDENT *head);
STUDENT *delete(STUDENT *head);
STUDENT *sort(STUDENT *head);
STUDENT *insert(STUDENT *head,STUDENT *new);
void save(STUDENT *head);
STUDENT *load();
main()
{STUDENT *head,new;
head=init();
for(;;)
{switch(menu_select())
{
case 1:head=create();break;
case 2:print(head);break;
case 3:search(head);break;
case 4:head=delete(head);break;
case 5:head=sort(head);break;
case 6:head=insert(head,&new);break;
case 7:save(head);break;
case 8:head=load(); break;
case 9:exit(0);
}
}
}
STUDENT *init()
{
return NULL;
}
menu_select()
{int n;
printf("\npress any key to enter the menu......");
getch();
system("cls");
printf("********************************************************************************\n");
printf("\t\t Welcome to\n");
printf("*************************************MENU***************************************\n");
printf("\t\t\t1.Enter the record\n");
printf("\t\t\t2.Print the record\n");
printf("\t\t\t3.Search record on name\n");
printf("\t\t\t4.Delete a record\n");
printf("\t\t\t5.Sort to make new a file\n");
printf("\t\t\t6.Insert record to list\n");
printf("\t\t\t7.Save the file\n");
printf("\t\t\t8.Load the file\n");
printf("\t\t\t9. Quit\n");
printf("\n\t\tMade by Gou xiaobo.\n");
printf("********************************************************************************\n");
do{
printf("\n\t\t\tEnter your choice(1~9):");
scanf("%d",&n);
}while(n<1||n>9);
return(n);
}
STUDENT *create()
{int i,s;
STUDENT *head=NULL,*p;
clrscr();
for(;;)
{p=(STUDENT *)malloc(LEN);
if(!p)
{printf("\nOut of memory.");
return (head);
}
printf("Enter the num(0:list end):");
scanf("%s",p->num);
if(p->num[0]=='0') break;
printf("Enter the name:");
scanf("%s",p->name);
printf("Please enter the %d scores\n",3);
s=0;
for(i=0;i<3;i++)
{
do{
printf("score%d:",i+1);
scanf("%d",&p->score[i]);
if(p->score[i]<0 || p->score[i]>100)
printf("Data error,please enter again.\n");
}while(p->score[i]<0 || p->score[i]>100);
s=s+p->score[i];
}
p->sum=s;
p->average=(float)s/3;
p->order=0;
p->next=head;
head=p;
}
return(head);
}
void print(STUDENT *head)
{int i=0;
STUDENT *p;
clrscr();
p=head;
printf("\n************************************STUDENT************************************\n");
printf("-------------------------------------------------------------------------------\n");
printf("| Rec | Num | Name | Sc1 | Sc2 | Sc3 | Sum | Ave | Order |\n");
printf("-------------------------------------------------------------------------------\n");
while(p!=NULL)
{
i++;
printf("| %3d | %4s | %-4s | %3d | %3d | %3d | %3d | %4.2f | %-5d|\n",
i, p->num,p->name,p->score[0],p->score[1],p->score[2],p->sum,p->average,p->order);
p=p->next;
}
printf("-------------------------------------------------------------------------------\n");
printf("**************************************END**************************************\n");
}
void search(STUDENT *head)
{STUDENT *p;
char s[5];
clrscr();
printf("Please enter name for searching.\n");
scanf("%s",s);
p=head;
while(strcmp(p->name,s) && p != NULL)
p=p->next;
if(p!=NULL)
{printf("\n*************************************FOUND************************************\n");
printf("-------------------------------------------------------------------------------\n");
printf("| Num | Name | sc1 | sc2 | sc3 | Sum | Ave | Order |\n");
printf("-------------------------------------------------------------------------------\n");
printf("| %4s | %4s | %3d | %3d | %3d | %3d | %4.2f | %-5d|\n",
p->num,p->name,p->score[0],p->score[1],p->score[2],p->sum,p->average,p->order);
printf("-------------------------------------------------------------------------------\n");
printf("***************************************END**************************************\n");
}
else
printf("\nThere is no num %s student on the list.\n",s);
}
STUDENT *delete(STUDENT *head)
{int n;
STUDENT *p1,*p2;
char c,s[6];
clrscr();
printf("Please enter the deleted num: ");
scanf("%s",s);
p1=p2=head;
while(strcmp(p1->num,s) && p1 != NULL)
{p2=p1;
p1=p1->next;
}
if(strcmp(p1->num,s)==0)
{printf("**************************************FOUND************************************\n");
printf("-------------------------------------------------------------------------------\n");
printf("| Num | Name | sc1 | sc2 | sc3 | Sum | Ave | Order |\n");
printf("-------------------------------------------------------------------------------\n");
printf("| %4s | %4s | %3d | %3d | %3d | %3d | %4.2f | %-5d|\n",
p1->num,p1->name,p1->score[0],p1->score[1],p1->score[2],p1->sum,p1->average,p1->order);
printf("-------------------------------------------------------------------------------\n");
printf("***************************************END**************************************\n");
printf("\nAre you sure to delete the student Y/N ?");
for(;;)
{scanf("%c",&c);
if(c=='n'||c=='N') break;
if(c=='y'||c=='Y')
{
if(p1==head)
head=p1->next;
else
p2->next=p1->next;
n=n-1;
printf("\n(Num):%s(student have been deleted.)\n",s);
printf("Don't forget to save.\n");break;
}
}
}
else
printf("\nThere is no num %s student on the list.\n",s);
return(head);
}
STUDENT *sort(STUDENT *head)
{int i=0;
STUDENT *p1,*p2,*t,*temp;
temp=head->next;
head->next=NULL;
while(temp!=NULL)
{
t=temp;
temp=temp->next;
p1=head;
p2=head;
while(t->averageaverage&&p1!=NULL)
{
p2=p1;
p1=p1->next;
}
if(p1==p2)
{
t->next=p1;
head=t;
}
else
{
t->next=p1;
p2->next=t;
}
}
p1=head;
while(p1!=NULL)
{
i++;
p1->order=i;
p1=p1->next;
}
printf("Sorting is sucessful.\n");
return (head);
}
STUDENT *insert(STUDENT *head,STUDENT *new)
{STUDENT *p0,*p1,*p2;
int n,sum1,i;
p1=head;
p0=new;
printf("\nPlease enter a new record.\n");
printf("Enter the num:");
scanf("%s",new->num);
printf("Enter the name:");
scanf("%s",new->name);
printf("Please enter the %d scores.\n",3);
sum1=0;
for(i=0;i<3;i++)
{
do{
printf("score%d:",i+1);
scanf("%d",&new->score[i]);
if(new->score[i]>100||new->score[i]<0)
printf("Data error,please enter again.\n");
}while(new->score[i]>100||new->score[i]<0);
sum1=sum1+new->score[i];
}
new->sum=sum1;
new->average=(float)sum1/3;
new->order=0;
if(head==NULL)
{head=p0;p0->next=NULL;}
else
{while((p0->averageaverage)&&(p1->next!=NULL))
{p2=p1;
p1=p1->next;
}
if(p0->average>=p1->average)
{if(head==p1)head=p0;
else p2->next=p0;
p0->next=p1;}
else
{p1->next=p0;p0->next=NULL;}
}
n=n+1;
head=sort(head);
printf("\nStudent %s have been inserted.\n",new->name);
printf("Don't forget to save the new file.\n");
return(head);
}
void save(STUDENT *head)
{FILE *fp;
STUDENT *p;
char outfile[10];
printf("Enter outfile name,for example c:\\score\n");
scanf("%s",outfile);
if((fp=fopen(outfile,"w"))==NULL)
{
printf("Cannot open the file\n");
return;
}
printf("\nSaving the file......\n");
p=head;
while(p!=NULL)
{
fwrite(p,LEN,1,fp);
p=p->next;
}
fclose(fp);
printf("Save the file successfully!\n");
}
STUDENT *load()
{STUDENT *p1,*p2,*head=NULL;
FILE *fp;
char infile[10];
printf(" Enter infile name,for example c:\\score\n");
scanf("%s",infile);
if((fp=fopen(infile,"r"))==NULL)
{
printf("Can not open the file.\n");
return(head);
}
printf("Loading the file!\n");
p1=(STUDENT *)malloc(LEN);
if(!p1)
{
printf("Out of memory!\n");
return(head);
}
head=p1;
while(!feof(fp))
{
if(fread(p1,LEN,1,fp)!=1) break;
p1->next=(STUDENT *)malloc(LEN);
if(!p1->next)
{
printf("Out of memory!\n");
return (head);
}
p2=p1;
p1=p1->next;
}
p2->next=NULL;
fclose(fp);
printf("\nnYou have success to read data from the file!\n");
return (head);
}
全部回答
给,已经编译运行确认了: #include #include #include #include #define n 10 int m=0; struct student { char num[13]; char name[20]; char sex; char address[30]; int age; }; typedef struct lb { struct student xinxi; struct lb *next; }lb_1,*lb_2; void caidang() { printf(" \t \t \t (欢迎使用本班级档案管理系统)\t\t\t\t\n"); printf("★*★*★*★*★*★*★*★*★*★ 欢迎进入我们的系统 ★*★*★*★*★*★*★*★*★*★\n\n"); printf("1.录入学生资料\t\t\t\t\t4.查询学生信息\n\n"); printf("2.修改学生信息\t\t\t\t\t5.删除学生信息\n\n"); printf("3.保存学生信息\t\t\t\t\t0.退出档案系统\n\n"); printf(" \n"); printf("★*★*★*★*★*★*★*★*★*★ 欢迎进入本系统 ★*★*★*★*★*★*★*★*★*★\n"); } void color() { textbackground(8); textcolor(9); clrscr(); } void wrong() { printf("\n对不起您的输入错误!\n"); } void sorry() { printf("\n对不起该同学现没有任何信息!\n"); } void printe(lb_1 *p) { printf(" %-2s %s\t %s\t%s\t %d\t \n",p->xinxi.num,p->xinxi.name,p->xinxi.sex,p->xinxi.address,p->xinxi.age); } lb_1 *locate(lb_2 l,char findmess[],char nameornum[]) { lb_1 *r; if(strcmp(nameornum,"num")==0) { r=l->next; while(r!=null) { if(strcmp(r->xinxi.num,findmess)==0) return r; r=r->next; } } else if(strcmp(nameornum,"name")==0) { r=l->next; while(r!=null) { if(strcmp(r->xinxi.name,findmess)==0) return r; r=r->next; } } return 0; } void tianjia(lb_2 l) { lb_1 *p,*r,*s; char num[13]; r=l; s=l->next; while(r->next!=null) r=r->next; while(1) { printf(" 请输入添加的学生学号(输入'0'返回上一级菜单:)"); scanf("%s",num); if(strcmp(num,"0")==0) break; while(s) { if(strcmp(s->xinxi.num,num)==0) { printf("(必看提示):学号为'%s'的学生已有信息,若要修改请你输入'2 修改'!\n",num); printe(s); printf("\n"); return; } s=s->next; } p=(lb_1 *)malloc(sizeof(lb_1)); strcpy(p->xinxi.num,num); printf(" 请你输入学号:"); scanf("%s",p->xinxi.num); getchar(); printf(" 请你输入姓名:"); scanf("%s",p->xinxi.name); getchar(); printf(" 请你输入性别:"); scanf("%s",p->xinxi.sex); getchar(); printf(" 请你输入地址:"); scanf("%s",p->xinxi.address); getchar(); printf(" 请你输入年龄:"); scanf("%d",&p->xinxi.age); getchar(); p->next=null; r->next=p; r=p; m=1; } } void shanchu(lb_2 l) { int sel; lb_1 *p,*r; char findmess[20]; if(!l->next) { printf("\n******(必看提示):对不起,现文件中没有信息:所以您不能查询!\n"); return; } printf("\n <必看提示> <以学号删除请输入1\n> <以姓名删除请输入2\n> please:"); scanf("%d",&sel); if(sel==1) { printf("请输入要删除的学生的学号please:"); scanf("%s",findmess); p=locate(l,findmess,"num"); if(p) { r=l; while(r->next!=p) r=r->next; r->next=p->next; free(p); printf("\n*******(必看提示):该学生的信息已完全删除成功!\n"); m=1; } else sorry(); } else if(sel==2) { printf("请输入要删除的学生的姓名please:"); scanf("%s",findmess); p=locate(l,findmess,"name"); if(p) { r=l; while(r->next!=p) r=r->next; r->next=p->next; free(p); printf("\n******(必看提示):该学生信息已成功删除!\n"); m=1; } else sorry(); } else wrong(); } void chaxiong(lb_2 l) { int sel; char findmess[20]; lb_1 *p; if(!l->next) { printf("\n******(必看提示):对不起,现文件中没有信息:所以您不能查询!\n"); return; } printf("\n以学号查询请输入1:\n以姓名查询请输入2:\n以性别查询请输入3:\n以性别查询请输入4:\n please:"); scanf("%d",&sel); if(sel==1) { printf("请你输入要查找的学号:"); scanf("%s",findmess); p=locate(l,findmess,"num"); if(p) { printf("\t\t\t\t查找结果\n"); printf(" 学号:%s\n姓名:%s\n性别:%s\n地址:%s\n年龄:%d\n",p->xinxi.num,p->xinxi.name,p->xinxi.sex,p->xinxi.address,p->xinxi.age); } else sorry(); } if(sel==2) { printf("请你输入要查找的姓名:"); scanf("%s",findmess); p=locate(l,findmess,"name"); if(p) { printf("\t\t\t\t查找结果\n"); printf(" 学号:%s\n姓名:%s\n性别:%s\n地址:%s\n年龄:%d\n",p->xinxi.num,p->xinxi.name,p->xinxi.sex,p->xinxi.address,p->xinxi.age); } else sorry(); } else wrong(); } void xiugei(lb_2 l) { lb_1 *p; long int i,j; char findmess[20]; if(!l->next) { printf("\n(必看提示):对不起,现文件中没有信息:所以您不能查询!\n"); return; } for(i=1;i<=2;i++) { printf("\n\n\n\n\n"); printf("请输入密码:"); scanf("%s",&j); if(j==2007)break; else {if(j!=2007) return(caidang()); } } printf("请你输入要修改的学生学号:"); scanf("%s",findmess); p=locate(l,findmess,"num"); if(p) { printf("请你输入新学号(原来是%s):",p->xinxi.num); scanf("%s",p->xinxi.num); printf("请你输入新姓名(原来是%s):",p->xinxi.name); scanf("%s",p->xinxi.name); printf("请你输入新性别(原来是%s):",p->xinxi.sex); scanf("%s",p->xinxi.sex); printf("请你输入新地址(原来是%s):",p->xinxi.address); scanf("%s",p->xinxi.address); printf("请你输入新年龄(原来是%d):",p->xinxi.age); scanf("%s",p->xinxi.age); getchar(); m=1; } else sorry(); } void baocong(lb_2 l) { file* fp; lb_1 *p; int flag=1,count=0; fp=fopen("c:\\lyg","wr"); if(fp==null) { printf("\n=====>提示:重新打开文件时发生错误!\n"); exit(1); } p=l->next; while(p) { if(fwrite(p,sizeof(lb_1),1,fp)==1) { p=p->next; count++; } else { flag=0; break; } } if(flag) { printf("\n 提示;正在保存文件 共保存了%d条信息\n",count);m=0; } fclose(fp); } void main() { lb_2 l; file *fp; int sel;long i,j,d; char ch; char jian; int count=0; lb_1 *p,*r; color(); clrscr(); l=(lb_1*)malloc(sizeof(lb_1)); l->next=null; r=l; fp=fopen("c:\\lyg","rb"); if(fp==null) { printf("\t\t\t\t\n\n"); printf("\n"); printf(" *_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*\n" " *_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*\n" " welcome to come to our system!!! \n" " you can only inquire your own messages! if you want to see about other \n" " students' messages,you need first to send inquirment to them,asking for \n" " agreement,then you can visit his/her messages! \n" " have a good time! now you can come in!!! \n" " *_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*\n" " *_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*\n" " 注意:系统启动码为 : ilovemyschoolverymuch !!! \n" " *_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*\n" " *_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*\n"); printf("欢迎使用,本系统中现没有任何记录,您要先创建文件请按以下操做进行please:\n"); printf("\n 提示:文件还不存在,是否创建?(y/n)请做选择--\n"); printf("\n"); scanf("%c",&jian); if(jian=='y'||jian=='y') {fp=fopen("c:\\lyg","wb"); clrscr(); } {for(i=1;i<=2;i++) { printf("\n\n\n\n\n"); printf("请输入密码:"); scanf("%ld",&j); if(j==2007)break; else {if(j!=2007)return; } } } exit(0);clrscr(); } while(!feof(fp)) { p=(lb_1*)malloc(sizeof(lb_1)); if(fread(p,sizeof(lb_1),1,fp)) { p->next=null; r->next=p; r=p; count++; } } fclose(fp); while(1) { caidang(); printf("请你选择操作:"); scanf("%d",&sel); clrscr(); printf("\n\n\n"); if(sel==0) { if(m==1) { getchar(); printf("\n(必看提示):链表中的信息已经改动,如果确认把改动保存在文件中请做选择(y/n)?\n"); scanf("%c",&ch); if(ch=='y'||ch=='y') baocong(l); } break;clrscr(); } switch(sel) { case 1: tianjia(l);break; case 4: chaxiong(l);break; case 3: baocong(l);break; case 2: xiugei(l);break; case 5: shanchu(l);break; default: getchar();break; } } end: getchar(); }
我要举报
如以上问答信息为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
vba保存代码怎么加上这个功能。
派迪琪琪童装店地址在哪,我要去那里办事
材料体 现 的 道 理(1)只因滴水的坚持,磐石
阿玛拉王国 惩罚新敌人,老朋友,坐到后面能不
岔庙镇义河村村地址在什么地方,想过去办事
即插即用 桌面扩展到监视器上 显示无信号
【range】请问range在英语中怎么用?
半条命2物理沙盘服务器怎么安装
回首若如初见 岁月何必斑驳是情话吗
凤凰便利怎么去啊,有知道地址的么
2013crv后尾翼高位刹车灯光
男友不够大方怎么办?
宏云摩配怎么去啊,有知道地址的么
求问PS怎么才可以按着一定的规律复制?比如我
山东省曲阜市曲阜城修建于什么朝代
推荐资讯
以思乡情和恋乡意为本体,写一个比喻句
急求东江阴街小学或者民立街小学的照片!!
如何看待用脚投票,?????
什么叫电磁炮
恒大人员名字
易方达基金110026怎么样,可以买吗
雷蒙照明我想知道这个在什么地方
什么是缩量洗盘?
跟对象分手了,但是我很爱很爱TA,TA已经不爱
舒康推拿足浴这个地址在什么地方,我要处理点
鲁山县平顶山中国福利彩票这个地址在什么地方
海马福美来三代和现代瑞纳,买哪个?
正方形一边上任一点到这个正方形两条对角线的
阴历怎么看 ?