用C语言开发简单的应用系统程序.docx

上传人:b****5 文档编号:7674720 上传时间:2023-01-25 格式:DOCX 页数:17 大小:17.38KB
下载 相关 举报
用C语言开发简单的应用系统程序.docx_第1页
第1页 / 共17页
用C语言开发简单的应用系统程序.docx_第2页
第2页 / 共17页
用C语言开发简单的应用系统程序.docx_第3页
第3页 / 共17页
用C语言开发简单的应用系统程序.docx_第4页
第4页 / 共17页
用C语言开发简单的应用系统程序.docx_第5页
第5页 / 共17页
点击查看更多>>
下载资源
资源描述

用C语言开发简单的应用系统程序.docx

《用C语言开发简单的应用系统程序.docx》由会员分享,可在线阅读,更多相关《用C语言开发简单的应用系统程序.docx(17页珍藏版)》请在冰豆网上搜索。

用C语言开发简单的应用系统程序.docx

用C语言开发简单的应用系统程序

用C语言开发简单的应用系统程序,设计一个与防震、抗震救灾有关的数据管理系统

要求:

界面友好,使用方便;利用结构体数组实现数据结构设计;系统具有增加,查询,插入,排序、统计等基本功能;系统的各个功能模块要求用函数的形式实现;数据用文件保存,源代码不得少于150行,必须用TurboC2.0编程,程序应有友好的人机交互界面、完善的功能和实用性.

那位高手能帮帮忙啊!

拜托了!

本贴来自ZDNetChina中文社区,本贴地址:

一道C语言编程题

[此问题的推荐答案]

我最近写了一个图书管理程序,和你这个差不多,你可以稍微修改就可以使用,不过我用的是链表的方式来完成的。

程序如下:

#include

#include

#include

#defineNULL0

#definefilename"lib.dat"

charshowmain();/*显示系统菜单*/

voiddatainput(structNode*head);/*图书数据的输入*/

voidshowdata(structNode*head);/*图书数据的显示*/

voidshownode(structNode*p);/*单个数据节点的显示*/

voiddelnode(structNode*p);

voidsavedata(structNode*head);

voidloaddata(structNode*head);

voidsortdata(structNode*head);

voidfreedata(structNode*head);

voiddeldata(structNode*head);

voidmodifydata(structNode*head);

structNode

{

intid;/*编号*/

charbname[16];/*名称*/

charwname[16];/*图书作者*/

charpname[16];/*出版社名称*/

floatprice;/*图书价格*/

structNode*next;/*指向数据节点的指针*/

};

voidmain()

