课程设计报告集合的交并差运算.docx

上传人:scccc 文档编号:11994133 上传时间:2021-11-30 格式:DOCX 页数:11 大小:28.71KB
返回 下载 相关 举报
课程设计报告集合的交并差运算.docx_第1页
第1页 / 共11页
课程设计报告集合的交并差运算.docx_第2页
第2页 / 共11页
课程设计报告集合的交并差运算.docx_第3页
第3页 / 共11页
亲,该文档总共11页,到这儿已超出免费预览范围,如果喜欢就下载吧!
资源描述

《课程设计报告集合的交并差运算.docx》由会员分享,可在线阅读,更多相关《课程设计报告集合的交并差运算.docx(11页珍藏版)》请在三一文库上搜索。

1、LoriEiqiau 匸訓右口會 Of LamZhGu G<OfliH>ieFCiai Cfillcue兰州商学院陇桥学院工学系课程设计报告设系计题目:集合的交、并、差运算别:工学系专业方向:信息管理与信息系统年级、班:20XX级X班学生姓名:张某某学生学号:000000000000指导教师:王某某20xx年00月00 日目录一、系统开发的背景 1二、系统分析与设计 1一系统功能要求 11、输入集合 1 中的元素; 12、输入集合 2 中的元素; 13、执行交集、并集、差集运算; 1二系统模块结构设计 11 、集合的交集运算, 12、集合的并集运算, 23、集合的差集运算, 2三、

2、系统的设计与实现 2一集合的交集运算:VOIDJIAO 2二集合的并集运算:VOIDBING 3三集合的差集运算:VOID CHA 4四、系统测试 5一测试MAIN;函数 5二测试 VOID JIAO函数 5三测试VOID BING函数 5四测试VOID CHA函数 5五、总结 6六、附件代码、局部图表 7集合的交、并、差运算、系统开发的背景为了演示执行集合的交、并和差运算的程序,因此设计了这个程序。二、系统分析与设计一系统功能要求可以对键盘输入的集合元素进行反序输出,然后对输入的集合进行交 集,并集,差集的运算。1、输入集合1中的元素;2、输入集合2中的元素;3、执行交集、并集、差集运算;二

3、系统模块结构设计通过对系统功能的分析,集合交并差系统功能如图1所示。集合的交并差运尊系统图1集合的交并差运算系统功能图通过上图的功能分析,把整个系统划分为 3个模块:1、集合的交集运算,该模块主要实现:找出集合1与集合2中相同的2、集合的并集运算,该模块主要实现:将集合1与集合2中的元素集 中于一起,并且全部输出,借助函数 void bing()来实现;3、集合的差集运算,该模块主要实现:集合1减去集合2输出所得结 果;集合2减去集合1输出所得结果,借助函数void cha()来实现。三、系统的设计与实现(一) 集合的交集运算:void jiao()分析:首先输出集合1与集合2的元素,然后输出

4、集合1与集合2中 相同的元素。流程图如图2所示。图 2: jiao(pointer *head1,pointer *head2, pointer *head3)流程图该模块的具体代码如下所示。void jiao(po in ter *head1,po in ter *head2, poin ter *head3)poi nter *p1,*p2,*p3;p1=head1->li nk;while(p1!=NULL)p2=head2->li nk;while(p2!=NULL)&&(p2->data!=p1->data)p2=p2->li nk;if

