开发工具:
文件大小: 52kb
下载次数: 0
上传时间: 2016-04-22
详细说明: #include #include #include #include #define LENGTH sizeof(student) #define NULL 0 #define MAX_GESHU 1000 /*最多处理的学生个数*/ long int Xs_geshu=0; /*记录当前学生个数的变量*/ struct xs_cj /*成绩的结构体*/ { float yu wen;float shuxue;float yingyu;/*语数外*/ float wuli;float huaxue;float shengwu;/*理化生*/ float zhengzhi;float lishi;float dili;/*政史地*/ }; struct student /*学生数据结构体*/ { unsigned long int xuehao;/*学号*/ char xingming[20];/*姓名*/ char xingbie;/*性别*/ unsigned short int nianling;/*年龄*/ char xueke;/*文科还是理科*/ char lianxidianhua[20];/*联系电话*/ struct xs_cj chengji;/*成绩*/ struct student *next; }; struct student *chushi_shuju(void);/*初始化数据库函数*/ void print_shuju(struct student *p);/*打印所有数据的函数*/ struct student *tianjia_shuju(struct student *p1); /*添加学生数据的函数*/ void xiugai_shuju(struct student *p); /*修改学生数据的函数*/ struct student *shanchu_shuju(struct student *p); /*删除学生数据的函数*/ void tongji_shuju(struct student *p); /*统计学生数据的函数*/ struct student *paixu_shuju(struct student *p); /*排列学生数据的函数*/ void main() { short int caozuo=0; /*用户操作控制变量*/ unsigned long int jishi=0; struct student *head=NULL; printf("=========================欢迎进入学生数据库管理系统!=========================\n\n"); printf("您的目录是空的,需要现在开始创建吗?\n是(输入1) 不(输入0):"); scanf("%d",&caozuo); if(caozuo==0) goto endsystem; head=chushi_shuju(); printf("=========================初始数据已录入完毕=========================\n\n\n\n\n\n\n\n\n"); play :; printf("查看所有数据请输入1,添加数据请输入2,修改数据请输入3,删除数据请输入4,统计数据请输入5,排序功能请输入6,退出程序请输入0\n"); scanf("%d",&caozuo); switch(caozuo) { case 0: goto endsystem; case 1: print_shuju(head);break; case 2: head=tianjia_shuju(head);break; case 3: xiugai_shuju(head);break; case 4: head=shanchu_shuju(head);break; case 5: tongji_shuju(head);break; case 6: head=paixu_shuju(head);break; default :break; } printf("\n\n\n\n\n\n\n\n"); goto play; endsystem : printf("感谢您使用本程序,有什么建议请联系本人,独角螃蟹QQ:1020313617\n"); printf("退出倒记时:\n"); for(jishi=0;jishi<=200000000;jishi++) { jishi==30000000 ? printf("4\n"):0; jishi==80000000 ? printf("3\n"):0; jishi==130000000 ? printf("2\n"):0; jishi==160000000 ? printf("1\n"):0; jishi==190000000 ? printf("0\n"):0; } } struct student *chushi_shuju(void) { struct student *head,*p1,*p2; short int caozuo=0; /*用户操作控制变量*/ p1=(struct student *)malloc(LENGTH); /*动态开辟内存空间*/ if(!p1) /*分配空间失败则退出*/ { printf("系统繁忙 请稍后重试!"); goto bak; } head=p1; do { Xs_geshu=Xs_geshu+1; p2=p1; printf("==================请输入第%d个学生的数据(数据中间用空格分隔)==================\n",Xs_geshu); printf("学号: 姓名: 性别(男m 女f): 年龄: 选科(文w 理l): 联系电话(没有请添0):\n"); scanf("%ld %s %c %d %c %s",&p1->xuehao,p1->xingming,&p1->xingbie,&p1->nianling,&p1->xueke,p1->lianxidianhua); printf("============================请输入该学生的各课成绩============================\n"); if(p1->xueke=='l') { printf("语文: 数学: 英语: 物理: 化学: 生物:\n"); scanf("%f %f %f %f %f %f",&p1->chengji.yuwen,&p1->chengji.shuxue,&p1->chengji.yingyu,&p1->chengji.wuli,&p1->chengji.huaxue,&p1->chengji.shengwu); p1->chengji.zhengzhi=-1,p1->chengji.lishi=-1,p1->chengji.dili=-1; }else{ printf("语文: 数学: 英语: 政治: 历史: 地理:\n"); scanf("%f %f %f %f %f %f",&p1->chengji.yuwen,&p1->chengji.shuxue,&p1->chengji.yingyu,&p1->chengji.zhengzhi,&p1->chengji.lishi,&p1->chengji.dili); p1->chengji.wuli=-1,p1->chengji.huaxue=-1,p1->chengji.shengwu=-1; } printf("继续输入吗? 是(输入1) 否(输入0):"); scanf("%d",&caozuo); p1=(struct student *)malloc(LENGTH); p2->next=p1; if(!p1) { printf("系统繁忙 请稍后重试!"); break; } }while(caozuo); p2->next=NULL; free(p1); bak:; return head; } void print_shuju(struct student *p) /*打印数据的函数 form main()*/ { struct student *head; unsigned long int caozuo=0; head=p; printf("============================查看%d个学生的所有数据============================\n",Xs_geshu); if(p==NULL) { printf("没有任何数据!\n"); goto endprint; } printf("学号: 姓名: 性别(男m 女f): 年龄: 选科(文w 理l): 联系电话:\n"); while(p!=NULL) { printf("%-7ld%-15s%-7c%-7d%-7c%-7s\n",p->xuehao,p->xingming,p->xingbie,p->nianling,p->xueke,p->lianxidianhua); p=p->next; } p=head; printf("查找学生成绩请输入该学生的学号,返回上一级请输入0\n"); scanf("%ld",&caozuo); if(caozuo) { for(;p!=NULL;p=p->next) { if(p->xuehao==caozuo) { printf("姓名: 语文: 数学: 英语: 物理: 化学: 生物: 政治: 历史: 地理:\n"); printf("%-15s",p->xingming); printf("%-7.1f%-7.1f%-7.1f",p->chengji.yuwen,p->chengji.shuxue,p->chengji.yingyu); printf("%-7.1f%-7.1f%-7.1f",p->chengji.wuli,p->chengji.huaxue,p->chengji.shengwu); printf("%-7.1f%-7.1f%-7.1f",p->chengji.zhengzhi,p->chengji.lishi,p->chengji.dili); putchar('\n'); break; } } caozuo=0; if(p==NULL) { printf("没有找到该学生数据,需要创建该数据吗?(是1 否0):"); scanf("%d",&caozuo); } if(caozuo) tianjia_shuju(head); } endprint:; } struct student *tianjia_shuju(struct student *p1) /*添加数据的函数 form main()*/ { struct student *p,*p2; short int caozuo=0; p2=p1; p=(struct student *)malloc(LENGTH); if(!p) { printf("系统繁忙 请稍后重试!"); goto endtianjia; } chongshu:; printf("学号: 姓名: 性别(男m 女f): 年龄: 选科(文w 理l): 联系电话(没有请添0):\n"); scanf("%ld %s %c %d %c %s",&p->xuehao,p->xingming,&p->xingbie,&p->nianling,&p->xueke,p->lianxidianhua); printf("输入成绩:\n"); if(p->xueke=='l') { printf("语文: 数学: 英语: 物理: 化学: 生物:\n"); scanf("%f %f %f %f %f %f",&p->chengji.yuwen,&p->chengji.shuxue,&p->chengji.yingyu,&p->chengji.wuli,&p->chengji.huaxue,&p->chengji.shengwu); p->chengji.zhengzhi=-1,p->chengji.lishi=-1,p->chengji.dili=-1; }else{ printf("语文: 数学: 英语: 政治: 历史: 地理:\n"); scanf("%f %f %f %f %f %f",&p->chengji.yuwen,&p->chengji.shuxue,&p->chengji.yingyu,&p->chengji.zhengzhi,&p->chengji.lishi,&p->chengji.dili); p->chengji.wuli=-1,p->chengji.huaxue=-1,p->chengji.shengwu=-1; } printf("确定输入内容?(是1 否0):"); scanf("%d",&caozuo); if(!caozuo) goto chongshu; if(p2!=NULL) { while(p2->next!=NULL) /*找到末尾项,在末尾添加*/ { p2=p2->next; } p2->next=p; p->next=NULL; Xs_geshu=Xs_geshu+1; return p1; }else{ Xs_geshu=Xs_geshu+1; p->next=NULL; return p; } endtianjia:; } void xiugai_shuju(struct student *p) /*修改数据的函数*/ { struct student *p1=p; unsigned long xiugai_xuehao; short int caozuo=0; printf("请输入要修改的学生的学号:"); scanf("%d",&xiugai_xuehao); while(p1!=NULL) /*找到要修改的数据项*/ { if(p1->xuehao==xiugai_xuehao) break; p1=p1->next; } if(p1!=NULL) { chongshu:; printf("重新输入该学生的数据:\n"); printf("学号: 姓名: 性别(男m 女f): 年龄: 选科(文w 理l): 联系电话(没有请添0):\n"); scanf("%ld %s %c %d %c %s",&p1->xuehao,p1->xingming,&p1->xingbie,&p1->nianling,&p1->xueke,p1->lianxidianhua); printf("输入成绩:\n"); if(p1->xueke=='l') { printf("语文: 数学: 英语: 物理: 化学: 生物:\n"); scanf("%f %f %f %f %f %f",&p1->chengji.yuwen,&p1->chengji.shuxue,&p1->chengji.yingyu,&p1->chengji.wuli,&p1->chengji.huaxue,&p1->chengji.shengwu); p1->chengji.zhengzhi=-1,p1->chengji.lishi=-1,p1->chengji.dili=-1; }else{ printf("语文: 数学: 英语: 政治: 历史: 地理:\n"); scanf("%f %f %f %f %f %f",&p1->chengji.yuwen,&p1->chengji.shuxue,&p1->chengji.yingyu,&p1->chengji.zhengzhi,&p1->chengji.lishi,&p1->chengji.dili); p1->chengji.wuli=-1,p1->chengji.huaxue=-1,p1->chengji.shengwu=-1; } printf("确定输入内容?(是1 否0):"); scanf("%d",&caozuo); if(!caozuo) goto chongshu; }else{ printf("没有找到该学生数据,需要创建该数据吗?(是1 否0):"); scanf("%d",&caozuo); if(caozuo) tianjia_shuju(p); } } struct student *shanchu_shuju(struct student *p) /*删除数据的函数 form main()*/ { struct student *head=p,*p1=p,*p2=p; unsigned long chuming_xuehao; short int n=0; if(p!=NULL) { printf("请输入要除名的学生的学号:"); scanf("%d",&chuming_xuehao); while(p1!=NULL) /*找到要出名学号的数据项*/ { if(p1->xuehao==chuming_xuehao) break; p2=p1; p1=p1->next; n++; } if(p1!=NULL) { if(n) /*如果删除的是开头项*/ { p2->next=p1->next; free(p1); Xs_geshu=Xs_geshu-1; return p; }else{ /*删除的是后面项*/ Xs_geshu=Xs_geshu-1; p2=p1->next; free(p1); return p2; } }else{ printf("没有找到该学生!\n"); return p; } }else{ printf("数据库中没有学生了!\n"); return NULL; } } void tongji_shuju(struct student *p) /*统计学生数据的函数 form main()*/ { struct student *p1=p; short int caozuo,i=0,j=0; float xs_zongfen[MAX_GESHU]={0};/*学生的统计数据*/ float xs_fangcha(struct student *p,float zongfen); short int xs_paiming[MAX_GESHU]={0}; float cj_pingjunfen[9]={0},cj_zongpingjunfen=0;/*成绩统计数据*/ short int cj_geshu[9]={0}; play:; if(p!=NULL) { printf("查看学生统计数据请输入1,查看各课成绩统计数据输入2,返回上一级输入0\n"); scanf("%d",&caozuo); switch(caozuo) { case 1: break; case 2: goto kc_tongji;break; case 0: goto endtongji;break; default :goto endtongji; } i=0; j=0; while(1) /*记录各个学生的总成绩*/ { if(p1->xueke=='l') { xs_zongfen[i]+=p1->chengji.yuwen+p1->chengji.shuxue+p1->chengji.yingyu+p1->chengji.wuli+p1->chengji.huaxue+p1->chengji.shengwu; }else{ xs_zongfen[i]+=p1->chengji.yuwen+p1->chengji.shuxue+p1->chengji.yingyu+p1->chengji.zhengzhi+p1->chengji.lishi+p1->chengji.dili; } if(p1->next==NULL) break; p1=p1->next; i++; } for(i=0;ij) xs_paiming[i]++; } } } p1=p; i=0; printf("============================%d个学生的统计数据============================\n",Xs_geshu); printf("学号: 姓名: 平均分: 总分: 方差: 排名:\n"); while(1) { printf("%-7ld%-15s%-9.2f%-7.1f%-9.2f%-7d\n",p1->xuehao,p1->xingming,xs_zongfen[i]/6,xs_zongfen[i],xs_fangcha(p1,xs_zongfen[i]),xs_paiming[i]); if(p1->next==NULL) break; p1=p1->next; i++; } /*归零操作*/ p1=p; caozuo=0,i=0,j=0; cj_zongpingjunfen=0; for(i=0;ichengji.yuwen;cj_geshu[0]++; cj_pingjunfen[1]+=p1->chengji.shuxue;cj_geshu[1]++; cj_pingjunfen[2]+=p1->chengji.yingyu;cj_geshu[2]++; if(p1->chengji.wuli!=-1) {cj_pingjunfen[3]+=p1->chengji.wuli;cj_geshu[3]++;} if(p1->chengji.huaxue!=-1) {cj_pingjunfen[4]+=p1->chengji.huaxue;cj_geshu[4]++;} if(p1->chengji.shengwu!=-1) {cj_pingjunfen[5]+=p1->chengji.shengwu;cj_geshu[5]++;} if(p1->chengji.zhengzhi!=-1) {cj_pingjunfen[6]+=p1->chengji.zhengzhi;cj_geshu[6]++;} if(p1->chengji.lishi!=-1) {cj_pingjunfen[7]+=p1->chengji.lishi;cj_geshu[7]++;} if(p1->chengji.dili!=-1) {cj_pingjunfen[8]+=p1->chengji.dili;cj_geshu[8]++;} if(p1->next==NULL) break; p1=p1->next; } for(i=0;i<9;i++) cj_zongpingjunfen+=cj_pingjunfen[i]; /*统计总共的成绩*/ printf("============================9门课程的统计数据============================\n"); printf(" 语文: 数学: 英语: 物理: 化学: 生物: 政治: 历史: 地理:\n"); printf("平均分: "); for(i=0;i<9;i++) printf("%-7.2f",cj_pingjunfen[i]/cj_geshu[i]); if(cj_geshu[3]==0||cj_geshu[6]==0) printf("\n六门课程的总平均分:%7.2f\n",cj_zongpingjunfen/6); else printf("\n九门课程的总平均分:%7.2f\n",cj_zongpingjunfen/9); }else{ printf("数据库中没有任何数据!\n"); goto endtongji; } /*归零操作*/ p1=p; caozuo=0,i=0,j=0; cj_zongpingjunfen=0; for(i=0;ixueke=='l') { s+=pow((p->chengji.yuwen-zongfen/6),2)+pow((p->chengji.shuxue-zongfen/6),2)+pow((p->chengji.yingyu-zongfen/6),2); s+=pow((p->chengji.wuli-zongfen/6),2)+pow((p->chengji.huaxue-zongfen/6),2)+pow((p->chengji.shengwu-zongfen/6),2); }else{ s+=pow((p->chengji.yuwen-zongfen/6),2)+pow((p->chengji.shuxue-zongfen/6),2)+pow((p->chengji.yingyu-zongfen/6),2); s+=pow((p->chengji.zhengzhi-zongfen/6),2)+pow((p->chengji.lishi-zongfen/6),2)+pow((p->chengji.dili-zongfen/6),2); } return s/6; } struct student *paixu_shuju(struct student *p)/*对数据库的排序所调用的函数 form main()*/ { short int caozuo=0; struct student *xuehao_paixu(struct student *p); /*对学号进行排序的函数*/ struct student *xingming_paixu(struct student *p); /*对姓名进行排序的函数*/ struct student *paiming_paixu(struct student *p); /*对成绩行进排序的函数*/ struct student *(*hanshu)(struct student *); /*指针函数,储存以上不同函数的入口*/ if(p!=NULL) /*不对空数据进行排序*/ { printf("按学号请输入1,按姓名请输入2,按成绩排序请输入3,返回上一级请输入0\n"); scanf("%d",&caozuo); switch(caozuo) { case 1: hanshu=xuehao_paixu;return (*hanshu)(p); case 2: hanshu=xingming_paixu;return (*hanshu)(p); case 3: hanshu=paiming_paixu;return (*hanshu)(p); default : break; } }else{ printf("没有任何数据!\n"); } return p; } struct student *xuehao_paixu(struct student *p)/*按照学号对数据库排序 form *paixu_shuju()*/ { struct student *p1=p; struct student *shuju[MAX_GESHU],*jiezhi; short int caozuo=0,i,j,n; printf("正排请输入1,反排请输入2:"); scanf("%d",&caozuo); for(i=0,n=1;1;i++,n++) /*将各个学生结构体地址录入指针数组*/ { shuju[i]=p1; if(p1->next==NULL) break; p1=p1->next; } if(caozuo==2) goto fanpai; for(i=0;ixuehao>(*(shuju+j))->xuehao) { jiezhi=*(shuju+i); *(shuju+i)=*(shuju+j); *(shuju+j)=jiezhi; } } } goto lianjie; fanpai:; for(i=0;ixuehao<(*(shuju+j))->xuehao) { jiezhi=*(shuju+i); *(shuju+i)=*(shuju+j); *(shuju+j)=jiezhi; } } } lianjie:; for(i=0;inext=*(shuju+i+1); /*排序完后连接各个接口*/ (*(shuju+i))->next=NULL; return *shuju; } struct student *xingming_paixu(struct student *p)/*按照姓名对数据库排序 form *paixu_shuju()*/ { struct student *p1=p; struct student *shuju[MAX_GESHU],*jiezhi; short int caozuo=0,i,j,n; printf("正排请输入1,反排请输入2:"); scanf("%d",&caozuo); for(i=0,n=1;1;i++,n++) /*将各个接口录入指针数组*/ { shuju[i]=p1; if(p1->next==NULL) break; p1=p1->next; } if(caozuo==2) goto fanpai; for(i=0;ixingming,(*(shuju+j))->xingming)>0) { jiezhi=*(shuju+i); *(shuju+i)=*(shuju+j); *(shuju+j)=jiezhi; } } } goto lianjie; fanpai:; for(i=0;ixingming,(*(shuju+j))->xingming)<0) { jiezhi=*(shuju+i); *(shuju+i)=*(shuju+j); *(shuju+j)=jiezhi; } } } lianjie:; for(i=0;inext=*(shuju+i+1); /*连接各个接口*/ (*(shuju+i))->next=NULL; return *shuju; } struct student *paiming_paixu(struct student *p) /*按成绩排序数据 form *paixu_shuju()*/ { struct student *p1=p; float zongfen[MAX_GESHU]={0},fenshu; struct student *shuju[MAX_GESHU],*jiezhi; short int caozuo,i,j,n; for(i=0,n=1;1;i++,n++) /*各个接口录入指针数组*/ { shuju[i]=p1; if(p1->next==NULL) break; p1=p1->next; } i=0; p1=p; while(1) /*统计各个学生的总成绩*/ { if(p1->xueke=='l') { zongfen[i]+=p1->chengji.yuwen+p1->chengji.shuxue+p1->chengji.yingyu+p1->chengji.wuli+p1->chengji.huaxue+p1->chengji.shengwu; }else{ zongfen[i]+=p1->chengji.yuwen+p1->chengji.shuxue+p1->chengji.yingyu+p1->chengji.zhengzhi+p1->chengji.lishi+p1->chengji.dili; } if(p1->next==NULL) break; i++; p1=p1->next; } printf("正排请输入1,反排请输入2:"); scanf("%d",&caozuo); if(caozuo==2) goto fanpai; for(i=0;izongfen[j]) { jiezhi=*(shuju+i); *(shuju+i)=*(shuju+j); *(shuju+j)=jiezhi; fenshu=zongfen[i]; zongfen[i]=zongfen[j]; zongfen[j]=fenshu; } } } goto lianjie; fanpai:; for(i=0;inext=*(shuju+i+1); /*连接各个借口*/ (*(shuju+i))->next=NULL; return *shuju; } ...展开收缩
(系统自动生成,下载前可以参看下载内容)
下载文件列表
相关说明
- 本站资源为会员上传分享交流与学习,如有侵犯您的权益,请联系我们删除.
- 本站是交换下载平台,提供交流渠道,下载内容来自于网络,除下载问题外,其它问题请自行百度。
- 本站已设置防盗链,请勿用迅雷、QQ旋风等多线程下载软件下载资源,下载后用WinRAR最新版进行解压.
- 如果您发现内容无法下载,请稍后再次尝试;或者到消费记录里找到下载记录反馈给我们.
- 下载后发现下载的内容跟说明不相乎,请到消费记录里找到下载记录反馈给我们,经确认后退回积分.
- 如下载前有疑问,可以通过点击"提供者"的名字,查看对方的联系方式,联系对方咨询.