{

structNode*head,*tail;

intnum;

charanswer;

head->next=NULL;

head=(structNode*)malloc(sizeof(structNode));/*给节点分配内存,并通过head指向*/

tail=(structNode*)malloc(sizeof(structNode));/*给节点分配内存,并通过tail指向*/

head->next=tail;

tail->next=NULL;/*建立head和tail的关系并将tail指向空节点*/

head->id=0;

loaddata(head);

answer=showmain();

while(answer!

='q')

{

switch(answer)

{

case'1':

showdata(head);

printf("pressanykeytocontinue\n");

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=showmain();

}/*主界面的运行程序*/

printf("youaregoingtoquitsystem\n");

printf("doyouwanttosaveY/N\n");

answer=getch();

if(answer='y')savedata(head);

freedata(head);

}

charshowmain()

{

charoutchar;

clrscr(0);

system("cls");

printf("\n==========welcometouselibsystem=================\n");

printf("==\n");

printf("=1show=\n");

printf("=2add=\n");

printf("=3modify=\n");

printf("=4del=\n");

printf("=5sort=\n");

printf("=6save=\n");

printf("=qquit=\n");

printf("\n");

printf("====================================================\n");

outchar=getch();

returnoutchar;

}

voidloaddata(structNode*head)

{

FILE*fp;

structNode*p;

inti,num;

intid;/*编号*/

charbname[16];/*名称*/

charwname[16];/*图书作者*/

charpname[16];/*出版社名称*/

floatprice;/*图书价格*/

p=head->next;

if((fp=fopen(filename,"r"))==NULL)

{

printf(filename);

printf("can'tbeopen.\n");

getch();

}

else

{

fscanf(fp,"%d",&num);

head->id=num;

for(i=0;i

{

p=(structNode*)malloc(sizeof(structNode));/*申请一个新的节点*/

fscanf(fp,"%d",&id);

fscanf(fp,"%s",&bname);

fscanf(fp,"%s",&wname);

fscanf(fp,"%s",&pname);

fscanf(fp,"%f",&price);

p->id=id;

stpcpy(p->bname,bname);

stpcpy(p->wname,wname);

stpcpy(p->pname,pname);

p->price=price;/*将数据拷贝到节点上*/

p->next=head->next;

head->next=p;/*将新的节点插入链表当中*/

}

fclose(fp);

}

}

/*显示数据*/

voidshowdata(structNode*head)

{

structNode*p;

p=head->next;

clrscr(0);

system("cls");

printf("====showingdatainlibsystem======\n\n");

printf("format:

id|bookname|writer|publishment|price\n");

if(p->next==NULL)printf("nodatainlib\n");

printf("\n");

while(p->next!

=NULL)/*当链表没有达到尾部时则输出数据*/

{

shownode(p);/*显示单个节点的数据*/

p=p->next;

}

}

/*显示单个节点的数据*/

voidshownode(structNode*p)

{

intlen,i;

printf("%5d)",p->id);

printf("%s",p->bname);

len=strlen(p->bname);

for(i=0;i<(16-len);i++)printf("");

printf("%s",p->wname);

len=strlen(p->wname);

for(i=0;i<(16-len);i++)printf("");

printf("%s",p->pname);

len=strlen(p->pname);

for(i=0;i<(16-len);i++)printf("");

printf("%1f",p->price);

printf("\n");

}

/*数据输入,添加*/

voiddatainput(structNode*head)

{

structNode*p;

intid;/*编号*/

charbname[16];/*名称*/

charwname[16];/*图书作者*/

charpname[16];/*出版社名称*/

floatprice;/*图书价格*/

charanswer='';

clrscr(0);

system("sys");

printf("===========inputdatatolibsystem=============\n\n");

while(answer!

='q')

{

p=(structNode*)malloc(sizeof(structNode));/*申请一个新的节点*/

printf("pleaseinputidofbook:

");

scanf("%d",&id);

printf("\npleaseinputbookname:

");

scanf("%s",&bname);

printf("\npleaseinputwriter:

");

scanf("%s",&wname);

printf("\npleaseinputpublishment:

");

scanf("%s",&pname);

printf("\npleaseinputprice:

");

scanf("%f",&price);/*得到图书相应的数据*/

p->id=id;

stpcpy(p->bname,bname);

stpcpy(p->wname,wname);

stpcpy(p->pname,pname);

p->price=price;/*将数据拷贝到节点上*/

p->next=head->next;

head->next=p;/*将新的节点插入链表当中*/

printf("\npressanykeytocontinetoadd,qtobacktomain\n");

answer=getch();

}

}

voidmodifydata(structNode*head)

{

intnum;

structNode*p;

charanswer;

intid;/*编号*/

charbname[16];/*名称*/

charwname[16];/*图书作者*/

charpname[16];/*出版社名称*/

floatprice;/*图书价格*/

clrscr(0);

system("cls");

showdata(head);

printf("===========inputdatatolibsystem=============\n\n");

printf("whichbook(id)doyouwanttomodify:

");

scanf("%d",&num);

p=head->next;

while(p->next!

=NULL)

{

if(p->id==num)

{

printf("pleaseinputidofbook:

");

scanf("%d",&id);

printf("\npleaseinputbookname:

");

scanf("%s",&bname);

printf("\npleaseinputwriter:

");

scanf("%s",&wname);

printf("\npleaseinputpublishment:

");

scanf("%s",&pname);

printf("\npleaseinputprice:

");

scanf("%f",&price);/*得到图书相应的数据*/

p->id=id;

stpcpy(p->bname,bname);

stpcpy(p->wname,wname);

stpcpy(p->pname,pname);

p->price=price;/*将数据拷贝到节点上*/

break;

}

else

{

p=p->next;

}

}

if(p->next==NULL)

{

printf("can'tfindthebookpressanykeytocontinue");

getch();

}

else

{

showdata(head);

printf("pressanykeytocontinue");

getch();

}

}

voiddelnode(structNode*p)

{

structNode*p1,*temp;

temp=p->next;

p1=temp->next;

p->next=p1;

free(temp);

}

voiddeldata(structNode*head)

{

intnum;

structNode*p0,*p1;

charanswer;

clrscr(0);

system("cles");

showdata(head);

printf("whichbook(id)doyouwantdelete:

");

scanf("%d",&num);

p0=head;

p1=head->next;

while(p1->next!

=NULL)

{

if(p1->id==num)

{

printf("doyoureallywanttodelete%d,:

",num);

answer=getch();

if(answer=='y')delnode(p0);

break;

}

else

{

p1=p1->next;

p0=p0->next;

}

}

if(p1->next==NULL)

{

printf("can'tfindthebookpressanykeytocontinue");

getch();

}

else

{

showdata(head);

printf("\n<%d>hasbeendeletedsuccess,pressanykeytocontinue",num);

getch();

}

}

voidsortdata(structNode*head)

{

structNode*head2,*p,*tail,*p2,*pre,*temp;

intway;

clrscr(0);

system("cls");

temp=head;

head2=(structNode*)malloc(sizeof(structNode));

tail=(structNode*)malloc(sizeof(structNode));

head2->next=head->next;

tail->next=NULL;

head->next=tail;

printf("============sortdatainlibsystem============\n");

printf("1sortinid\n");

printf("2sortinbookname\n");

printf("3sortinwriter\n");

printf("4sortinpublishment\n");

printf("5sortinprice\n");

printf("\npleaseselectwayofsorting:

");

scanf("%d",&way);

p2=head2->next;

switch(way)

{

case1:

{

while(p2->next!

=NULL)

{

p=head->next;

pre=head;

while(p->next!

=NULL)

{

if(p2->idid)

break;

else

{

pre=pre->next;

p=p->next;

}

}

head2->next=p2->next;

p2->next=p;

pre->next=p2;

p2=head2->next;

}

free(head2->next);

free(head2);

break;

}

case2:

{

while(p2->next!

=NULL)

{

p=head->next;

pre=head;

while(p->next!

=NULL)

{

if(strcmp(p2->bname,p->bname)<0)

break;

else

{

pre=pre->next;

p=p->next;

}

}

head2->next=p2->next;

p2->next=p;

pre->next=p2;

p2=head2->next;

}

free(head2->next);

free(head2);

break;

}

case3:

{

while(p2->next!

=NULL)

{

p=head->next;

pre=head;

while(p->next!

=NULL)

{

if(strcmp(p2->wname,p->wname)<0)

break;

else

{

pre=pre->next;

p=p->next;

}

}

head2->next=p2->next;

p2->next=p;

pre->next=p2;

p2=head2->next;

}

free(head2->next);

free(head2);

break;

}

case4:

{

while(p2->next!

=NULL)

{

p=head->next;

pre=head;

while(p->next!

=NULL)

{

if(strcmp(p2->pname,p->pname)<0)

break;

else

{

pre=pre->next;

p=p->next;

}

}

head2->next=p2->next;

p2->next=p;

pre->next=p2;

p2=head2->next;

}

free(head2->next);

free(head2);

break;

}

case5:

{

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;

pre->next=p2;

p2=head2->next;

}

free(head2->next);

free(head2);

break;

}

default:

printf("wronginput\n");

}

showdata(head);

printf("pressanykeytocontinue\n");

getch();

}

voidsavedata(structNode*head)

{

FILE*fp;

structNode*p;

p=head->next;

if((fp=fopen(filename,"w"))==NULL)

{

printf(filename);

printf("can'tbeopenorcreate.\n");

getch();

}

else

{

fprintf(fp,"%d\n",head->id);

while(p->next!

=NULL)

{

fprintf(fp,"%d\n",p->id);

fprintf(fp,"%s\n",p->bname);

fprintf(fp,"%s\n",p->wname);

fprintf(fp,"%s\n",p->pname);

fprintf(fp,"%f\n",p->price);

p=p->next;

}

fclose(fp);

printf(filename);

printf("savesuccessfullypressanykey");

getch();

}

}

voidfreedata(structNode*head)

{

structNode*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