5、(p2!=NULL)&&(p2->data=p1->data)p3=(po in ter *)malloc(sizeof(struct poin ter);p3->data=p1->data;p3->li nk=head3->li nk;head3->li nk=p3;p1=p1->li nk;(二) 集合的并集运算:void bing()1与集合2中分析:首先输出集合1与集合2的元素,然后输出集合的全部元素。流程图如图3所示。流程图图 3: bin g(po in ter *head1,po in ter *head2, poi

6、n ter *head3)该模块的具体代码如下所示。void bin g(po in ter *head1,po in ter *head2, poin ter *head3)poi nter *p1,*p2,*p3;p1=head1->li nk;while(p1!=NULL)p3=(po in ter *)malloc(sizeof(struct poin ter);p3->data=p1->data;p3->li nk=head3->li nk;head3->li nk=p3;p1=p1->li nk;p2=head2->li nk;whi

7、le(p2!=NULL)p1=head1->li nk;while(p1!=NULL)&&(p1->data!=p2->data)p1=p1->li nk;if(p1=NULL)p3=(po in ter *)malloc(sizeof(struct poin ter);p3->data=p2->data;p3->li nk=head3->li nk;head3->li nk=p3;p2=p2->li nk;(三) 集合的差集运算: void cha()分析:首先输出集合1减去集合2的结果,然后输出集合2减去集合1中的

8、结果。流程图如图4所示。图 4: cha(pointer *head1,pointer *head2, pointer *head3)流程图该模块的具体代码如下所示。void cha_1(po in ter *head1,po in ter *head2, poin ter *head3)poi nter *p1,*p2,*p3;p1=head1->li nk;while(p1!=NULL)p2=head2->li nk;while(p2!=NULL) &&(p2->data!=p1->data)p2=p2->li nk;if(p2=NULL)p3

9、=(po in ter *)malloc(sizeof(struct poin ter);p3->data=p1->data;p3->li nk=head3->li nk;head3->li nk=p3;p1=p1->li nk;四、系统测试(一)测试main()函数测试该函数使用的测试方法,测试的具体步骤,测试用例的选取,测 试的结果。*集合用交*不憲运謀系统* 丰SS;苗S羽潮隅烬;SZSS直请顿入集含荃入讪:表示结朿请输入数据:图5系统界面(二)测试 void jiao() 函数测试该函数执行集合交集运算的执行结果。图6交集执行结果(三) 测试void

10、 bing()函数测试该函数执行集合并集运算的执行结果。E-J込曙 I茧盘贰饗'詡驚:事黄丫申苗毀號;图7并集执行结果(四) 测试void cha()函数测试该函数执行集合并集运算的执行结果。d s at合2是;igfd合与集合2差的值为;合2与集合差的值为二ljas图8差集执行结果五、总结系统完成了执行计算集合的交集、并集以及差集的功能。系统虽然完整运行,但也有缺乏。系统的设计未能考虑到集合元素的 唯一性,从键盘输入的集合元素在原样输出时,未能将重复元素剔除;再 者,系统未能实现选择性操作,即输入集合 1与集合2中的元素以后,按 Enter便输出交集、并集与差集的全部结果。我的收获:

11、通过课程设计,我学习到了许多内容。首先是对已学过的 内容的尤其是上学期C+有了更深入的理解。其次,在程序编译过程中,我 遇到了许许多多的问题,这些问题大多数都是小问题,主要是对问题思考 的不够全面的结果。但是在自己的反复检查、实验,以及老师的帮助下, 这些问题都一一解决了。而在解决问题的过程中,我能够了解到我设计中 的缺乏之处。程序编辑过程中,我也认识到了自己的缺乏,对已学过的知识是有所 理解,也能够合理地运用,但对细节方面有所忽略,这也正是刚开始时发 现程序无法正常运行却不知错在哪的原因。因此这让我懂得了,在学习的 过程中要认真仔细。最后,程序设计让我将以学过的知识综合运用,我感觉编译程序确

12、实很有意思。因为它不仅是一门课程,也是一门语言,我们要学好这门语言,就要了解这门语言的“语法结构 ,只有把话说清楚了,才能明白意思;也只有把“话说正确了,程序才能执行。六、附件(代码、局部图表)#include<stdio.h>#include<stdlib.h> typedef struct pointer char data;struct pointer *link; pointer;void readdata(pointer *head) pointer *p; char tmp;printf("t (输入 '0' 表示结束 )n&quo

13、t;);printf("t 请输入数据 :n"); scanf("%c",&tmp); while(tmp!='0')p=(pointer *)malloc(sizeof(struct pointer); p->data=tmp; p->link=head->link;head->link=p; scanf("%c",&tmp);void disp(pointer *head) pointer *p; p=head->link; while(p!=NULL) printf(

14、"%c",p->data); p=p->link;void jiao(pointer *head1,pointer *head2, pointer *head3) pointer *p1,*p2,*p3;p1=head1->link; while(p1!=NULL) p2=head2->link;while(p2!=NULL)&&(p2->data!=p1->data)p2=p2->link;if(p2!=NULL)&&(p2->data=p1->data)p3=(pointer *)ma

15、lloc(sizeof(struct pointer);p3->data=p1->data;p3->link=head3->link;head3->link=p3;p1=p1->link;void bing(pointer *head1,pointer *head2, pointer *head3)pointer *p1,*p2,*p3;p1=head1->link;while(p1!=NULL)p3=(pointer *)malloc(sizeof(struct pointer);p3->data=p1->data;p3->link

16、=head3->link;head3->link=p3;p1=p1->link;p2=head2->link;while(p2!=NULL)p1=head1->link;while(p1!=NULL)&&(p1->data!=p2->data)p1=p1->link;if(p1=NULL)p3=(pointer *)malloc(sizeof(struct pointer);p3->data=p2->data;p3->link=head3->link;head3->link=p3;p2=p2->

17、link;void cha_1(pointer *head1,pointer *head2, pointer *head3) pointer *p1,*p2,*p3;p1=head1->link;while(p1!=NULL) p2=head2->link; while(p2!=NULL)&&(p2->data!=p1->data) p2=p2->link;if(p2=NULL)p3=(pointer *)malloc(sizeof(struct pointer); p3->data=p1->data;p3->link=head3

18、->link; head3->link=p3;p1=p1->link;void cha_2(pointer *head1,pointer *head2, pointer *head3) pointer *p1,*p2,*p3;p2=head2->link;while(p2!=NULL) p1=head1->link; while(p1!=NULL)&&(p1->data!=p2->data) p1=p1->link;if(p1=NULL)p3=(pointer *)malloc(sizeof(struct pointer); p3

19、->data=p2->data;p3->link=head3->link;head3->link=p3;p2=p2->link;main() pointer *head1,*head2,*head3; head1=(pointer *)malloc(sizeof(struct pointer); head1->link=NULL;head2=(pointer *)malloc(sizeof(struct pointer); head2->link=NULL;head3=(pointer *)malloc(sizeof(struct pointer

20、);head3->link=NULL;printf("n");printf("n");printf("集合的交、并、差运算系统 n");printf(=请根据提示进行操作 = n");printf("n");printf(=下面开始执行操作步骤 = n");printf("n");printf("t请输入集合 1:n");readdata(head1);printf("t请输入集合 2:n");readdata(head2);pr

21、intf(" 集合 1 是 :n");disp(head1);printf("n 集合 2 是:n");disp(head2);printf("n 集合 1与集合 2 交的值为 :n");jiao(head1,head2,head3);disp(head3);head3->link=NULL;printf("n 集合 1与集合 2 并的值为 :n");bing(head1,head2,head3);disp(head3);head3->link=NULL;printf("n 集合 1与集合 2 差的值为 :n");cha_1(head1,head2,head3);disp(head3);printf("n 集合 2 与集合 1 差的值为 :n"); cha_2(head1,head2,head3);disp(head3);getch();

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 社会民生


经营许可证编号:宁ICP备18001539号-1