集合上二元关系性质判定的实现选编.doc

《离散数学》实验报告 (20/ 2016 学年 第 学期) 班 级 学 号 指 导 教 师 指 导 单 位 计算机学院计算机科学与技术系 日 期 2015年10月20日 集合上二元关系性质判定的实现 实验内容和要求 内容: 。 要求: 。 二、 能够利用编程正确判定任意二元关系的自反性、对称性、传递性、反自反性和反对称性。 函数Analagmatic() 通过判断矩阵主对角线是否为1。 函数Irreflexive() 通过判断矩阵主对角线是否为0。 函数Symmetry() 判断矩阵A[x][y]是否等于A[y][x] 函数Antisymmetry() 判断A[x][y]*A[y][x]是否为1 函数Transitivity() 判断A[x][p]*A[p][y]==1A[x][y]是否为1 以上各函数皆通过将集合化为矩阵并用循环遍历实现。 四、 #includeiostream #includefstream using namespace std; int A[100][100]; int n; void Input() //输入函数 { cout请输入元素个数:; cinn; cout请输入相应的n阶矩阵(0,1)endl; for(int i=0;in;i++) { for(int j=0;jn;j++) { cinA[i][j]; } } } void Analagmatic() { for(int x=0;xnA[x][x]==1;x++) { } if (x==n) cout该二元关系具有自反性endl; else cout该二元关系不具有自反性endl; } void Irreflexive() { for(int x=0;xnA[x][x]==0;x++) { } if(x==n) cout该二元关系具有反自反性endl; else cout该二元关系不具有反自反性endl; } void Symmetry() { for(int x=0;xn;x++) { for(int y=0;ynA[x][y]==A[y][x];y++); { } if(y!=n) { cout该二元关系不具有对称性endl;return; } } cout该二元关系具有对称性endl; } void Antisymmetry(){ for(int x=0;xn;x++) { for(int y=0;(ynA[x][y]*A[y][x]!=1)||(ynx==y);y++); { } if(y!=n) { cout该二元关系不具有反对称性endl;return; } } cout该二元关系具有反对称性endl; } void Transitivity()//判断传递性 { int s=1; for(int x=0;xn;x++) { int p=0; for(int y=0;xy;y++) { if(A[x][p]*A[p][y]==1A[x][y]!=1) s=0; } p++; } if(s==0) cout该二元关系不具有传递性endl; else cout该二元关系具有传递性endl; } int main() { Input(); Analagmatic(); Irreflexive(); Symmetry(); Antisymmetry(); Transitivity(); return 0; } 五、测试数据及其结果分析 调试过程中的问题 七、设计总结 上机时的表现 学习态度 算法思想准备情况 程序设计能力 解决问题能力 课题功能实现情况 算法设计合理性 算法效能评价 报告书写认真程度 内容详实程度 文字表达熟练程度 回答问题准确度 简 短 评 语 教师签名:

文档评论(0)

1亿VIP精品文档

相关文档