学生籍贯信息记录簿系统课程设计源代码
- 格式: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++;//为后面的一共文件里存了多少人的数据做累加,求人员个数。
学院程序设计工程训练报告C语言程序设计学生籍贯信息记录簿课程名称C语言程序设计工程训练姓名院(系)信息科学与技术学院专业班级学号指导教师教务处制目录1 需求分析 (1)2 系统总框图和功能模块说明 (1)2.1 系统总框图 (1)2.2 功能模块说明 (2)3 系统设计 (2)3.1 主要结构体 (2)3.2主要功能函数 (2)3.3 关键函数的流程图 (3)4 系统调试 (4)5 总结 (6)6 源程序清单 (8)1 需求分析编制一个学生籍贯信息记录簿,每个学生信息包括:学号、姓名、籍贯。
具体功能:1、创建信息链表并以磁盘文件保存2、读取磁盘文件并显示输出所有学生的籍贯信息3、按学号或姓名查询其籍贯4、按籍贯查询并输出该籍贯的所有学生5、能添加、删除和修改学生的籍贯信息6、系统以菜单方式工作2 系统总框图和功能模块说明2.1 系统总框图图1 系统总框图2.2 功能模块说明系统初始化模块:完成系统初始化。
创建信息链表模块:在本地创建学生籍贯文件,保存学生籍贯信息。
输入学生信息模块:完成学生籍贯信息的录入。
修改学生信息模块:完成学生籍贯信息的修改。
查询学生信息模块:完成学生籍贯信息的查询。
删除学生信息模块:完成学生籍贯信息的删除。
重置学生信息模块:完成学生籍贯信息的重置。
保存学生信息模块:完成学生籍贯信息的保存。
3 系统设计3.1 主要结构体学生信息:学号、姓名、籍贯typedef struct{ short zhku_status;char zhku_number[12];char zhku_name[10];char zhku_address[20];}StuType;3.2主要功能函数void zhku_AddData(void) /*录入数据*/void wxw_ListData(void) /*显示所有数据*/void wp_Delete(void) /*做删除标记*/void wp_Pack(void) /*重置信息*/ void zhku_UpdateData(void) /*修改*/void SH_Search(void) /*查询*/3.3 关键函数的流程图4 系统调试打开程序后按任意键,将会出现上述界面。
目录1 设计内容及要求 (1)1.1 课程设计要求 (1)1.2 学生籍贯管理系统的要求 (1)2 程序设计环境及设计思想 (1)2.1 软件设计环境 (1)2.2 设计思想 (1)3 数据保存方式以及格式 (2)4 模块的调用、划分与功能图 (2)4.1 各软件模块之间的调用方式 (2)4.2 系统完成功能 (2)4.3 功能框图显示 (3)5 界面设计 (3)5.1 学生籍贯管理系统公共数据结构 (7)6 小结 (7)参考文献 (8)附录:程序源代码 (9)1 设计内容及要求1.1 课程设计要求1. 要求利用C语言面向过程的编程思想来完成系统的设计;2. 突出C语言的函数特征,以多个函数实现每一个子功能;3. 画出功能模块图;4. 进行简单界面设计,能够实现友好的交互;5. 具有清晰的程序流程图和数据结构的详细定义;6. 熟练掌握C语言对文件的各种操作。
1.2 学生籍贯管理系统的要求该程序应该具有下列功能:(1)输入学生信息并以磁盘文件保存;(2)读取磁盘文件并显示输出所有学生的籍贯信息;(3)按学号或姓名查询其籍贯;(4)按籍贯查询并输出该籍贯的所有学生;(5)能添加、删除和修改学生的籍贯信息;(6)显示输出天津籍和非天津籍学生的信息并可分别存盘;2 程序设计环境及设计思想2.1 软件设计环境Microsoft Visual C++ 6.02.2 设计思想该程序运用了结构体数组的输入,输出,修改及存储,采用循环的方式对程序进行编写,同时也采用循环的方式对程序进行输入、显示、查询、检索、删除、编辑等操作。
实现编程的意义。
3 数据保存方式以及格式本学生信息系统将能自动把输入的学生信息保存为C://data .txt文件中,在文件的读取时,系统将能自动把该二进制文件读出,并在屏幕上显示出学生信息。
前提是必须在C盘中创建data.txt文件。
4 模块的调用、划分与功能图4.1 各软件模块之间的调用方式程序中各个模块之间的调用方式主要是通过函数的调用实现的。
目录1 设计目的 (2)2 功能描述 (3)2.1模块功能 (3)2.1.1 添加功能 (3)2.1.2 删除功能 (3)2.1.3 查询功能 (3)2.2流程图........................................... 错误!未定义书签。
3 总体设计 (9)3.1 功能模块设计 (10)3.2 数据结构设计 (10)3.3 函数功能描述 (10)3.3.1 #include <stdio.h> (11)3.3.2 #include<ctype.h> (11)3.3.3#include<string.h> (11)3.3.4 #include<stdlib.h> (11)4 程序实现 (12)4.1 源码分析 (12)4.2 运行结果 (13)5总结 (17)C语言课程设计学生籍贯信息记录1.设计要求:基本功能①可以存储学生信息;②按学号和姓名查找该学生的籍贯;③按籍贯可以查询所有学生的信息;④可以对学生的信息加以修改;⑤可以删除学生的信息;拓展功能a)写入文件b)读取文件创新(自拟)功能:程序实现的其它功能由个人自拟。
2.设计要求具体说明学生籍贯信息包括:学号、姓名、省份,县市名称。
试设计一学生籍贯信息管理,使之能提供以下功能:1) 系统以菜单方式工作(用键盘输入 1~8 之间的数来选择功能,其中 8 为退出);2) 学生籍贯信息录入功能(包括学号、姓名、省份、县市名称);3) 学生籍贯信息整体浏览功能;4) 按学号查询学生籍贯信息;5) 按省份查询统计学生人数信息;6) 按照学号查询修改学生信息;7) 按照输入的学号信息的删除学生籍贯记录信息。
8) 根据“省份”由小到大排序。
题目要求1)按分析、设计、编码、调试和测试的软件开发过程完成这个应用程序。
2) 为各项操作功能设计一个菜单。
应用程序运行后,先显示这个菜单,然后用户通过菜单项选择希望进行的操作项目。
#include”stdio。
h”#include"conio。
h”#include"stdlib。
h”#include”string。
h"#define N 1000 //N为可输入的学生总人数,可根据需要更改#define M 2 //M为宏定义的(在创建密码函数中)可建立的登陆用户个数,可更改struct student //定义学生信息结构体数组{char num[9]; //学号char name[20]; //姓名char depar[15]; //院系char zhuanye[15];//专业char classes[5]; //班级char age[3];//年龄char sex[4]; //性别char nation[5]; //民族char birth[9]; //出生日期char add[10];//籍贯};struct code //定义密码结构体数组{char name[20];char code[7];}co[M],s0;//确认是否新创建密码文件模块int code(){FILE *fp;if((fp=fopen("学生学籍管理系统__code。
txt","rt"))==NULL){printf(”密码文件不存在,请输入新的用户名及密码:\n");//若不存在此密码文件,则提示用户创建密码printf("请输入任意键继续!”);getch();system("cls");return 1; //无密码文件返回1 }elsereturn 0; //已有密码文件返回0 }//新创建初始密码void code_input(){FILE *fp;int i;if((fp=fopen(”学生学籍管理系统__code。
txt”,"wt"))==NULL);//当建立密码文件成功时,进入for循环for(i=0;i〈M;i++) //M为宏定义的可建立的登陆用户个数,可更改{printf("请录入第%d个用户名:",i+1);//创建不同的用户名及密码scanf(”%s",co[i]。
#include "stdafx.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(" 1. 录入学生籍贯信息\n\n");printf(" 2. 查编学生籍贯信息\n\n");printf(" 3. 删除学生籍贯信息\n\n");printf(" 4. 退出程序\n\n");printf(" 请您选择1-4:");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;}。
计算机科学与技术系课程设计报告2012~2013 学年第1学期课程C语言课程设计课程设计名称学生籍贯信息记录簿设计学生学号专业班级指导教师目录一、绪言——需求分析……………………二、系统设计……………………………(一)设计思想…………………………(二)源程序设计…………………………(三)、设计表示……………………………三、系统调试………………………………四、学生籍贯记录薄使用说明…………………五、总结……………………………………六、参考文献……………………………………一、绪言——需求分析随着学校办学规模的不断扩大、办学层次的多样化、在校生的不断增多。
开发这系统可以是教务处老师减轻工作压力,比较系统的对学生进行管理,加快速度、加强管理,使各项管理更加规化。
题目要求设计一个学生籍贯信息记录簿系统,该系统要求对学生籍贯信息进行管理和维护。
要求为:(1)创建信息链表并以磁盘文件保存;(2)读取磁盘文件并显示输出所有学生的籍贯信息;(3)按学号或查询其籍贯;(4)按籍贯查询并输出该籍贯的所有学生;(5)能添加、删除和修改学生的籍贯信息(可选项)。
二、系统设计(一)设计思想:流程图(二)、源程序设计#include<stdio.h> ///宏定义函数#include<stdlib.h> //串操作及存操作函数#include<string.h> /////调用系统函数typedef struct student ////定义新结构体student {char name[10]; /*定义*/int num; /*定义学号*/char sex[10]; /*定义性别*/int age; /*定义年龄*/char location[10]; /*定义籍贯*/}s;void Fun(){char ch1;/*定义字符*/printf("继续操作?\n\t——输入Y继续操作/N退出系统[不区分大小写]\n"); scanf("%s",&ch1); /*接收字符*/switch(ch1) /*选择结构*/{case 'Y':case 'y':break;case 'N':case 'n':printf("欢迎您再次使用。
#include"comnirecord.h"#include"iostream.h"#include"fcntl.h"#include"errno.h"#define FILENAME1 "sichuan.txt"#define FILENAME2 "feisichuan.txt"void menu(){cout<<" [1]----------添加"<<endl;cout<<" [2]----------删除"<<endl;cout<<" [3]----------修改"<<endl;cout<<" [4]----------按学号查询"<<endl;cout<<" [5]----------按姓名查询"<<endl;cout<<" [6]----------按籍贯查询"<<endl;cout<<" [7]----------显示"<<endl;cout<<" [8]----------退出"<<endl;cout<<" 请选择要进行的操作:"<<endl;}void main(){int mu;cout<<"----------------------------------------"<<endl<<endl;cout<<"*****欢迎使用学生籍贯信息记录簿系统*****"<<endl<<endl;cout<<"----------------------------------------"<<endl;menu();cin>>mu;info inform;inform.studentID=new char[10];=new char[10];inform.province=new char[10];FILE* fh=fopen(FILENAME1,"r+");FILE* fh2=fopen(FILENAME2,"r+");if (fh==NULL||fh2==NULL){perror(FILENAME1);return;}comnirecord a(fh);//a是从四川籍的用户的链表comnirecord b(fh2);//b是从非四川籍的用户的链表while (mu!=8){switch (mu){case 1:cout<<"请输入你要添加的用户的信息:"<<endl;cout<<"请输入你要添加的用户的学号:"<<endl;cin>>inform.studentID;cout<<"请输入你要添加的用户的姓名:"<<endl;cin>>;cout<<"请输入你要添加的用户的籍贯:"<<endl;cin>>inform.province;if (strcmp(inform.province,"四川")==0){a.Insert(a.Getn()-1,inform.studentID,,inform.province);}elseb.Insert(b.Getn()-1,inform.studentID,,inform.province);break;case 2:cout<<"请输入你要删除的用户的学号:"<<endl;cin>>inform.studentID;if(!(a.Delete(inform.studentID)||b.Delete(inform.studentID))){cout<<"删除失败!未找到该学号的用户!"<<endl;}break;case 3:cout<<"请输入你要修改的用户的学号:"<<endl;cin>>inform.studentID;if(!(a.Delete(inform.studentID)||b.Delete(inform.studentID))){cout<<"修改失败!未找到该学号的用户!"<<endl;}else{cout<<"请输入你要修改的用户修改后的信息:"<<endl;cout<<"修改后的学号:";cin>>inform.studentID;cout<<"修改后的姓名:";cin>>;cout<<"修改后的籍贯:";cin>>inform.province;if (strcmp(inform.province,"四川")==0){a.Insert(a.Getn()-1,inform.studentID,,inform.province);}elseb.Insert(b.Getn()-1,inform.studentID,,inform.province);}break;case 4:cout<<"请输入要查询的用户的学号:"<<endl;cin>>inform.studentID;if (!(a.SearchID(inform.studentID)||b.SearchID(inform.studentID))){cout<<"未找到该学号的用户!"<<endl;}break;case 5:cout<<"请输入要查询的用户的姓名:"<<endl;cin>>;if (!(a.SearchNam()||b.SearchNam())){cout<<"未找到该姓名的用户!"<<endl;}break;case 6:cout<<"请输入要查询的用户的籍贯:"<<endl;cin>>inform.province;if (!(a.SearchPro(inform.province)||b.SearchPro(inform.province))){cout<<"未找到该籍贯的用户!"<<endl;}break;case 7:a.Display();b.Display();break;default:cout<<"输入有错,请重输!"<<endl;break;}menu();cin>>mu;}delete[]inform.studentID;delete[];delete[]inform.province;fclose(fh);FILE* fg=fopen(FILENAME1,"w+");FILE* fg2=fopen(FILENAME2,"w+");a.WriteInFile(fg);b.WriteInFile(fg2);}2、comnirecord头文件:#include"iostream.h"#include"string.h"#include"stdio.h"class comnirecord;struct info{char * studentID;char * name;char * province;friend comnirecord;};class Node{info element;Node * link;friend comnirecord;};class comnirecord{public:comnirecord(FILE * fp);~comnirecord();bool Insert(int i,char * stuID,char * nam,char * prov);//存取void Display(info x);//显示void Display();bool Delete(char * stuID);// 按学号删除bool SearchID(char * stuID);//按学号查询bool SearchNam(char * nam);//按姓名查询bool SearchPro(char * prov);//按籍贯查询bool WriteInFile(FILE * fp);int Getn();private:bool SearchID(char * stuID,info & x)const;bool SearchNam(char * nam,info & x)const;bool SearchPro(char * prov,Node * &x)const;Node * first;int n;};int comnirecord::Getn(){return n;}comnirecord::comnirecord(FILE * fp){n=0;first=NULL;int count=-1;int q[3];int k1,k2,k3;char * s=new char[30];while (fgets(s,30,fp)!=NULL){Node * p=new Node;int j=0;for (int i=0;s[i]!='\0';i++)//可以考虑中间是用","隔开的情况{if (s[i]==' '&&j<=2){q[j]=i;j++;}}p->element.studentID=new char[q[0]+1];p->=new char[q[1]-q[0]];p->element.province=new char[q[2]-q[1]];k1=sprintf(p->element.studentID,"%c",s[0]);for (i=1;i<q[0];i++){k1+=sprintf(p->element.studentID+k1,"%c",s[i]);}k2=sprintf(p->,"%c",s[q[0]+1]);for (i=q[0]+2;i<q[1];i++){k2+=sprintf(p->+k2,"%c",s[i]);}k3=sprintf(p->element.province,"%c",s[q[1]+1]);for (i=q[1]+2;i<q[2];i++){k3+=sprintf(p->element.province+k3,"%c",s[i]);}Insert(count,p->element.studentID,p->,p->element.province);count++;delete[]s;s=new char[30];}delete [] s;}comnirecord::~comnirecord(){Node *p;while (first){p=first->link;delete first->element.studentID;// 是否需要??delete first->;delete first->element.province;delete first;first=p;}}bool comnirecord::Insert(int i,char * stuID,char * nam,char * prov){if(i<-1||i>n-1){cout<<"out of bounds!"<<endl;cout<<"录取失败!"<<endl;return false;}Node * q=new Node;q->element.studentID=new char[strlen(stuID)+1];strcpy(q->element.studentID,stuID);q->=new char[strlen(nam)+1];strcpy(q->,nam);q->element.province=new char[strlen(prov)+1];strcpy(q->element.province,prov);Node * p=first;for (int j=0;j<i;j++) p=p->link;if (i>-1){q->link=p->link;p->link=q;}else{q->link=first;first=q;}n++;return true;}bool comnirecord::Delete(char * stuID){if(!n){cout<<"underflow"<<endl; return false;}Node * p=first;Node * q=first;for (int j=0;j<n&&strcmp(p->element.studentID,stuID)!=0;j++){q=p;p=p->link;}if (!p){//cout<<"未找到该学号的学生信息!"<<endl;return false;}if (p==first){first=first->link;}else{p=q->link;q->link=p->link;}delete []p->element.studentID;delete []p->;delete []p->element.province;delete []p;n--; return true;}bool comnirecord::SearchID(char * stuID){info x;bool a=SearchID(stuID,x);if (a){Display(x);}return a;}bool comnirecord::SearchID(char * stuID,info & x)const{Node * p=first;for (int j=0;j<n&&strcmp(p->element.studentID,stuID)!=0;j++) p=p->link;if (!p){//cout<<"未找到该学号的学生信息!"<<endl;return false;}x.studentID=newchar[strlen(p->element.studentID)+1];strcpy(x.studentID,p->element.studentID);=new char[strlen(p->)+1];strcpy(,p->);x.province=newchar[strlen(p->element.province)+1];strcpy(x.province,p->element.province);return true;}bool comnirecord::SearchNam(char * nam){info x;bool a=SearchNam(nam,x);if (a){Display(x);}return a;}bool comnirecord::SearchNam(char * nam,info & x)const {Node * p=first;。
+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;}。