1、用C语言开发简单的应用系统程序用C语言开发简单的应用系统程序,设计一个与防震、抗震救灾有关的数据管理系统 要求:界面友好,使用方便;利用结构体数组实现数据结构设计;系统具有增加,查询,插入,排序、统计等基本功能;系统的各个功能模块要求用函数的形式实现;数据用文件保存,源代码不得少于150行,必须用Turbo C2.0编程,程序应有友好的人机交互界面、完善的功能和实用性. 那位高手能帮帮忙啊!拜托了!本贴来自ZDNetChina中文社区 ,本贴地址:一道C语言编程题此问题的推荐答案我最近写了一个图书管理程序,和你这个差不多,你可以稍微修改就可以使用,不过我用的是链表的方式来完成的。程序如下: #
2、include #include #include #define NULL 0 #define filename lib.dat char showmain();/*显示系统菜单*/ void datainput(struct Node *head); /*图书数据的输入*/ void showdata(struct Node *head); /*图书数据的显示*/ void shownode(struct Node *p); /*单个数据节点的显示*/ void delnode(struct Node *p); void savedata(struct Node *head); void
3、loaddata(struct Node *head); void sortdata(struct Node *head); void freedata(struct Node *head); void deldata(struct Node *head); void modifydata(struct Node *head); struct Node int id; /*编号*/ char bname16; /*名称*/ char wname16; /*图书作者*/ char pname16; /*出版社名称*/ float price; /*图书价格*/ struct Node *next
4、; /*指向数据节点的指针*/ ; void main() struct Node *head,*tail; int num; char answer; head-next=NULL; head=(struct Node*)malloc(sizeof(struct Node); /*给节点分配内存,并通过head指向*/ tail=(struct Node*)malloc(sizeof(struct Node); /*给节点分配内存,并通过tail指向*/ head-next=tail; tail-next=NULL; /*建立head和tail的关系并将tail指向空节点*/ head-id
5、=0; loaddata(head); answer=showmain(); while(answer!=q) switch(answer) case 1:showdata(head); printf(press anykey to continuen); getch(); break; case 2:datainput(head);break; case 3:modifydata(head);break; case 4:deldata(head);break; case 5:sortdata(head);break; case 6:savedata(head);break; answer=s
6、howmain(); /*主界面的运行程序*/ printf(you are going to quit systemn); printf(do you want to save Y/Nn); answer=getch(); if(answer=y) savedata(head); freedata(head); char showmain() char outchar; clrscr(0); system(cls); printf(n=welcome to use lib system=n); printf(= =n); printf(= 1 show =n); printf(= 2 add
7、 =n); printf(= 3 modify =n); printf(= 4 del =n); printf(= 5 sort =n); printf(= 6 save =n); printf(= q quit =n); printf(n); printf(=n); outchar=getch(); return outchar; void loaddata(struct Node *head) FILE *fp; struct Node *p; int i, num; int id; /*编号*/ char bname16; /*名称*/ char wname16; /*图书作者*/ ch
8、ar pname16; /*出版社名称*/ float price; /*图书价格*/ p=head-next; if(fp=fopen(filename,r)=NULL) printf(filename); printf( cant be open .n); getch(); else fscanf(fp,%d,&num); head-id=num; for(i=0;iid=id; stpcpy(p-bname,bname); stpcpy(p-wname,wname); stpcpy(p-pname,pname); p-price=price; /*将数据拷贝到节点上*/ p-next=h
9、ead-next; head-next=p; /*将新的节点插入链表当中*/ fclose(fp); /*显示数据*/ void showdata(struct Node *head) struct Node *p; p=head-next; clrscr(0); system(cls); printf(=showing data in lib system=nn); printf(format: id|bookname|writer|publishment|pricen); if(p-next=NULL) printf(no data in libn); printf(n); while(p
10、-next!=NULL) /*当链表没有达到尾部时则输出数据*/ shownode(p); /*显示单个节点的数据*/ p=p-next; /*显示单个节点的数据*/ void shownode(struct Node *p) int len,i; printf(%5d) ,p-id); printf(%s,p-bname); len=strlen(p-bname); for(i=0;iwname); len=strlen(p-wname); for(i=0;ipname); len=strlen(p-pname); for(i=0;iprice); printf(n); /*数据输入,添加*
11、/ void datainput(struct Node *head) struct Node *p; int id; /*编号*/ char bname16; /*名称*/ char wname16; /*图书作者*/ char pname16; /*出版社名称*/ float price; /*图书价格*/ char answer= ; clrscr(0); system(sys); printf(=input data to lib system=nn); while(answer!=q) p=(struct Node*)malloc(sizeof(struct Node); /*申请一
12、个新的节点*/ printf(please input id of book: ); scanf(%d,&id); printf(nplease input book name: ); scanf(%s,&bname); printf(nplease input writer: ); scanf(%s,&wname); printf(nplease input publishment: ); scanf(%s,&pname); printf(nplease input price: ); scanf(%f,&price); /*得到图书相应的数据*/ p-id=id; stpcpy(p-bna
13、me,bname); stpcpy(p-wname,wname); stpcpy(p-pname,pname); p-price=price; /*将数据拷贝到节点上*/ p-next=head-next; head-next=p; /*将新的节点插入链表当中*/ printf(npress anykey to contine to add, q to back to mainn); answer=getch(); void modifydata(struct Node *head) int num; struct Node *p; char answer; int id; /*编号*/ ch
14、ar bname16; /*名称*/ char wname16; /*图书作者*/ char pname16; /*出版社名称*/ float price; /*图书价格*/ clrscr(0); system(cls); showdata(head); printf(=input data to lib system=nn); printf(which book(id) do you want to modify: ); scanf(%d,&num); p=head-next; while(p-next!=NULL) if(p-id=num) printf(please input id o
15、f book: ); scanf(%d,&id); printf(nplease input book name: ); scanf(%s,&bname); printf(nplease input writer: ); scanf(%s,&wname); printf(nplease input publishment: ); scanf(%s,&pname); printf(nplease input price: ); scanf(%f,&price); /*得到图书相应的数据*/ p-id=id; stpcpy(p-bname,bname); stpcpy(p-wname,wname)
16、; stpcpy(p-pname,pname); p-price=price; /*将数据拷贝到节点上*/ break; else p=p-next; if(p-next=NULL) printf(cant find the book press anykey to continue); getch(); else showdata(head); printf(press anykey to continue); getch(); void delnode(struct Node *p) struct Node *p1,*temp; temp=p-next; p1=temp-next; p-n
17、ext=p1; free(temp); void deldata(struct Node *head) int num; struct Node *p0,*p1; char answer; clrscr(0); system(cles); showdata(head); printf(which book(id) do you want delete: ); scanf(%d,&num); p0=head; p1=head-next; while(p1-next!=NULL) if(p1-id=num) printf(do you really want to delete %d ,:,num
18、); answer=getch(); if(answer=y) delnode(p0); break; else p1=p1-next; p0=p0-next; if(p1-next=NULL) printf(cant find the book press anykey to continue); getch(); else showdata(head); printf(n has been deleted success, press anykey to continue,num); getch(); void sortdata(struct Node *head) struct Node
19、 *head2,*p,*tail,*p2,*pre,*temp; int way; clrscr(0); system(cls); temp=head; head2=(struct Node*)malloc(sizeof(struct Node); tail=(struct Node*)malloc(sizeof(struct Node); head2-next=head-next; tail-next=NULL; head-next=tail; printf( =sort data in lib system=n); printf( 1 sort in idn); printf( 2 sor
20、t in booknamen); printf( 3 sort in writern); printf( 4 sort in publishmentn); printf( 5 sort in pricen); printf(nplease select way of sorting:); scanf(%d,&way); p2=head2-next; switch(way) case 1: while(p2-next!=NULL) p=head-next; pre=head; while(p-next!=NULL) if(p2-idid) break; else pre=pre-next; p=
21、p-next; head2-next=p2-next; p2-next=p; pre-next=p2; p2=head2-next; free(head2-next); free(head2); break; case 2: while(p2-next!=NULL) p=head-next; pre=head; while(p-next!=NULL) if(strcmp(p2-bname,p-bname)next; p=p-next; head2-next=p2-next; p2-next=p; pre-next=p2; p2=head2-next; free(head2-next); fre
22、e(head2); break; case 3: while(p2-next!=NULL) p=head-next; pre=head; while(p-next!=NULL) if(strcmp(p2-wname,p-wname)next; p=p-next; head2-next=p2-next; p2-next=p; pre-next=p2; p2=head2-next; free(head2-next); free(head2); break; case 4: while(p2-next!=NULL) p=head-next; pre=head; while(p-next!=NULL)
23、 if(strcmp(p2-pname,p-pname)next; p=p-next; head2-next=p2-next; p2-next=p; pre-next=p2; p2=head2-next; free(head2-next); free(head2); break; case 5: while(p2-next!=NULL) p=head-next; pre=head; while(p-next!=NULL) if(p2-priceprice) break; else pre=pre-next; p=p-next; head2-next=p2-next; p2-next=p; pr
24、e-next=p2; p2=head2-next; free(head2-next); free(head2); break; default:printf(wrong inputn); showdata(head); printf(press anykey to continuen); getch(); void savedata(struct Node *head) FILE *fp; struct Node *p; p=head-next; if(fp=fopen(filename,w)=NULL) printf(filename); printf( cant be open or cr
25、eate .n); getch(); else fprintf(fp,%dn,head-id); while(p-next!=NULL) fprintf(fp,%dn,p-id); fprintf(fp,%sn,p-bname); fprintf(fp,%sn,p-wname); fprintf(fp,%sn,p-pname); fprintf(fp,%fn,p-price); p=p-next; fclose(fp); printf(filename); printf( save successfully press anykey ); getch(); void freedata(struct Node *head) struct Node *p,*q; p=head-next; free(head); while(p-next!=NULL) q=p-next; free(p); p=q; free(p); _本贴来自ZDNetChina中文社区 ,本贴地址:
copyright@ 2008-2022 冰豆网网站版权所有
经营许可证编号:鄂ICP备2022015515号-1