版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
1、构造任意合式公式的真值表#include stdio.h #includethesis.h int main()thesis a30; char x=1; int i=0,n;cout请输入命题变元(不超过 30 个)(输入0结束输 入 ):x; if(i19)couterror:变元个数太多!endl;break;if(x!=0)ai.inname(x); i+;n=i;int m;m=n;string a;cout请输入命题公式( 否定:!,合取:&,析取:| )a;couta的真值表为:endl;for(int j=0;jm;j+) coutchar(aj.getvalue(); cou
2、t 真 值 endl; assignment(a,n,m,&a0);system(pause); return 0;#includethesis.h#ifndef thesis_h #define thesis_h #include#include #include using namespace std;class thesis/命题类int value;char name;/value:命题的真值( 0/1) name:命题名public:thesis()value=2;name=a; friend thesis operator !(thesis &q)q.invalue(1-q.get
3、value(); return q;/重载逻辑运算符friend thesis operator &(thesis &p,thesis &q)p.invalue(p.getvalue()+q.getvalue()/2); return p; friend thesis operator |(thesis &p,thesis &q)if(p.getvalue()+q.getvalue()0) p.invalue(1); else p.invalue(0);return p;friend thesis operator (thesis &p,thesis &q)if(p.getvalue()=1&
4、q.getvalue()=0) p.invalue(0);else p.invalue(1);return p;friend thesis operator (thesis &p,thesis &q)if(p.getvalue()=q.getvalue()p.invalue(1); else p.invalue(0);return p;void invalue(int x)value=x;/ 输 入 value void inname(char x)name=x;/输入 name int getvalue()return value;/获取真值int getname()return name;
5、/获取命题名;void assignment(string a,int n,int m,thesis a);/声明函数int bds(string a,int n,thesis a);int run(string a,int &i,int l,int n,thesis a);void assignment(string a,int n,int m,thesis a)/命题赋值并计算真值for(int j=0;j1)assignment(a,n-1,m,&a0);elsefor(int i=0;im;i+)coutai.getvalue();coutbds(a,m,&a0),;/定义运算符号集合
6、int l;int i=0;l=strlen(&a0);/表达式长度while(il)if(ai=()int k=1;for(int j=i+2;jl;j+)if(k!=0)if(aj=() k+; if(aj=)k-;if(k=0)int l=j-i-1;char *p=new charl+1; string b;for(int m=0;ml;m+) pm=ai+1+m;pl=0;b=p;elsedelete p; temp.invalue(bds(b,n,&a0); if(i=0)answer.invalue(temp.getvalue(); i=j+1;break;if(ai=!)/否定
7、的计算temp.invalue(run(a,i,l,n,&a0); answer=!temp;i+;continue;else if(ai=|)temp.invalue(run(a,i,l,n,&a0); answer=answer|temp;i+;continue;else if(ai=&)temp.invalue(run(a,i,l,n,&a0); answer=answer&temp;i+;continue;else if(ai=)temp.invalue(run(a,i,l,n,&a0); answer=answer)temp.invalue(run(a,i,l,n,&a0); ans
8、wer=answertemp;i+;continue;elsefor(int j=0;jn;j+)if(ai=char(aj.getname()temp.invalue(aj.getvalue(); if(i=0)answer.invalue(temp.getvalue(); i+;break;return answer.getvalue();int run(string a,int &i,int l,int n,thesis a)thesis temp;if(ai+1=()int k=1;for(int j=i+2;jl;j+)if(k!=0)if(aj=() k+; if(aj=)k-;i
9、f(k=0)int l=j-i-1;char *p=new charl+1; string b;for(int m=0;ml-1;m+) pm=ai+2+m;pl-1=0;b=p;delete p;temp.invalue(bds(b,n,&a0); i=i+j;break;elseint j=0; while(jl)if(ai+1=char(aj.getname()i+;temp=aj; break;j+;return temp.getvalue();#endif“”“”at the end, xiao bian gives you a passage. minand once said,
10、people who learn to learn are very happy people. in every wonderful life, learning is an eternal theme. as a professional clerical and teaching position, i understand the importance of continuous learning, life is diligent, nothing can be gained, only continuous learning can achieve better self. only by constantly learning and mastering the latest relevant knowledge, can employees from all walks of life keep up with the pace of enterprise development and innovate to meet
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 工会2025年度工作报告国企2025工会工作报告
- 2025-2030中国母婴用品行业供需状况与投资风险评估报告
- 山东省青岛市黄岛区弘文校2026届初三下学期六校联考(2月)物理试题试卷含解析
- 四川省达州市通川区2025-2026学年初三联考评估卷(八)语文试题含解析
- 吉林省长春市二道区2025-2026学年初三年级下学期第一次考试语文试题试卷含解析
- 陕西省西安市雁塔区高新一中达标名校2025-2026学年初三下学期5月质量检测试题语文试题试卷含解析
- 台州市重点中学2026届初三联合调研考试物理试题试卷含解析
- 湖北恩施沐抚大峡谷2026年初三下学期1月月考试题语文试题试卷含解析
- 辽宁省丹东市第五中学2025-2026学年初三下学期寒假收心模拟考试语文试题试卷含解析
- (正式版)DB37∕T 3041-2017 《饲料中磷、硫的测定 电感耦合等离子体原子发射光谱法》
- 2026年及未来5年市场数据中国税务大数据行业市场全景分析及投资前景展望报告
- 24J113-1 内隔墙-轻质条板(一)
- 小区道路及室外管网配套工程施工设计方案
- 轨道交通防水工程施工质量验收标准
- 2026年乌海职业技术学院单招职业技能测试题库及一套答案详解
- 华南地区地理知识
- GB/T 4025-2010人机界面标志标识的基本和安全规则指示器和操作器件的编码规则
- GB/T 23901.5-2019无损检测射线照相检测图像质量第5部分:双丝型像质计图像不清晰度的测定
- GB/T 10665-2004碳化钙(电石)
- 工会经费使用管理常见问题解答
- 制药工程导论课件
评论
0/150
提交评论