程序的设计报告

上传人:wuy****ng 文档编号:164563665 上传时间:2022-10-25 格式:DOC 页数:23 大小:418KB
收藏 版权申诉 举报 下载
程序的设计报告_第1页
第1页 / 共23页
程序的设计报告_第2页
第2页 / 共23页
程序的设计报告_第3页
第3页 / 共23页
资源描述:

《程序的设计报告》由会员分享,可在线阅读,更多相关《程序的设计报告(23页珍藏版)》请在装配图网上搜索。

1、 课 程 设 计课程名称:程序设计语言课程设计 设计题目:链表操作相关的基本运算 设计统计任意文本字数的程序 车票订购统计系统 学 院:信息工程与自动化学院 专 业:计算机科学与技术 年 级:2011级 学生姓名: 指导教师: 日 期:2012-8-26 教 务 处 课 程 设 计 任 务 书 信息工程与自动化 学院 计算机科学与技术 专业 2011 年级学生姓名: 学号: 课程设计题目: 程序设计语言课程设计 课程设计主要内容:一、 基础程序设计:本设计部分主要完成与链表操作相关的基本运算,其中包含:链表的建立、链表的输出、链表的插入、链表的删除等运算。.二、 综合程序设计:1、设计统计任意

2、文本字数的程序(张力老师组必做):要求包括:中英文文本的:中文字数、英文字符数、英文单词数及其他符号。2、车票订购统计系统(张力老师组必做):下图是昆明北京的沿途车站与票价:昆明长沙武汉郑州北京距离:700KM票价:68元距离:1100KM票价:90元距离:1000KM票价:85元距离:500KM票价:60元请用C语言为之开发一个售票程序,要求如下:(1)乘客购票时用菜单选择起点站和终到站。如果选择的起点站和终到站为同一个站则报错,程序退出。(2)选好起点站和终到站之后,通过调用函数int BuyTicket() 为之计算票价和里程,并在屏幕上显示出来。(3)用文件类型存储每一次售票记录,包括

3、:售票流水号,起点站,终点站,里程,金额等数据,并统计所有存储记录的总售票金额及各站的旅客流量(进站流量+出站流量)。设 计 指 导 教 师 (签字): 2012年8 月26日目录课 程 设 计 任 务 书1摘要2链表的相关操作21.1.需求分析。21.2. 模块分析21.3. 编码及调试31.4.总结和体会3设计统计任意文本字数的程序42.1.需求分析。42.2. 模块分析42.3. 编码及调试42.4.总结和体会5车票订购统计系统53.1.需求分析。53.2. 模块分析53.3. 编码及调试73.4.总结和体会7反思7附录9参考文献9摘要 本次文档是我在老师的指导下对程序设计语言课程学习后

4、,作出的实验成果和总结。具体是链表的相关操作,统计任意文本字数,车票订购统计系统等几次程序的设计及改进,总结。链表的相关操作1.1.需求分析。数组使我们储存数据之时可以不再为同类型数据而苦恼。但是对数组的定义多了就浪费储存空间,如果定义少了满足不了我们的需求。为了解决这个问题,所以我们使用链表用以解决。同时为了链表的完整性。我们使用链表的插入与删除。1.2. 模块分析 在此将给出几个重点分析及注释,具体见附录的源程序注释。struct Node /*节点的数据结构*/int number;struct Node *next;此段是对链表节点的数据结构的描述。此是设计的重点。同时最后一句是必不可

