学生籍贯信息记录簿系统课程设计源代码
- 格式:doc
- 大小:71.00 KB
- 文档页数:17
程序设计--学生籍贯信息记录簿一、需求分析为了方便管理和查询,需要对全体学生的籍贯信息进行记录和统计。
本系统需要满足以下功能要求:1. 记录学生的籍贯信息,包括省、市、县/区。
2. 可以查询某个省、市、县/区的学生人数及比例。
3. 可以查看某个学生的详细信息,包括学号、姓名、性别、身份证号、电话号码等。
二、概要设计本系统采用MVC架构,前端使用HTML+CSS+Javascript,后端使用Java语言和MySQL数据库实现。
1. 数据库设计数据库中包含两个表:学生表和籍贯表。
学生表包含学生的基本信息,籍贯表包含省、市、县/区的信息。
学生表字段如下:| 字段名 | 类型 | 说明 || ---------- | ------ | -------- || id | int | 主键 || name | varchar(20) | 姓名 || gender | int | 性别(0: 男, 1: 女) || id_card | varchar(18) | 身份证号码 || phone_num | varchar(11) | 电话号码 || province_id | int | 省id || city_id | int | 市id || county_id | int | 县/区id |2. 功能实现实现方法:1. 添加学生信息用户在前端输入学生信息,包括姓名、性别、身份证号码、电话号码和籍贯信息,点击保存按钮后将学生信息插入数据库中。
2. 查询某个省、市、县/区的学生人数及比例用户在前端选择省、市、县/区,点击查询按钮后,后端计算该地区的学生人数及比例,将结果在前端显示。
3. 查看某个学生的详细信息三、详细设计省、市、县/区的信息分别封装在Province、City和County类中。
学生信息封装在Student类中。
Province:public class Province {private int id;private String name;// getter和setter方法}City:Student:public class Student {private int id;private String name;private int gender;private String id_card;private String phone_num;private Province province;private City city;private County county;2. DAO层设计数据访问层(DAO)通过封装SQL查询语句,对数据库进行操作。
#include "stdio.h"#include "stdlib.h"#include "conio.h"#include "string.h"#define N 20struct student//结构体,用于存储学生的籍贯信息{char studentID[20];char name[20];char sex[20];char age[20];char province[20];};void Menu1(){puts("\t\t-----欢迎进入学生籍贯信息记录簿系统-----");puts("\t\t 1----添加学生籍贯信息");puts("\t\t 2----显示学生籍贯信息");puts("\t\t 3----删除学生籍贯信息");puts("\t\t 4----修改学生籍贯信息");puts("\t\t 5----查询系统");puts("\t\t 6----退出");puts("\t\t 请选择……");}void Menu2(){puts("\t\t-----欢迎进入学生籍贯查询子系统-----");puts("\t\t 1---按姓名查询");//按学号或姓名查询其籍贯;puts("\t\t 2---按学号查询");puts("\t\t 3---按籍贯查询");//按籍贯查询并输出该籍贯的所有学生;puts("\t\t 4---返回");puts("\t\t 请选择……");}int reads(struct student stu[N]) // 读取文件中的内容{FILE *fp;int i=0;if((fp=fopen("学生籍贯信息记录簿.txt","r"))==NULL){printf("文件打开失败!\n");return 0;}else{for(i=0;!feof(fp);i++)fscanf(fp,"%s %s %s %s %s\n",stu[i].studentID,stu[i].name,stu[i].sex,stu[i].age,stu[i].province);}fclose(fp);return i;}void save(struct student stu[N],int n) // 学生籍贯信息改变后更新并保存文件{FILE *fp;int i=0;if((fp=fopen("学生籍贯信息记录簿.txt","w"))==NULL){printf("文件打开失败!\n");return ;}else{for(i=0;i<n;i++)fprintf(fp,"%s %s %s %s %s\n",stu[i].studentID,stu[i].name,stu[i].sex,stu[i].age,stu[i].provin ce);}fclose(fp);}void show() // 学生籍贯信息显示函数{struct student stu[N];int i,n;n=reads(stu);printf("*********************所有的学生信息如下**********************\n\n");printf(" 学号姓名性别年龄籍贯\n");printf("*************************************************************\n");for(i=0;i<n;i++)printf("%s\t%s\t\t%s\t%s\t\t%s\n",stu[i].studentID,stu[i].name,stu[i].sex,stu[i].age,stu[i].province) ;getch();}void add()/*添加学生籍贯信息*/{FILE *fp;int n,i;struct student stu;if((fp=fopen("学生籍贯信息记录簿.txt","a"))==NULL) //向文件中添加学生信息{printf("文件打开失败!\n");return;}printf("请输入要添加的学生信息数量,按回车键确认:");scanf("%d",&n);for(i=1;i<=n;i++){printf("\n请输入第%d个学生的学号、姓名,性别,年龄,籍贯,用空格分开,并按回车键确认:\n",i);scanf("%s%s%s%s%s",stu.studentID,,stu.sex,&stu.age,stu.province);fprintf(fp,"\n%s\t%s\t\t%s\t%s\t\t%s\n",stu.studentID,,stu.sex,stu.age,stu.province);}fclose(fp);}void del() /*删除学生籍贯信息*/{struct student stu[N];char number[20];int n,i,j;n=reads(stu);printf("\n请输入要删除学生信息的学号,按回车键确认:");scanf("%s",number);for(i=0;i<n;i++)if(strcmp(number,stu[i].studentID)==0) break;if(i>=n){printf("没有该学生信息!\n");return;}else{for(j=i+1;j<n;j++)stu[j-1]=stu[j];}save(stu,n-1);printf("删除成功!\n");}void change() //更改学生籍贯信息{struct student stu[N];int n,i;char number[20];printf("\n请输入要更改信息的学生学号,按回车键确认:");scanf("%s",number);n=reads(stu);for(i=0;i<n;i++)if(strcmp(number,stu[i].studentID)==0)break;if(i>=n){printf("没有该学生信息!");return;}printf("\n请输入更改后学生的学号,姓名,性别,年龄,籍贯按回车键确认:\n");scanf("%s %s %s %s %s\n",stu[i].studentID,stu[i].name,stu[i].sex,stu[i].age,stu[i].province);save(stu,n);}void find1()//按姓名查询籍贯{struct student stu[N];int n,i;char name[20];printf("\n请输入要查询的学生的姓名,按回车键确认:");scanf("%s",name);n=reads(stu);for(i=0;i<n;i++)if(strcmp(name,stu[i].name)==0)printf("该学生的籍贯为%s",stu[i].province);else if(i>=n){printf("没有该学生信息!");return;}}void find2()//按学号查询籍贯{struct student stu[N];int n,i;char xuehao[20];printf("\n请输入要查询的学生的学号,按回车键确认:");scanf("%s",xuehao);n=reads(stu);for(i=0;i<n;i++)if(strcmp(xuehao,stu[i].studentID)==0)printf("该学生的籍贯为%s",stu[i].province);else if(i>=n){printf("没有该学生信息!");return;}}//查询子函数void find3()//按籍贯查询并输出该籍贯的所有学生{struct student stu[N];int n,i;char pro[20];printf("\n请输入要查询籍贯,按回车键确认:");scanf("%s",pro);n=reads(stu);for(i=0;i<n;i++)if(strcmp(pro,stu[i].province)==0)printf("%s\t",stu[i].name);else if(i>=n){printf("无此学生信息!");return;}}void main(){int choice1,choice2;Menu1();while(12){scanf("%d",&choice1);switch(choice1){//调用子函数。
+64编制一种学生籍贯信息记录簿,每个学生信息涉及:学号、姓名、籍贯。
详细功能:(1)创立信息链表并以磁盘文献保存;(2)读取磁盘文献并显示输出所有学生籍贯信息;(3)按学号或姓名查询其籍贯;(4)按籍贯查询并输出该籍贯所有学生;(5)能添加、删除和修改学生籍贯信息;#include "dos.h"#include "stdio.h"#include "stdlib.h"#include "conio.h"#include "math.h"#include "string.h"/**********************建立链表******************************/struct hj{ int age;long number;char name[10],address[50],sex[2];struct hj *next;};/**************************文献操作函数******************************/FILE *fp;void openfile(char xx[20]){fp=fopen(xx,"ab+");if(fp==NULL)fp=fopen(xx,"wb");}/************************录入信息函数***********************************/void hjnew(void){system("cls");int n=0,xage;long xnumber;char xname[10];char xaddress[50];char xsex[2];struct hj *head;struct hj *x1,*x2;head=NULL;x2=NULL;printf("\n ★★★★★欢迎使顾客籍管理系统★★★★★\n"); printf("\n ★★★录入信息★★★\n");printf("\n 〓提示输入0返回上级菜单〓\n\n\n"); printf("\n 请输入学号【15字内】:");scanf("%ld",&xnumber);if(xnumber==0)goto haha;printf("\n 请输入姓名【10字内】:");scanf("%s",xname);printf("\n 请输入年龄【|-__-|】:"); scanf("%d",&xage);printf("\n 请输入性别【男OR女】:");scanf("%s",xsex);printf("\n 请输入籍贯【25字内】:"); scanf("%s",xaddress);while(xnumber!=0){n++;x1=(struct hj *)malloc(sizeof(struct hj));x1->number=xnumber;strcpy(x1->name,xname);strcpy(x1->sex,xsex);x1->age=xage;strcpy(x1->address,xaddress);if(n==1)head=x1;elsex2->next=x1;x2=x1;printf("\n 请输入学号【15字内】:"); scanf("%ld",&xnumber);if(xnumber==0)break;printf("\n 请输入姓名【10字内】:"); scanf("%s",xname);printf("\n 请输入年龄【|-__-|】:"); scanf("%d",&xage);printf("\n 请输入性别【男OR女】:");scanf("%s",xsex);printf("\n 请输入籍贯【25字内】:"); scanf("%s",xaddress);}x2->next=NULL;x1=head;while(x1!=NULL){openfile("hj.txt");char d[5]="四川";fwrite(x1,sizeof(struct hj),1,fp);fclose(fp);if(strstr(x1->address,d)!=NULL){openfile("schj.txt");fwrite(x1,sizeof(struct hj),1,fp);fclose(fp);}else{openfile("qthj.txt");fwrite(x1,sizeof(struct hj),1,fp);fclose(fp);}x1=x1->next;}haha:;}/*****************************查询函数*************************/void hjxmselect(void) //按学号方式查询函数{ssmmx:int n=0;long hh;system("cls");printf("\n ★★★★★欢迎使顾客籍管理系统★★★★★\n"); printf("\n ★★★查询编辑信息★★★\n");printf("\n 〓提示输入0返回上级菜单〓\n\n\n"); printf(" 请您输入学号:");scanf("%ld",&hh);if(hh!=0){struct hj *p;struct hj *q=NULL,*head=NULL;fp=fopen("hj.txt","rb");if(fp==NULL){printf("\n没有记录,请输入记录然后再查询!"); getch();goto jjx;}while(!feof(fp)){n++;p=(struct hj *)malloc(sizeof(struct hj));fread(p,sizeof(struct hj),1,fp);if(n==1)head=p;elseq->next=p;q=p;}q->next=NULL;p=head;while(p!=NULL){if(p->number==hh){int a;printf("\n 结果→ 学号=%ld 姓名=%s 年龄=%d 性别=%s ",p->number,p->name,p->age,p->sex);printf("\n 地址=%s",p->address);printf("\n\n 操作→ ⑴更改数据⑵删除数据⑶查询其她数据⑷返回上页⑸退出程序\n\n 请您选取操作:");ssmx:scanf("%d",&a);switch(a){void hjedit(struct hj *headd,struct hj *pp);void hjdelete(struct hj *headdd,struct hj *ss);case 1:hjedit(head,p);goto ssmmx;break;case 2:hjdelete(head,p);goto ssmmx;break;case 3:goto ssmmx;case 4:goto jjx;case 5:exit(0);default:printf("\n 错误选取,请重新选取:");goto ssmx;}}elsep=p->next;}int iiii=0;printf("\n 没有此记录1.重新查询2.返回上一页3.退出程序!");printf("\n 请选取:");qqqq:scanf("%d",&iiii);switch(iiii){case 1:goto ssmmx;case 2:goto jjx;case 3:exit(0);default:printf("\n 错误选取,请重新选取:");goto qqqq;}goto jjx;}jjx:;}void hjxhselect(void)//按姓名方式查询函数{ssmm:int n=0;char hh[10];system("cls");printf("\n ★★★★★欢迎使顾客籍管理系统★★★★★\n"); printf("\n ★★★查询编辑信息★★★\n");printf("\n 〓提示输入0返回上级菜单〓\n\n\n"); printf(" 请您输入姓名:");scanf("%s",hh);if(strcmp(hh,"0")!=0){struct hj *p;struct hj *q=NULL,*head=NULL;fp=fopen("hj.txt","rb");if(fp==NULL){printf("\n没有记录,请输入记录然后再查询!");getch();goto jjj;}while(!feof(fp)){n++;p=(struct hj *)malloc(sizeof(struct hj));fread(p,sizeof(struct hj),1,fp);if(n==1)head=p;elseq->next=p;q=p;}q->next=NULL;p=head;while(p!=NULL){if(strcmp(p->name,hh)==0){int a;printf("\n 结果→ 学号=%ld 姓名=%s 年龄=%d 性别=%s ",p->number,p->name,p->age,p->sex);printf("\n 地址=%s",p->address);printf("\n\n 操作→ ⑴更改数据⑵删除数据⑶查询其她数据⑷返回上页⑸退出程序\n\n 请您选取操作:");ssm:scanf("%d",&a);switch(a){void hjedit(struct hj *headd,struct hj *pp);void hjdelete(struct hj *headdd,struct hj *ss);case 1:hjedit(head,p);goto ssmm;break;case 2:hjdelete(head,p);goto ssmm;break;case 3:goto ssmm;case 4:goto jjj;case 5:exit(0);default:printf("\n 错误选取,请重新选取:");goto ssm;}}elsep=p->next;}int iii=0;printf("\n 没有此记录1.重新查询2.返回上一页3.退出程序!");printf("\n 请选取:");qqq:scanf("%d",&iii);switch(iii){case 1:goto ssmm;case 2:goto jjj;case 3:exit(0);default:printf("\n 错误选取,请重新选取:");goto qqq;}goto jjj;}jjj:;}void hjjgselect(void)//按籍贯方式查询{yyy:int i;system("cls");printf("\n ★★★★★欢迎使顾客籍管理系统★★★★★\n"); printf("\n ★★★籍贯方式查询信息★★★\n\n\n"); printf("\n 一显示所有信息\n");printf("\n 二显示四川籍所有信息\n");printf("\n 三显示其他籍所有信息\n");printf("\n 四自定义查询信息\n");printf("\n 五←返回上级菜单\n");printf("\n 六↓退出程序\n");printf("\n\n 请选取:");scanf("%d",&i);switch(i){ void zdyselect(void);void allselect(char a[8]);case 1:allselect("hj.txt");goto yyy;break;case 2:allselect("schj.txt");goto yyy;break;case 3:allselect("qthj.txt");goto yyy;break;case 4:zdyselect();case 5:break;case 6:exit(0);}}void zdyselect(void){ssmmz:int n=0,j=0;char hh[10];system("cls");printf("\n ★★★★★欢迎使顾客籍管理系统★★★★★\n"); printf("\n ★★★自定义查询信息★★★\n\n\n"); printf(" 请您输入地址核心字:");scanf("%s",hh);if(strcmp(hh,"0")!=0){struct hj *p;struct hj *q=NULL,*head=NULL;fp=fopen("hj.txt","rb");if(fp==NULL){printf("\n 没有记录,请输入记录然后再查询!");getch();goto jjz;}while(!feof(fp)){n++;p=(struct hj *)malloc(sizeof(struct hj)); fread(p,sizeof(struct hj),1,fp);if(n==1)head=p;elseq->next=p;q=p;}q->next=NULL;p=head;while(p!=NULL){if(strstr(p->address,hh)!=NULL){int a;j++;printf("\n 结果→ 学号=%ld 姓名=%s 年龄=%d 性别=%s ",p->number,p->name,p->age,p->sex);printf("\n 地址=%s",p->address);printf("\n\n 操作→ ⑴更改数据⑵删除数据⑶查询下一条数据⑷返回上页⑸退出程序\n\n 请您选取操作:");ssmz:scanf("%d",&a);switch(a){void hjedit(struct hj *headd,struct hj *pp);void hjdelete(struct hj *headdd,struct hj *ss);case 1:hjedit(head,p);goto ssmmz;break;case 2:hjdelete(head,p);goto ssmmz;break;case 3:p=p->next;continue;case 4:goto jjz;case 5:exit(0);default:printf("\n 错误选取,请重新选取:");goto ssmz;}p=p->next;}elsep=p->next;}if(j==0){printf("\n\n\n没有匹配记录按任意键继续!");getch();fclose(fp);goto ssmmz;}else{ int xx;printf("\n\n查询完毕!⑴继续查询⑵返回上一级菜单⑶退出程序");printf("\n请选取:");scanf("%d",&xx);if(xx==2)goto jjz;else if(xx==3)exit(0);}goto ssmmz;jjz:;}}void allselect(char a[8])//所有查询{int n=0;int k=0;system("cls");printf("\n ★★★★★欢迎使顾客籍管理系统★★★★★\n"); printf("\n ★★★籍贯方式信息★★★\n\n\n");struct hj *p;struct hj *q=NULL,*head=NULL;fp=fopen(a,"rb");if(fp==NULL){printf("\n对不起,没有记录无法查询!");goto xxxx;}rewind(fp);while(!feof(fp)){n++;p=(struct hj *)malloc(sizeof(struct hj));fread(p,sizeof(struct hj),1,fp);if(n==1)head=p;elseq->next=p;q=p;}q->next=NULL;struct hj *h1,*p2,*q3,*r4,*s5;h1=p2=(hj *)malloc(sizeof(struct hj));p2->next=head;while(p2->next!=NULL){q3=p2->next;r4=p2;while(q3->next!=NULL){if(q3->next->number<p2->next->number) r4=q3;q3=q3->next;}if(r4!=p2){s5=r4->next;r4->next=s5->next;s5->next=p2->next;p2->next=s5;}p2=p2->next;}head=h1->next->next;free(h1);p=head;while(p!=NULL&&n>0){n--;printf("\n学号=%ld 姓名=%s 年龄=%d 性别=%s",p->number,p->name,p->age,p->sex);printf("\n地址=%s",p->address);p=p->next;}xxxx:printf("\n→显示完毕←\n⑴↑返回上级菜单⑵↓退出程序\n请选择:"); xxx:scanf("%d",&n);switch(n){case 1:break;case 2:exit(0);default:printf("\n错误选取,请重新选取:");goto xxx;}}void hjselect(void)//查询编辑信息函数{cxbegin:int a;system("cls");printf("\n ★★★★★欢迎使顾客籍管理系统★★★★★\n"); printf("\n ★★★查询编辑信息★★★\n\n\n"); printf("\n 一按学号方式查询\n");printf("\n 二按姓名方式查询\n");printf("\n 三按籍贯方式查询\n");printf("\n 四→显示所有信息\n");printf("\n 五←返回上级菜单\n");printf("\n 请选择查询方式:");cxmm:scanf("%d",&a);switch(a){case 1:hjxmselect();goto cxbegin;break;case 2:hjxhselect();goto cxbegin;break;case 3:hjjgselect();goto cxbegin;break;case 4:allselect("hj.txt");goto cxbegin;break;case 5:break;default:printf("\n错误选取,请重新选取:");goto cxmm;}}void hjde(void)//删除界面函数{cxxbegin:int a;system("cls");printf("\n ★★★★★欢迎使顾客籍管理系统★★★★★\n"); printf("\n ★★★删除信息★★★\n\n\n");printf("\n 一按学号方式删除\n");printf("\n 二按姓名方式删除\n");printf("\n 三按籍贯方式删除\n");printf("\n 四→删除所有信息\n");printf("\n 五←返回上级菜单\n");printf("\n 请选择删除方式:");cxxmm:scanf("%d",&a);int i=0;switch(a){case 1:hjxmselect();goto cxxbegin;break;case 2:hjxhselect();goto cxxbegin;break;case 3:zdyselect();goto cxxbegin;break;case 4:fp=fopen("hj.txt","wb");if(fp!=NULL)i++;fp=fopen("schj.txt","wb");if(fp!=NULL)i++;fp=fopen("qthj.txt","wb");if(fp!=NULL)i++;if(i==3){printf("\n 所有数据已经删除敲任意键继续");getch();}goto cxxbegin;break;case 5:break;default:printf("\n错误选取,请重新选取:");goto cxxmm;}}//==============删除函数接口===============void hjdelete(struct hj *headdd,struct hj *ss){struct hj *q;char d[5]="四川";if(headdd==ss){headdd=headdd->next;goto gogo;}q=headdd;while(q!=NULL){if(q->next->number==ss->number) {break;}q=q->next;}q->next=ss->next;gogo:q=headdd;fp=fopen("hj.txt","wb");while(q!=NULL){fwrite(q,sizeof(struct hj),1,fp);q=q->next;}fclose(fp);q=headdd;fp=fopen("schj.txt","wb");while(q!=NULL){if(strstr(q->address,d)!=NULL){fwrite(q,sizeof(struct hj),1,fp);}q=q->next;}fclose(fp);q=headdd;fp=fopen("qthj.txt","wb");while(q!=NULL){if(strstr(q->address,d)==NULL){fwrite(q,sizeof(struct hj),1,fp);}q=q->next;}fclose(fp);}//===============编辑函数接口==============void hjedit(struct hj *headd,struct hj *pp) {int n=0;struct hj *p,*p1,*p2;char d[5]="四川";printf("\n 输入→ 学号="); scanf("%ld",&pp->number);printf("\n 姓名="); scanf("%s",pp->name);printf("\n 年龄="); scanf("%d",&pp->age);printf("\n 性别="); scanf("%s",pp->sex);printf("\n 地址="); scanf("%s",pp->address);p=headd;fp=fopen("hj.txt","wb");while(p!=NULL){fwrite(p,sizeof(struct hj),1,fp);p=p->next;}fclose(fp);p1=headd;fp=fopen("schj.txt","wb");while(p1!=NULL){if(strstr(p1->address,d)!=NULL){fwrite(p1,sizeof(struct hj),1,fp);}p1=p1->next;}fclose(fp);p2=headd;fp=fopen("qthj.txt","wb");while(p2!=NULL){if(strstr(p2->address,d)==NULL){fwrite(p2,sizeof(struct hj),1,fp);}p2=p2->next;}fclose(fp);}/*****************************主函数****************************************/ int main(int argc,char* argv[]){begin:int t;system("cls");printf("\n ★★★★★欢迎使顾客籍管理系统★★★★★\n\n\n\n\n");printf(" 一录入学生籍贯信息\n\n");printf(" 二查编学生籍贯信息\n\n");printf(" 三删除学生籍贯信息\n\n");printf(" 四退出程序\n\n");printf(" 请您选取:");mm:scanf("%d",&t);switch(t){case 1:hjnew();break;case 2:hjselect();break;case 3:hjde();break;case 4:exit(0);default:printf("\n 错误选取,请重新选取:");goto mm;}goto begin;return 0;}。
C语言程序设计学生籍贯信息记录簿编制一个学生籍贯信息记录簿,每个学生信息包括:学号、姓名、籍贯。
具体功能:(1)创建信息链表并以磁盘文件保存;(2)读取磁盘文件并显示输出所有学生的籍贯信息;(3)按学号或姓名查询其籍贯;(4)按籍贯查询并输出该籍贯的所有学生;(5)能添加、删除和修改学生的籍贯信息;#include<conio.h>#include<stdio.h>#include<stdlib.h>#include<string.h>#include<time.h>typedef struct{char id[12];char name[21];char origin[101];}student;FILE *fp;student stu,cache;void Menu(){system("cls");time_t t = time(0);char tmp[64];strftime(tmp, sizeof(tmp), "%Y/%m/%d %A",localtime(&t));puts(tmp);printf("\n");printf("1 --输入信息\n");printf("2 --显示所有信息\n");printf("3 --按学号查询\n");printf("4 --按姓名查询\n");printf("5 --按籍贯查询\n");printf("0 --退出\n\n\n请输入选项:");}void Creat_add(){system("cls");fp=fopen("stu_origin.dat","rb+");if(fp==NULL){fp=fopen("stu_origin.dat","wb+");if(fp==NULL){printf("can't creat the filestu_origin.dat!\n");printf("Press any key to exit...");getch();} }fseek(fp,0,SEEK_END);char next='y';while(next=='y'||next=='Y'){printf("请输入学号:");scanf("%s",stu.id);printf("请输入姓名:");scanf("%s",);printf("请输入籍贯:");scanf("%s",stu.origin);printf("\n\n确定写入数据?(y/n)");if(getch()=='y'||getch()=='Y') fwrite(&stu,sizeof(stu),1,fp);printf("\n\n是否继续输入?(y/n)");next=getch();system("cls");}fclose(fp);}void Display_all(){system("cls");fp=fopen("stu_origin.dat","rb");if(fp==NULL) {printf("can't open the file stu_origin.dat!\nPress any key to get back...");getch();}else{rewind(fp);printf("\n\n学号\t\t姓名\t\t籍贯\n");while(fread(&stu,sizeof(stu),1,fp))printf("%s\t%s\t%s\n",stu.id,,stu.origin);fclose(fp);printf("\n\nPress any key to get back...");getch();}}int Check_Id(char *Id,char c){rewind(fp);while(fread(&cache,sizeof(stu),1,fp)){if(strcmp(Id,cache.id)==0){printf("\n\n学号\t\t姓名\t\t籍贯\n");printf("%s\t%s\t%s\n",cache.id,,cache.origin);return 0;}}printf("\n\n无此学生!\n");return 1;}int Check_Name(char *Name,char c){int n=0;rewind(fp);while(fread(&cache,sizeof(stu),1,fp)){if(strcmp(Name,)==0){if(++n==1)printf("\n\n学号\t\t姓名\t\t籍贯\n");printf("%s\t%s\t%s\n",cache.id,,cache.origin);}}if(!n){printf("\n\n无此学生!\n");return 1;}return 0;}int Check_Orgin(char *Origin,char c){int n=0;rewind(fp);while(fread(&cache,sizeof(stu),1,fp)){if(strcmp(Origin,cache.origin)==0){if(++n==1)printf("\n\n学号\t\t姓名\t\t籍贯\n");printf("%s\t%s\t%s\n",cache.id,,cache.origin);}}if(!n){printf("\n\n无此学生!\n");return 1;}return 0;}void Search_id(){fp=fopen("stu_origin.dat","rb");if(fp==NULL) {printf("can't open the file stu_origin.dat!\nPress any key to get back...");getch();}char k;do{system("cls");do{printf("请输入学号:");gets(stu.id);}while(Check_Id(stu.id,'s'));printf("\n\n继续查询?(y/n)");k=getch();}while(k=='y'||k=='Y');fclose(fp);printf("\nPress any key to get back...");getch();}void Search_name(){fp=fopen("stu_origin.dat","rb");if(fp==NULL) {printf("can't open the file stu_origin.dat!\nPress any key to get back...");getch();}do{system("cls");do{printf("请输入姓名:");gets();}while(Check_Name(,'s'));printf("\n\n继续查询?(y/n)");}while(getch()=='y'||getch()=='Y');fclose(fp);printf("\nPress any key to get back...");getch();}void Search_origin(){fp=fopen("stu_origin.dat","rb");if(fp==NULL) {printf("can't open the file stu_origin.dat!\nPress any key to get back...");getch();}do{system("cls");do{printf("请输入籍贯:");gets(stu.origin);}while(Check_Orgin(stu.origin,'s'));printf("\n\n继续查询?(y/n)");}while(getch()=='y'||getch()=='Y');fclose(fp);printf("\nPress any key to get back...");getch(); }void Call(){char key=getch();if(key=='1') Creat_add();if(key=='2') Display_all();if(key=='3') Search_id();if(key=='4') Search_name();if(key=='5') Search_origin();if(key=='0') exit(1);}void main(){while(1){Menu();Call();}}该程序还不能删除和修改信息。
程序设计--学生籍贯信息记录簿-CAL-FENGHAI-(2020YEAR-YICAI)_JINGBIAN程序设计报告( 2012 /2013 学年第二学期)题目:学生籍贯信息记录簿专业学生姓名班级学号指导教师指导单位日期学生籍贯信息记录簿一、课题内容和要求编制一个学生籍贯信息记录簿,每个学生信息包括:学号、姓名、籍贯。
具体功能:(1)创建信息链表并以磁盘文件保存;(2)读取磁盘文件并显示输出所有学生的籍贯信息;(3)按学号或姓名查询其籍贯;(4)按籍贯查询并输出该籍贯的所有学生;(5)能添加、删除和修改学生的籍贯信息;(6)显示输出江苏籍和非江苏籍学生的信息并可分别存盘。
二、需求分析模块1:显示基本信息(创建信息链表并以磁盘文件保存,读取磁盘文件)模块2:输出籍贯信息(显示输出所有学生的籍贯信息)模块3:根据条件查询(按学号或姓名查询其籍贯,按籍贯查询)模块4:输出学生信息(输出该籍贯的所有学生)模块5:基本信息管理(添加、删除和修改学生的籍贯信息)模块6:分别显示存盘(显示输出江苏籍和非江苏籍学生的信息并可分别存盘)模块7:结束程序(退出系统)三、概要设计四、源程序代码#include<>#include<>#include<>#include<>#define MAX 100 取最初输入的信息并显示void Readfile(); 改第i个学生的姓名和籍贯void Save1(); 示输出江苏,非江苏学生信息void Find(int i); 学号或姓名查询籍贯void Finds(); 入信息并存档\n");printf("2.读取信息并显示\n");printf("3.按学号或姓名查询籍贯\n");printf("4.按籍贯查询学生\n");printf("5.修改(删除)指定姓名或学号的学生的姓名和籍贯\n");printf("6.显示输出江苏,非江苏学生信息\n");printf("**********************************************************\n");scanf("%s",&choose);switch(choose){case '1':{Input();Save1();}break;case '2':{Readfile();Display();}break;case '3':{Readfile();Find(1);}break;case '4':{Readfile();Finds();}break;case '5':{Readfile();Find(0);}break;case '6':{Readfile();Dis();}break;default:printf("输入错误,请重新输入:\n");}}while(1);}void Save2(int t) um,stu[t].name,stu[t].address);um);if(strcmp(stu[n].num,"Finish")==0) break;scanf("%s",stu[n].name);scanf("%s",stu[n].address);n++;}while(1);}void Save1() um,stu[i].name,stu[i].address);取信息并显示{int i;printf(" 学号姓名籍贯:\n");for(i=0;i<n;i++){printf("%5s %5s %5s\n",stu[i].num ,stu[i].name ,stu[i].address);}}void Find(int f) 学号或姓名查询籍贯{int i;int choose,k;char ans[50]; 学号查询\n");printf("2.按姓名查找\n");printf("3.返回主菜单\n");scanf("%d",&choose);if(choose==1){printf("请输入学号\n");scanf("%s",ans);k=-1;for(i=0;i<n;i++)if(strcmp(ans,stu[i].num)==0){k=i;break;}if(k==-1)printf("不存在该学生信息\n");else{if(f==1)printf("%s %s %s\n",stu[k].num,stu[k].name,stu[k].address);elseModify(k);ame)==0){k=i;break;}if(k==-1)printf("不存在该学生信息\n");else{if(f==1)printf("%s %s %s\n",stu[k].num,stu[k].name,stu[k].address);elseModify(k);改第t个学生的姓名和籍贯{int choose;int i;printf("1.删除\n");printf("2.修改\n");scanf("%d",&choose);if(choose==1){for(i=t;i<n-1;i++){stu[i]=stu[i+1];}n--;}else{printf(">>>>请重新输入该学生信息:\n");scanf("%s %s %s",stu[t].num,stu[t].name,&stu[t].address);}Save2(t); um,stu[n].name,&stu[n].address);示输出江苏,非江苏学生信息{int i;printf("江苏学生:\n");printf("学号姓名籍贯\n");for(i=0;i<n;i++){if(strcmp(stu[i].address,"江苏")==0)um,stu[i].name,stu[i].address);}}printf("\n");printf("\n");printf("非江苏学生:\n");printf("学号姓名籍贯\n");for(i=0;i<n;i++){if(strcmp(stu[i].address,"江苏")!=0){printf("%s %7s %5s\n",stu[i].num,stu[i].name,stu[i].address);}}}void Finds(){int i,k=-1;int choose;char ans[50];printf("请输入籍贯\n");scanf("%s",ans);for(i=0;i<n;i++)if(strcmp(ans,stu[i].address)==0){k=1;printf("%s %s %s\n",stu[i].num,stu[i].name,stu[i].address);}if(k=-1)printf("无此省份学生信息\n");return;}五、测试数据及其结果分析截取了调试时的图片,基本符合要求,但然后一些不人性化的地方值得修改。
学生籍贯信息记录簿设计c语言学生籍贯信息记录簿设计C语言随着教育水平的提高,学生的籍贯信息越来越重要。
籍贯信息记录簿是学生个人信息管理的一个重要组成部分,它既方便管理者查看学生人口分布情况,也方便学生查询自己的籍贯信息。
本文将介绍一个基于C语言的学生籍贯信息记录簿设计方案。
这个方案可以轻松地记录和查询学生的籍贯信息,还支持对信息进行排序和修改。
1、设计思路设计一个包含以下功能的学生籍贯信息记录簿:- 添加学生籍贯信息:输入学生的姓名和籍贯信息,将其加入记录簿中。
- 查询学生籍贯信息:按学生姓名查询学生籍贯信息。
- 修改学生籍贯信息:按学生姓名修改学生籍贯信息。
- 排序学生籍贯信息:按学生姓名或籍贯信息排序学生籍贯信息。
- 导出学生籍贯信息:将学生籍贯信息导出为文本文件。
2、数据结构设计为实现上述功能,需要以下数据结构:``` struct student { char name[20]; //学生姓名 char province[20]; //籍贯 };struct node { struct student data; //数据struct node *next; //指向下一个节点的指针 }; ```这里用链表来存储学生籍贯信息记录簿,每个节点表示一个学生的信息。
数据结构包含了学生姓名和籍贯信息,还有指向下一个节点的指针。
3、函数设计实现上述功能,需要以下函数:- `void menu()`: 显示功能菜单。
- `voidadd_node(struct node **head)`: 添加节点。
- `void search_node(struct node *head)`: 按学生姓名查询节点。
- `void modify_node(struct node *head)`: 按学生姓名修改节点。
- `void sort_node(struct node*head)`: 按学生姓名或籍贯信息排序节点。
九、源程序代码#include<iostream.h>#include<string.h>#include<fstream.h>#include<iomanip.h>//kj;lj;j;j;class population{private:int maxnum;//人口户籍编号最大值rint sno;//编号char name[20];char sex[2];int age;char birth[10];//出生日期char folk[2];//民族char mianmao[10];//政治面貌char department[10];//村组名char speciality[10];//家庭门牌号char address[30];//人口家庭详细地址public:population();~population();void enter();//户籍信息录入函数void display();//户籍信息输出函数void setsno(int temp);int getsno();char *getname();char *getspeciality();void read();void write();void change();};population::population(){}population::~population(){}int population::getsno(){return sno;}char *population::getspeciality(){return speciality;}void population::setsno(int temp){sno=temp;}char *population::getname(){return name;}void population::display(){cout<<setw(4)<<sno<<setw(4)<<name<<setw(4)<<sex<<setw(4)<<age<<setw(4)<<folk<<setw(8 )<<birth<<setw(8)<<mianmao<<setw(8)<<department<<setw(8)<<speciality<<setw(8)<<address<<e ndl;}void population::change(){char ch;cout<<" 请输入要修改人员的信息"<<endl;cout<<"*******************************************************"<<endl;cout<<"姓名是不是要改写(Y/N)"<<endl;cin>>ch;if(ch=='Y'||ch=='y'){cout<<"请输入新姓名:"<<endl;cin>>name;}cout<<"输入性别(男(n),女(m)):"<<endl;cin>>sex;if (strcmp(sex,"n")!=0&&strcmp(sex,"m")!=0){cout<<"错误请重新输入!:"<<endl;cin>>sex;}cout<<"输入年龄:"<<endl;cin>>age;while(age<1||age>=110){cout<<"错误请重新输入!"<<endl;cin>>age;}cout<<"输入出生日期:"<<endl;cin>>birth;cout<<"输入民族:"<<endl;cin>>folk;cout<<"输入政治面貌类别(党员(a),非党员(b)):"<<endl;cin>>mianmao;while(strcmp(mianmao,"a")!=0&&strcmp(mianmao,"b")!=0){cout<<"错误请重新输入!"<<endl;cin>>mianmao;}cout<<"输入村组名:"<<endl;cin>>department;cout<<"输入家庭门牌号:"<<endl;cin>>speciality;cout<<"输入家庭详细地址:"<<endl;cin>>address;cout<<"***************************************************"<<endl;cout<<"你刚刚输入的人员信息如下:"<<endl;display();}void population::enter(){ifstream tfile("max.txt",ios::binary|ios::nocreate);if(tfile){tfile.read((char *)&maxnum,sizeof maxnum);}else{maxnum=1000;//户籍编号初始化}tfile.close();sno=maxnum++;ofstream ofile("max.txt");ofile.write((char*)&maxnum,sizeof maxnum);tfile.close();cout<<"请输入人员信息"<<endl;cout<<"人员姓名:"<<endl;cin>>name;cout<<"性别(男(n),女(m)):"<<endl;cin>>sex;while(strcmp(sex,"n")!=0&&strcmp(sex,"m")!=0){cout<<"错误请重新输入!"<<endl;cin>>sex;}cout<<"出生日期:"<<endl;cin>>birth;cout<<"年龄:"<<endl;cin>>age;while(age<1||age>=110){cout<<"错误请重新输入!"<<endl;cin>>age;}cout<<"政治面貌类别(党员(a),非党员(b)):"<<endl;cin>>mianmao;while(strcmp(mianmao,"a")!=0&&strcmp(mianmao,"b")!=0) {cout<<"错误请重新输入!"<<endl;cin>>mianmao;}cout<<"民族:"<<endl;cin>>folk;cout<<"村组名:"<<endl;cin>>department;cout<<"家庭门牌号:"<<endl;cin>>speciality;cout<<"家庭详细地址:"<<endl;cin>>address;}//主程序部分:#include<iostream.h>#include<fstream.h>#include<string.h>#include<iomanip.h>#include<stdlib.h>//#include"population.h"population pop;//population 类的全局变量void read(){ifstream afile("population.txt",ios::nocreate);afile.read((char*)&pop,sizeof pop);}void write(){ofstream bfile("population.txt",ios::app);bfile.write((char*)&pop,sizeof pop);}void input(void)//录入函数{char ch;pop.enter();write();cout<<"你还要输入下一位人员的信息吗(Y/N)!"<<endl;cin>>ch;if(ch=='Y'||ch=='y'){input();}}void search()//查询函数{int j,k,i,m=0;char ch1[5],ch2[10];cout<<"请输入你的查找类型:(1.编号2.姓名3.门牌号)"<<endl;cin>>j;while(j<=0||j>=4){cout<<"错误请重新选择!"<<endl;cin>>j;}if(j==1){cout<<"请输入你要查找的人员的编号:"<<endl;cin>>i;}if(j==2){cout<<"请输入你要查找的人员的姓名:"<<endl;cin>>ch1;}if(j==3){cout<<"请输入你要查找的人员的家庭门牌号:"<<endl;cin>>ch2;}ifstream dfile("population.txt",ios::nocreate);while (dfile.good()){dfile.read((char *) &pop,sizeof pop);if(i==pop.getsno()||strcmp(pop.getname(),ch1)==0||strcmp(pop.getspeciality(),ch2)==0){cout<<"你要查找的人员信息如下:"<<endl;cout<<setw(4)<<"编号"<<setw(4)<<"姓名"<<setw(4)<<"性别"<<setw(4)<<"年龄"<<setw(4)<<"民族"<<setw(8)<<"出生日期"<<setw(8)<<"政治面貌"<<setw(8)<<"村组名"<<setw(8)<<"家庭门牌号"<<setw(8)<<"家庭详细地址"<<endl;pop.display();i=0;k=0;m=1;return;}}if(m!=1) cout<<"没有找到这名人员的信息!"<<endl;}void omit()//删除函数{int ch;cout<<"请输入要删除的人员的编号:"<<endl;cin>>ch;ifstream in("population.txt",ios::nocreate);//打开文件1,读数据ofstream out("population1.txt",ios::trunc);//打开文件写数据到文件2while(in)//循环读数据{if(in.read((char*)&pop,sizeof pop))//读后存在pop变量里,读pop这么大小if(ch!=pop.getsno())// 如果读出来的数据的pop取sno不等于刚才输入的学号,将这组数据写入文件{out.write((char*)&pop,sizeof pop);}elsecout<<"人员已成功删除!"<<endl;}in.close();//关闭文件out.close();ifstream ifile("population1.txt",ios::nocreate);//将文件2的内容弄到文件1上ofstream hfile("population.txt",ios::trunc);while(ifile){if(ifile.read((char*)&pop,sizeof pop))hfile.write((char *)&pop,sizeof pop);}ifile.close();hfile.close();}void change(){ int p=0,l=0;int ch;cout<<"请输入你要修改的人员编号:";cin>>ch;fstream efile("population.txt",ios::in|ios::out);while(efile.good()){ efile.seekg(sizeof(pop)*p);if(efile.read((char *) &pop,sizeof pop)){if(ch==pop.getsno()){pop.display();pop.change();efile.seekp(sizeof(pop)*p);efile.write((char *) &pop,sizeof pop);l++;return;}}p++;}efile.close();if(l!=1)cout<<"没有你所要修改的学生信息!"<<endl;}void output()//输出函数{int i=0;ifstream cfile("population.txt",ios::nocreate);//打开文件while(cfile)//循环读文件的数据到类或结构体里{if( cfile.read((char *)&pop,sizeof pop)){pop.display();//调用pop的成员函数打印i++;//为后面的一共文件里存了多少人的数据做累加,求人员个数。
+64编制一个学生籍贯信息记录簿,每个学生信息包括:学号、、籍贯。
具体功能:(1)创建信息链表并以磁盘文件保存;(2)读取磁盘文件并显示输出所有学生的籍贯信息;(3)按学号或查询其籍贯;(4)按籍贯查询并输出该籍贯的所有学生;(5)能添加、删除和修改学生的籍贯信息;#include "dos.h"#include "stdio.h"#include "stdlib.h"#include "conio.h"#include "math.h"#include "string.h"/**********************建立链表******************************/struct hj{ int age;long number;char name[10],address[50],sex[2];struct hj *next;};/**************************文件操作函数******************************/FILE *fp;void openfile(char xx[20]){fp=fopen(xx,"ab+");if(fp==NULL)fp=fopen(xx,"wb");}/************************录入信息函数***********************************/void hjnew(void){system("cls");int n=0,xage;long xnumber;char xname[10];char xaddress[50];char xsex[2];struct hj *head;struct hj *x1,*x2;head=NULL;x2=NULL;printf("\n ★★★★★欢迎使用户籍管理系统★★★★★\n");printf("\n ★★★录入信息★★★\n");printf("\n 〓提示输入0返回上级菜单〓\n\n\n");printf("\n 请输入学号【15字】:");scanf("%ld",&xnumber);if(xnumber==0)goto haha;printf("\n 请输入【10字】:");scanf("%s",xname);printf("\n 请输入年龄【|-__-|】:");scanf("%d",&xage);printf("\n 请输入性别【男OR女】:");scanf("%s",xsex);printf("\n 请输入籍贯【25字】:");scanf("%s",xaddress);while(xnumber!=0){n++;x1=(struct hj *)malloc(sizeof(struct hj));x1->number=xnumber;strcpy(x1->name,xname);strcpy(x1->sex,xsex);x1->age=xage;strcpy(x1->address,xaddress);if(n==1)head=x1;elsex2->next=x1;x2=x1;printf("\n 请输入学号【15字】:");scanf("%ld",&xnumber);if(xnumber==0)break;printf("\n 请输入【10字】:");scanf("%s",xname);printf("\n 请输入年龄【|-__-|】:");scanf("%d",&xage);printf("\n 请输入性别【男OR女】:");scanf("%s",xsex);printf("\n 请输入籍贯【25字】:");scanf("%s",xaddress);}x2->next=NULL;x1=head;while(x1!=NULL){openfile("hj.txt");char d[5]="";fwrite(x1,sizeof(struct hj),1,fp);fclose(fp);if(strstr(x1->address,d)!=NULL){openfile("schj.txt");fwrite(x1,sizeof(struct hj),1,fp);fclose(fp);}else{openfile("qthj.txt");fwrite(x1,sizeof(struct hj),1,fp);fclose(fp);}x1=x1->next;}haha:;}/*****************************查询函数*************************/ void hjxmselect(void) //按学号方式查询函数{ssmmx:int n=0;long hh;system("cls");printf("\n ★★★★★欢迎使用户籍管理系统★★★★★\n");printf("\n ★★★查询编辑信息★★★\n"); printf("\n 〓提示输入0返回上级菜单〓\n\n\n");printf(" 请您输入学号:");scanf("%ld",&hh);if(hh!=0){struct hj *p;struct hj *q=NULL,*head=NULL;fp=fopen("hj.txt","rb");if(fp==NULL){printf("\n没有记录,请输入记录然后再查询!");getch();goto jjx;}while(!feof(fp)){n++;p=(struct hj *)malloc(sizeof(struct hj));fread(p,sizeof(struct hj),1,fp);if(n==1)head=p;elseq->next=p;q=p;}q->next=NULL;p=head;while(p!=NULL){if(p->number==hh){int a;printf("\n 结果→ 学号=%ld =%s 年龄=%d 性别=%s ",p->number,p->name,p->age,p->sex);printf("\n 地址=%s",p->address);printf("\n\n 操作→ ⑴更改数据⑵删除数据⑶查询其他数据⑷返回上页⑸退出程序\n\n 请您选择操作:");ssmx:scanf("%d",&a);switch(a){void hjedit(struct hj *headd,struct hj *pp);void hjdelete(struct hj *headdd,struct hj *ss);case 1: hjedit(head,p);goto ssmmx;break;case 2: hjdelete(head,p);goto ssmmx;break;case 3: goto ssmmx;case 4: goto jjx;case 5:exit(0);default:printf("\n 错误的选择,请重新选择:");goto ssmx;}}elsep=p->next;}int iiii=0;printf("\n 没有此记录 1.重新查询 2.返回上一页 3.退出程序!");printf("\n 请选择:");qqqq:scanf("%d",&iiii);switch(iiii){case 1: goto ssmmx;case 2: goto jjx;case 3: exit(0);default: printf("\n 错误的选择,请重新选择:");goto qqqq;}goto jjx;}jjx:;}void hjxhselect(void)//按方式查询函数{ssmm:int n=0;char hh[10];system("cls");printf("\n ★★★★★欢迎使用户籍管理系统★★★★★\n");printf("\n ★★★查询编辑信息★★★\n");printf("\n 〓提示输入0返回上级菜单〓\n\n\n");printf(" 请您输入:");scanf("%s",hh);if(strcmp(hh,"0")!=0){struct hj *p;struct hj *q=NULL,*head=NULL;fp=fopen("hj.txt","rb");if(fp==NULL){printf("\n没有记录,请输入记录然后再查询!");getch();goto jjj;}while(!feof(fp)){n++;p=(struct hj *)malloc(sizeof(struct hj));fread(p,sizeof(struct hj),1,fp);if(n==1)head=p;elseq->next=p;q=p;}q->next=NULL;p=head;while(p!=NULL){if(strcmp(p->name,hh)==0){int a;printf("\n 结果→ 学号=%ld =%s 年龄=%d 性别=%s ",p->number,p->name,p->age,p->sex);printf("\n 地址=%s",p->address);printf("\n\n 操作→ ⑴更改数据⑵删除数据⑶查询其他数据⑷返回上页⑸退出程序\n\n 请您选择操作:");ssm:scanf("%d",&a);switch(a){void hjedit(struct hj *headd,struct hj *pp);void hjdelete(struct hj *headdd,struct hj *ss);case 1: hjedit(head,p);goto ssmm;break;case 2: hjdelete(head,p);goto ssmm;break;case 3: goto ssmm;case 4: goto jjj;case 5:exit(0);default:printf("\n 错误的选择,请重新选择:");goto ssm;}}elsep=p->next;}int iii=0;printf("\n 没有此记录 1.重新查询 2.返回上一页 3.退出程序!");printf("\n 请选择:");qqq:scanf("%d",&iii);switch(iii){case 1: goto ssmm;case 2: goto jjj;case 3: exit(0);default: printf("\n 错误的选择,请重新选择:");goto qqq;}goto jjj;}jjj: ;}void hjjgselect(void)//按籍贯方式查询{yyy:int i;system("cls");printf("\n ★★★★★欢迎使用户籍管理系统★★★★★\n");printf("\n ★★★籍贯方式查询信息★★★\n\n\n");printf("\n 一显示所有信息\n");printf("\n 二显示籍所有信息\n");printf("\n 三显示其它籍所有信息\n");printf("\n 四自定义查询信息\n");printf("\n 五←返回上级菜单\n");printf("\n 六↓退出程序\n");printf("\n\n 请选择:");scanf("%d",&i);switch(i){ void zdyselect(void);void allselect(char a[8]);case 1:allselect("hj.txt");goto yyy;break;case 2: allselect("schj.txt");goto yyy;break;case 3: allselect("qthj.txt");goto yyy;break;case 4: zdyselect();case 5: break;case 6: exit(0);}}void zdyselect(void){ssmmz:int n=0,j=0;char hh[10];system("cls");printf("\n ★★★★★欢迎使用户籍管理系统★★★★★\n");printf("\n ★★★自定义查询信息★★★\n\n\n");printf(" 请您输入地址关键字:");scanf("%s",hh);if(strcmp(hh,"0")!=0){struct hj *p;struct hj *q=NULL,*head=NULL;fp=fopen("hj.txt","rb");if(fp==NULL){printf("\n 没有记录,请输入记录然后再查询!");getch();goto jjz;}while(!feof(fp)){n++;p=(struct hj *)malloc(sizeof(struct hj));fread(p,sizeof(struct hj),1,fp);if(n==1)head=p;elseq->next=p;q=p;}q->next=NULL;p=head;while(p!=NULL){if(strstr(p->address,hh)!=NULL){int a;j++;printf("\n 结果→ 学号=%ld =%s 年龄=%d 性别=%s ",p->number,p->name,p->age,p->sex);printf("\n 地址=%s",p->address);printf("\n\n 操作→ ⑴更改数据⑵删除数据⑶查询下一条数据⑷返回上页⑸退出程序\n\n 请您选择操作:");ssmz:scanf("%d",&a);switch(a){void hjedit(struct hj *headd,struct hj *pp);void hjdelete(struct hj *headdd,struct hj *ss);case 1: hjedit(head,p);goto ssmmz;break;case 2: hjdelete(head,p);goto ssmmz;break;case 3: p=p->next;continue;case 4: goto jjz;case 5:exit(0);default:printf("\n 错误的选择,请重新选择:");goto ssmz;}p=p->next;}elsep=p->next;}if(j==0){printf("\n\n\n没有匹配的记录按任意键继续!");getch();fclose(fp);goto ssmmz;}else{ int xx;printf("\n\n查询完毕! ⑴继续查询⑵返回上一级菜单⑶退出程序");printf("\n请选择:");scanf("%d",&xx);if(xx==2)goto jjz;else if(xx==3)exit(0);}goto ssmmz;jjz: ;}}void allselect(char a[8])//全部查询{int n=0;int k=0;system("cls");printf("\n ★★★★★欢迎使用户籍管理系统★★★★★\n");printf("\n ★★★籍贯方式信息★★★\n\n\n"); struct hj *p;struct hj *q=NULL,*head=NULL;fp=fopen(a,"rb");if(fp==NULL){printf("\n对不起,没有记录无法查询!");goto xxxx;}rewind(fp);while(!feof(fp)){n++;p=(struct hj *)malloc(sizeof(struct hj));fread(p,sizeof(struct hj),1,fp);if(n==1)head=p;elseq->next=p;q=p;}q->next=NULL;struct hj *h1,*p2,*q3,*r4,*s5;h1=p2=(hj *)malloc(sizeof(struct hj));p2->next=head;while(p2->next!=NULL){q3=p2->next;r4=p2;while(q3->next!=NULL){if(q3->next->number<p2->next->number)r4=q3;q3=q3->next;}if(r4!=p2){s5=r4->next;r4->next=s5->next;s5->next=p2->next;p2->next=s5;}p2=p2->next;}head=h1->next->next;free(h1);p=head;while(p!=NULL&&n>0){n--;printf("\n学号=%ld =%s 年龄=%d 性别=%s",p->number,p->name,p->age,p->sex);printf("\n地址=%s",p->address);p=p->next;}xxxx:printf("\n→显示完毕←\n⑴↑返回上级菜单⑵↓退出程序 \n请选择:");xxx:scanf("%d",&n);switch(n){case 1:break;case 2:exit(0);default:printf("\n错误的选择,请重新选择:");goto xxx;}}void hjselect(void)//查询编辑信息函数{cxbegin:int a;system("cls");printf("\n ★★★★★欢迎使用户籍管理系统★★★★★\n");printf("\n ★★★查询编辑信息★★★\n\n\n"); printf("\n 一按学号方式查询\n");printf("\n 二按方式查询\n");printf("\n 三按籍贯方式查询\n");printf("\n 四→显示全部信息\n");printf("\n 五←返回上级菜单\n");printf("\n 请选择查询方式:"); cxmm:scanf("%d",&a);switch(a){case 1: hjxmselect();goto cxbegin;break;case 2: hjxhselect();goto cxbegin;break;case 3: hjjgselect();goto cxbegin;break;case 4: allselect("hj.txt");goto cxbegin;break;case 5: break;default:printf("\n错误的选择,请重新选择:");goto cxmm;}}void hjde(void)//删除界面函数{cxxbegin:int a;system("cls");printf("\n ★★★★★欢迎使用户籍管理系统★★★★★\n");printf("\n ★★★删除信息★★★\n\n\n"); printf("\n 一按学号方式删除\n");printf("\n 二按方式删除\n");printf("\n 三按籍贯方式删除\n");printf("\n 四→删除全部信息\n");printf("\n 五←返回上级菜单\n");printf("\n 请选择删除方式:"); cxxmm:scanf("%d",&a);int i=0;switch(a){case 1: hjxmselect();goto cxxbegin;break;case 2: hjxhselect();goto cxxbegin;break;case 3: zdyselect();goto cxxbegin;break;case 4:fp=fopen("hj.txt","wb");if(fp!=NULL)i++;fp=fopen("schj.txt","wb");if(fp!=NULL)i++;fp=fopen("qthj.txt","wb");if(fp!=NULL)i++;if(i==3){printf("\n 全部数据已经删除!!!!!!敲任意键继续");getch();}goto cxxbegin;break;case 5: break;default:printf("\n错误的选择,请重新选择:");goto cxxmm;}}//==============删除函数接口===============void hjdelete(struct hj *headdd,struct hj *ss){struct hj *q;char d[5]="";if(headdd==ss){headdd=headdd->next;goto gogo;}q=headdd;while(q!=NULL){if(q->next->number==ss->number){break;}q=q->next;}q->next=ss->next;gogo:q=headdd;fp=fopen("hj.txt","wb");while(q!=NULL){fwrite(q,sizeof(struct hj),1,fp);q=q->next;}fclose(fp);q=headdd;fp=fopen("schj.txt","wb");while(q!=NULL){if(strstr(q->address,d)!=NULL){fwrite(q,sizeof(struct hj),1,fp);}q=q->next;}fclose(fp);q=headdd;fp=fopen("qthj.txt","wb");while(q!=NULL){if(strstr(q->address,d)==NULL){fwrite(q,sizeof(struct hj),1,fp);}q=q->next;}fclose(fp);}//===============编辑函数接口============== void hjedit(struct hj *headd,struct hj *pp) {int n=0;struct hj *p,*p1,*p2;char d[5]="";printf("\n 输入→ 学号=");scanf("%ld",&pp->number);printf("\n =");scanf("%s",pp->name);printf("\n 年龄=");scanf("%d",&pp->age);printf("\n 性别=");scanf("%s",pp->sex);printf("\n 地址=");scanf("%s",pp->address);p=headd;fp=fopen("hj.txt","wb");while(p!=NULL){fwrite(p,sizeof(struct hj),1,fp); p=p->next;}fclose(fp);p1=headd;fp=fopen("schj.txt","wb");while(p1!=NULL){if(strstr(p1->address,d)!=NULL){fwrite(p1,sizeof(struct hj),1,fp);}p1=p1->next;}fclose(fp);p2=headd;fp=fopen("qthj.txt","wb");while(p2!=NULL){if(strstr(p2->address,d)==NULL){fwrite(p2,sizeof(struct hj),1,fp); }p2=p2->next;}fclose(fp);}/*****************************主函数****************************************/int main(int argc, char* argv[]){begin:int t;system("cls");printf("\n ★★★★★欢迎使用户籍管理系统★★★★★\n\n\n\n\n");printf(" 一录入学生籍贯信息\n\n");printf(" 二查编学生籍贯信息\n\n");printf(" 三删除学生籍贯信息\n\n");printf(" 四退出程序\n\n");printf(" 请您选择:");mm:scanf("%d",&t);switch(t){case 1: hjnew();break;case 2: hjselect();break;case 3: hjde();break;case 4:exit(0);default:printf("\n 错误的选择,请重新选择:"); goto mm;}goto begin;return 0;}。