构造命题公式的真值表--biaobiao88
对给出的任意一个命题公式(不超过四个命题变元),使学生会用C语言的程序编程表示出来,并且能够计算它在各组真值指派下所应有的真值,画出其真值表。
#include<iostream>
using namespace std;
struct
{
int p[] = {,,,};
int q[] = {,,,};
}m; int main()
{
cout << " p:";
for(int i = ;i < ;i++)
cout << m.p[i] << " ";
cout << endl;
cout << " q:";
for(int i = ;i < ;i++)
cout << m.q[i] << " ";
cout << endl;
//非p
cout << " 非p:";
int copyp[];
int k = ;
int feip[k];
for(int i = ;i < ;i++)
copyp[i] = m.p[i];
for(int i = ;i < ;i++)
{
if(copyp[i] == )
copyp[i] = ;
else
copyp[i] = ;
}
for(int i = ;i < ;i++)
{
feip[i] = copyp[i];
cout << copyp[i] << " ";
}
cout << endl;
//p交q
cout << "p合取q:";
for(int i = ;i < ;i++)
{
if(m.p[i] == || m.q[i] == )
cout << << " ";
else
cout << << " ";
}
cout << endl;
//p并q
cout << "p析取q:";
for(int i = ;i < ;i++)
{
if(m.p[i] == || m.q[i] == )
cout << << " ";
else
cout << << " ";
}
cout << endl;
//p蕴含q
cout << "p蕴含q:";
for(int i = ;i < ;i++)
{
if(feip[i] == || m.q[i] == )
cout << << " ";
else
cout << << " ";
}
cout << endl;
//p当且仅当q
cout << "p等价q:";
for(int i = ;i < ;i++)
{
if((m.p[i] == && m.q[i] == ) || (m.p[i] == && m.q[i] == ))
cout << << " ";
else
cout << << " ";
}
cout << endl;
return ;
}
运行结果:
以下代码为可输入的代码,用布尔值实现
#include<iostream>
using namespace std; void function(bool x,bool y)
{
bool m = x&y;
bool n = x|y;
bool a,b,c;
if(x == && y == )
a = ;
else
a = ;
if(y == && x == )
b = ;
else
b = ;
if(x == y)
c = ;
else
c = ;
cout << "p q ﹁p ﹁q p∩q p∪q p→q q→p p←→p p⊕q" << endl;
cout << x << " " << y << " " << !x << " " << !y << " ";
cout << m << " " << n << " ";
cout << a << " " << b << " " << c << " " << !c << endl;
} int main()
{
bool p,q;
int n;
cout << "请输入需要测试几组数据:";
cin >> n;
while(n--)
{
cout << "请输入命题p和命题q的真值:";
cin >> p >> q;
function(p,q);
}
return ;
}
运行结果:
构造命题公式的真值表--biaobiao88的更多相关文章
- C++实现求离散数学命题公式的真值表
一.实验内容 (1)求任意一个命题公式的真值表. (2)利用真值表求任意一个命题公式的主范式. (3)利用真值表进行逻辑推理. 注:(2)和(3)可在(1)的基础上完成. 二.实验目的 真值表是命题逻 ...
- [转]EXCEL如何使用动态公式
本文转自:http://tech.cncms.com/ruanjian/office/excel/95440.html 也许大家可能还不知道Excel中的动态公式是什么,所谓的动态公式,不是普通的公式 ...
- 【译】N 皇后问题 – 构造法原理与证明 时间复杂度O(1)
[原] E.J.Hoffman; J.C.Loessi; R.C.Moore The Johns Hopkins University Applied Physics Laboratory *[译]* ...
- 证明与计算(3): 二分决策图(Binary Decision Diagram, BDD)
0x01 布尔代数(Boolean algebra) 大名鼎鼎鼎的stephen wolfram在2015年的时候写了一篇介绍George Boole的文章:George Boole: A 200-Y ...
- 合(析)取范式转主合(析)取范式--》Java实现
这次老师布置了如下上机作业,不限语言.思前想后,问了几个大神,说了一堆不知道什么鬼的算法名称.... 经过一番百度,发现Java可以包含库然后使用JavaScript的一些函数,其中eval() 函数 ...
- 解释器模式 Interpreter 行为型 设计模式(十九)
解释器模式(Interpreter) 考虑上图中计算器的例子 设计可以用于计算加减运算(简单起见,省略乘除),你会怎么做? 你可能会定义一个工具类,工具类中有N多静态方法 比如定义了两个 ...
- PHP练习题一
目录:1.如何使用php导入导出csv?2.php接收POST数据的方式有哪些?3.如何让json_encode()不转义斜杠?我在做服务器返回一些数据时需要返回一些地址,但是默认的json_code ...
- Proposition
提供 \(k\) 个变量 \((k\leq 4)\) 可独立取值为 \(0,1\),两种运算分别等价于 \(\neg a\) 和 \(\neg a \lor b\) . 你需要恰好使用 \(n\) 个 ...
- Poj (3239),m皇后问题
题目链接:http://poj.org/problem?id=3239 构造法很牛逼啊,把这个搜索的题直接变成了打表. 我用dfs写了一下. 构造法公式(序列):一.当n mod 6 != 2 或 n ...
随机推荐
- 2. chromium开发工具--gclient
1.gclient简介 gclient是谷歌开发的一套跨平台git仓库管理工具,用来将多个git仓库组成一个solution进行管理.总体上,其核心功能是根据一个Solution的DEPS文件所定义的 ...
- 【转】Spring全家桶
Spring框架自诞生以来一直备受开发者青睐,有人亲切的称之为:Spring 全家桶.它包括SpringMVC.SpringBoot.Spring Cloud.Spring Cloud Dataflo ...
- DES介绍
DES对称加密算法中的一种.是一个分组加密算法. 密钥长64位.(密钥事实上是56位参与DES运算(第8.16.24.32.40.48.56.64位是校验位)56 位 8位奇偶校验位. DES算 ...
- 论文阅读笔记六十六:Wide Activation for Efficient and Accurate Image Super-Resolution(CVPR2018)
论文原址:https://arxiv.org/abs/1808.08718 代码:https://github.com/JiahuiYu/wdsr_ntire2018 摘要 本文证明在SISR中在Re ...
- python之路—从入门到放弃
python基础部分 函数 初识函数 函数进阶 装饰器函数 迭代器和生成器 内置函数和匿名函数 递归函数 常用模块 常用模块 模块和包 面向对象 初识面向对象 面向对象进阶 网络编程 网络编程 并发编 ...
- <binary search> 154 162
154. Find Minimum in Rotated Sorted Array II 当数组中存在大量的重复数字时,就会破坏二分查找法的机制,将无法取得 O(lgn) 的时间复杂度,又将会回到简单 ...
- A1033 To Fill or Not to Fill (25 分)
一.技术总结 是贪心算法的题目,题目主要考虑的问题有几个,是否会在第一个加油站的最近距离大于0,如果是这样那么直接输出答案,因为初始油箱没有汽油: 第二个是如何选定加油站,如果在可到达距离范围类,我们 ...
- [LeetCode] 536. Construct Binary Tree from String 从字符串创建二叉树
You need to construct a binary tree from a string consisting of parenthesis and integers. The whole ...
- [LeetCode] 464. Can I Win 我能赢吗
In the "100 game," two players take turns adding, to a running total, any integer from 1.. ...
- [LeetCode] 78. Subsets 子集合
Given a set of distinct integers, S, return all possible subsets. Note: Elements in a subset must be ...