5、少的。此处类似机构体中的定义要例举出需用到的数据类型,及名称。p1=p2=(struct Node*) malloc(sizeof(struct Node);这是动态分配内存的函数的调用。同时结合头文件stdlib.h。p2=head;if(head=NULL)head=p1;p1-next=NULL;插入节点的中心算法。以后皆照此类推。p-next =temp-next;删除的中心,替换和刷新。1.3. 编码及调试编码见附件源文件。1.4.总结和体会 通过这次的学习我明白了链表的创建,插入和删除。还在此次设计中锻炼了广泛搜集资料的能力。初步了解了什么叫结构化程序设计。设计统计任意文本字数的程

6、序2.1.需求分析。随着现在电子产品的广泛运用对文字的统计已经是最实际的了。看字计数随着电子文学的传播越来越不切实际,所以只有运用科学的方法。才能满足这种需求。2.2. 模块分析if(fp=fopen(filename,a)=NULL)printf(打開文件失敗,按任意鍵退出!);此段是对文件的打开,需要注意的是打开方式的不同。分为文本,二进制。还有是只读,只写还是读写。if(ch =1&ch=A&ch=a&ch=z)letter+;if(flg) word+;flg=0; else if(ch=n) paragraph+; else other+;此段是对文本统计的中心语句的统计。首先要分清

7、文字还是字母符号。然后再细分。具体可见以下流程:(由于版面需求特将流程图置于底部) 2.3. 编码及调试编码见附件源文件。2.4.总结和体会通过此次的学习,我清楚了如何让打开文件和关闭文件,同时明白了不同的文件打开方式。主要学会的是运用选择的方式统计文本中的字数。同时学会了逻辑的有效掌控,还有统计分类的着重与要点。车票订购统计系统3.1.需求分析。随着现在信息技术的发展,用信息技术解决问题越来越成为现在的主流。自动化成为了趋势。所以买票不再用排队,可以用一些信息技术来解决。所以设计了车票订购系统。这个系统可以很好地记录售票流水号,起点站,终点站,里程,金额等数据,并统计所有存储记录的总售票金额

8、及各站的旅客流量(进站流量+出站流量)。用文件储存。3.2. 模块分析struct buy_ticket_listchar name10;float distance;float price; bt=昆明,0,0,长沙,700,68,武汉,1100,90,郑州,1000,85,北京,500,60;struct store_informationint year,month,day,hour,min,sec;int exchange_shop;char start_station10;char end_station10;float distances;float prices; SI;结构体的

9、设定用于储存不同类型的若干数,便于储存和管理。oid get_date()FILE *fp;char filename20;float price_all=0;printf(请输入需打开文件名(并标明类型)例如lib.datn);scanf(%s,filename);if(fp=fopen(filename,r)=NULL)printf(打開文件失敗,按任意鍵退出!);printf(n现在开始打印列表:n);printf(流水号 起点站 终点站 里程 票价n);while (!feof(fp) fread(&SI,LEN,1,fp); if (feof(fp) break; flow_stat

10、istics(SI.start_station,SI.end_station); price_all+=SI.prices; printf(%4d%d%02d%d%02d%02d%02d %s %s %.2f %.2fn,SI.year,SI.month,SI.day, SI.hour,SI.min,SI.sec,SI.exchange_shop,SI.start_station,SI.end_station,SI.distances,SI.prices);fclose (fp);printf(流量统计:n);printf(t昆明:%dt长沙:%dt武汉:%dt郑州:%dt北京:%dn,km,

11、cs,wh,zz,bj);printf(nnttttt票价总计:%.2fn,price_all);km=0;cs=0;wh=0;zz=0;bj=0;文件储存便于管理。必要时有助于输出。用于文本的永久储存;int code()char code20;scanf(%s,code);if(strcmp(code,执行)=0) return 1; else printf(你输入有误!建立文档失败。将退出!n);return 0;独特设计防止用户输错清除文件。有效保护文件。3.3. 编码及调试编码见附件源文件。3.4.总结和体会通过此次的学习我不仅学会了如何来系统的设计程序。同时学会了要分块来设计使得自

12、己的模块看起来更加的简单清晰,同时对数据的储存更加清晰。明白了不同数据类型采用不同方式储存。在以后的编程中作用颇大。同时更加熟练的使用了文件的打开与读取。反思这次的程序设计对我的锻炼十分的显著。通过这些天的锻炼我明白了。只要掌握思想,小的方面可以从各处来个取长补短。有效地利用互联网就是其中一个有效途径。同时资料查询也不错。只要你有恒心,万事都不是困难。我也通过这几天对这些实际应用有了初步了解。对以后的作用颇大。开始 ch0? Ychinese+ NCh= ? Yspace+; flg=1; N0ch10digit+ Y(Ach=Z)|(a=ch=z) Nletter+ Y NFlg=1?Ch=

13、nparagraph+ Yword+;flg=0; Nother+结束 附录链表的相关操作见文件:linked list.cpp统计任意文本字数见文件:count_txt.cpp车票订购统计系统见文件:ticket_buy.cpp参考文献1 谭浩强著.C程序设计(第四版).北京:清华大学出版社.2010源文件程序:linked list.cpp# include # include string.h# include conio.h# include stdlib.hstruct Node /*节点的数据结构*/int number;struct Node *next;int m;/* 创建链

14、表 */struct Node *creat(struct Node *head)struct Node *p1,*p2;m=0;p1=p2=(struct Node*) malloc(sizeof(struct Node);printf (请输入数值:(若要退出请输入0!)n);scanf(%d,&p1-number);head=NULL;while (p1-number!=0)m+;if (head=NULL) head=p1; else p2-next=p1; p2 = p1; p1=(struct Node*) malloc(sizeof(struct Node); scanf(%d,

15、&p1-number);p2-next=NULL;return (head);/* * * * * * * * * * 插入节点* * * * * * * * * */struct Node *insert(struct Node *head,int n)struct Node *p1,*p2,*p3;p1=(struct Node*)malloc(sizeof(struct Node);p1-number=n;p2=head;if(head=NULL)head=p1;p1-next=NULL; else while (np2-number&p2-next!=NULL) p3 = p2; p2

16、 = p2-next; if (nnumber) if (head=p2) head = p1 ; p1 - next = p2 ; else p3 - next = p1 ; p1 - next = p2 ; else p2 - next = p1; p1 - next = NULL ; return (head) ;/* * * * * 删除节点* * * * * * * * * * * * */struct Node *delet (struct Node *head,int pstr)struct Node *temp,*p;temp=head;if (head=NULL)printf

17、(n数值不存在!n);elsetemp = head;while (temp-number!=pstr&temp-next!=NULL)p = temp ;temp = temp - next;if (temp-number=pstr )if (temp= head)head = head - next ;free(temp);elsep-next =temp-next;printf(请输入需删除对象:%dn,temp-number);free(temp);else printf(n没发现数据!n);return(head);/* * * * * * * * * * 链表各节点的输出* * *

18、 * * * * * * */void print (struct Node *head)struct Node *temp;temp=head;printf(n信息输出:n);while (temp!=NULL)printf( %dn , temp-number);temp=temp-next;void main()struct Node *head;int n,l,flg=1,i;head=NULL; flg=1;while (flg)system (cls);printf(ttt 功能选择n);printf(ttt1.数据输入n);printf(ttt2.数据添加n);printf(tt

19、t3.数据删除n);printf(ttt0.退出n);printf(请选择0 到 3n);scanf(%d,&i);switch (i)case 1 : head=creat (head); print(head); break;case 2 : print(head); printf(请输入添加数据:n);scanf(%d,&n);head=insert(head,n); print(head); break;case 3 : print(head); printf(请删除添加数据:n);scanf(%d,&l);head=delet(head,l); print(head); break;

20、case 0 : flg=0;if (i!=0) printf (你可以按任意键继续操作!);getch();system (cls);for(i=1;i=20;i+) printf(*);printf(感谢您的使用,再见!);for(i=1;i=20;i+) printf(*);printf(n);for(i=1;i=18;i+)printf( );count_txt.cpp# include /输入输出及文件操作# include # include # include char filenames20;void open_file()FILE *fp;char filename20;pr

21、intf(请输入文件名(并标明类型)例如test.txtn);scanf(%s,filename);fp=fopen(filename,w+);printf(新文件已建立n);fclose(fp);int save_date()FILE *fp;char word,filename20;printf(请输入需打开文件名(并标明类型)例如test.txtn);scanf(%s,filename);if(fp=fopen(filename,a)=NULL)printf(打開文件失敗,按任意鍵退出!); getchar();printf(请输入文本按$结束.n);word=getchar();whi

22、le (word!=$)fputc(word,fp);word=getchar();fclose(fp);printf(数据存入完毕!n);return 1;void count()FILE *fp; char ch,filename20;int flg;int letter=0,digit=0,space=0,other=0,chinese=0,paragraph=0,word=0; if(fp=fopen(filenames,r)=NULL)printf(打開文件失敗,按任意鍵退出!);exit(0); ch=fgetc(fp);while(ch!=EOF) if(ch =1&ch=A&c

23、h=a&ch=z)letter+;if(flg) word+;flg=0; else if(ch=n) paragraph+; else other+; ch=fgetc(fp); fclose(fp); printf(字母:%dn,letter); printf(数字:%dn,digit); printf(单词:%dn,word); printf(中文:%dn,chinese/2); printf(段落:%dn,paragraph+1); printf(字符:%dn,other); getch(); int print_date()FILE *fp;char word;printf(请输入需

24、打开文件名(并标明类型)例如test.txtn);scanf(%s,filenames);if(fp=fopen(filenames,r)=NULL)printf(打開文件失敗,按任意鍵退出!);exit (1); word=fgetc(fp); while (word!=EOF)putchar(word);word=fgetc(fp);fclose(fp);printf(n);printf(数据存入完毕!n);return 1;void main()int flg,i;flg=1;while (flg)system (cls);printf(ttt功能选择n);printf(tt1.文件建立

25、n);printf(tt2.文本输入n);printf(tt3.字数统计n);printf(tt0.你选择0将退出n);printf(ttplease chose 0 to 9n);scanf(%d,&i);switch (i)case 1 : open_file() ;break;case 2 : save_date() ;break;case 3 : print_date();count() ;break;case 0 : flg=0;if (i!=0) printf (you can press any key to continue!);getch();system (cls);pri

26、ntf(nnthank you use it,good bye!n);ticket_buy.cpp# include # include # include # include #include # define LEN sizeof(struct store_information)struct buy_ticket_listchar name10;float distance;float price; bt=昆明,0,0,长沙,700,68,武汉,1100,90,郑州,1000,85,北京,500,60;/*/struct store_informationint year,month,d

27、ay,hour,min,sec;int exchange_shop;char start_station10;char end_station10;float distances;float prices; SI;/*/int s,e;int SE=0;int km=0,cs=0,wh=0,zz=0,bj=0;/*/void choos_start_end()do printf(tt 请选择起始站nttt1.昆明nttt2.长沙nttt3.武汉nttt4.郑州nttt5.北京n);scanf(%d,&s); while (s5);doprintf(tt 请选择终点站nttt1.昆明nttt2.

28、长沙nttt3.武汉nttt4.郑州nttt5.北京n);scanf(%d,&e); while (e5);/*/int BuyTicket(int a,int b)int i;float distances=0,prices=0;if (a=b) printf(aa警告!你选择了同一站点,出错。n); else if (ab) for(i=a;i%s的票,此间距离为:%.2f;票价为:%.2fn,bta-1.name,btb-1.name,distances,prices); else if(ab) for(i=a-1;i=b;i-) distances+=bti.distance;pric

29、es+=bti.price; printf(你选择了%s-%s的票,此间距离为:%.2f;票价为:%.2fn,bta-1.name,btb-1.name,distances,prices); return (0);/*/void store_date(int a,int b) time_t tval; struct tm *now; tval = time(NULL); now = localtime(&tval);int i,j=0;SI.distances=0;SI.prices=0;/*/SI.year=now-tm_year+1900;SI.month=now-tm_mon+1;SI.

30、day=now-tm_mday;SI.hour=now-tm_hour;SI.min=now-tm_min;SI.sec=now-tm_sec;SI.exchange_shop=SE;/*流水号*/strcpy(SI.start_station,bta-1.name);strcpy(SI.end_station,btb-1.name);if (a=b) printf(aa警告!你选择了同一站点,出错。n); else if (ab) for(i=a;ib) for(i=a-1;i=b;i-) SI.distances+=bti.distance;SI.prices+=bti.price;j+;

31、/*/void open_file()FILE *fp;char filename20;printf(请输入文件名(并标明类型)例如lib.datn);scanf(%s,filename);fp=fopen(filename,w+);printf(新文件已建立n);fclose(fp);/*/int save_date()FILE *fp;char filename20;printf(请输入需打开文件名(并标明类型)例如lib.datn);scanf(%s,filename);if(fp=fopen(filename,a)=NULL)printf(打開文件失敗,按任意鍵退出!);if (fwr

32、ite(&SI,LEN,1,fp)!=1)printf(文件写入失败!n);fclose(fp);SE+;printf(数据存入完毕!n);return 1;/*/void flow_statistics(char *start,char *end)int sch,ech;if (strcmp(start,昆明)=0) sch=1; else if (strcmp(start,长沙)=0) sch=2; else if (strcmp(start,武汉)=0) sch=3; else if (strcmp(start,郑州)=0) sch=4; else if (strcmp(start,北京

33、)=0) sch=5; if (strcmp(end,昆明)=0) ech=1; else if (strcmp(end,长沙)=0) ech=2; else if (strcmp(end,武汉)=0) ech=3; else if (strcmp(end,郑州)=0) ech=4; else if(strcmp(end,北京)=0) ech=5;switch (sch) case 1 : switch (ech) case 5 :bj+; case 4 :zz+; case 3 :wh+; case 2 :cs+; case 1 :km+; break;case 2 : switch (ec

34、h) case 5 :bj+;case 4 :zz+;case 3 :wh+;case 2 :cs+;break;case 1 :cs+;km+; break; case 3 : switch (ech) case 5 :bj+;case 4 :zz+;case 3 :wh+;break;case 1 :km+;case 2 :cs+;wh+; break;case 4 : switch (ech) case 5 :bj+;case 4 :zz+;break;case 1 :km+;case 2 :cs+;case 3 :wh+;zz+; break;case 5: switch (ech)

35、case 5 :bj+;break; case 1 :km+; case 2 :cs+; case 3 :wh+; case 4 :zz+;bj+; /*/void get_date()FILE *fp;char filename20;float price_all=0;printf(请输入需打开文件名(并标明类型)例如lib.datn);scanf(%s,filename);if(fp=fopen(filename,r)=NULL)printf(打開文件失敗,按任意鍵退出!);printf(n现在开始打印列表:n);printf(流水号 起点站 终点站 里程 票价n);while (!feo

36、f(fp) fread(&SI,LEN,1,fp); if (feof(fp) break; flow_statistics(SI.start_station,SI.end_station); price_all+=SI.prices; printf(%4d%d%02d%d%02d%02d%02d %s %s %.2f %.2fn,SI.year,SI.month,SI.day, SI.hour,SI.min,SI.sec,SI.exchange_shop,SI.start_station,SI.end_station,SI.distances,SI.prices);fclose (fp);p

37、rintf(流量统计:n);printf(t昆明:%dt长沙:%dt武汉:%dt郑州:%dt北京:%dn,km,cs,wh,zz,bj);printf(nnttttt票价总计:%.2fn,price_all);km=0;cs=0;wh=0;zz=0;bj=0;/*/int code()char code20;scanf(%s,code);if(strcmp(code,执行)=0) return 1; else printf(你输入有误!建立文档失败。将退出!n);return 0;void main()int flg,i;flg=1;while (flg)system (cls);printf

38、(ttt功能选择n);printf(tt1.票单建立n);printf(tt2.票单输入n);printf(tt3.数据转存n);printf(tt4.票单显示n);printf(tt0.你选择0将退出n);printf(ttplease chose 0 to 4n);scanf(%d,&i);switch (i)case 1 : printf(若要执行以下功能请输入:(执行)n);if(code() open_file(); break;case 2 : choos_start_end(); BuyTicket(s,e); break;case 3 : store_date(s,e); sa

39、ve_date(); break;case 4 : get_date(); break;case 0 : flg=0;if (i!=0) printf (你可以按任意键继续操作!);getch();system (cls);for(i=1;i=20;i+) printf(*);printf(感谢您的使用,再见!);for(i=1;i=20;i+) printf(*);printf(n);for(i=1;i=18;i+)printf( );宁可累死在路上,也不能闲死在家里!宁可去碰壁,也不能面壁。是狼就要练好牙,是羊就要练好腿。什么是奋斗?奋斗就是每天很难,可一年一年却越来越容易。不奋斗就是每天都很容易,可一年一年越来越难。能干的人,不在情绪上计较,只在做事上认真;无能的人!不在做事上认真,只在情绪上计较。拼一个春夏秋冬!赢一个无悔人生!早安!献给所有努力的人.

展开阅读全文
温馨提示:
1: 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
2: 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
3.本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
5. 装配图网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
关于我们 - 网站声明 - 网站地图 - 资源地图 - 友情链接 - 网站客服 - 联系我们

copyright@ 2023-2025  zhuangpeitu.com 装配图网版权所有   联系电话:18123376007

备案号:ICP2024067431-1 川公网安备51140202000466号


本站为文档C2C交易模式,即用户上传的文档直接被用户下载,本站只是中间服务平台,本站所有文档下载所得的收益归上传人(含作者)所有。装配图网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。若文档所含内容侵犯了您的版权或隐私,请立即通知装配图网,我们立即给予删除!