编程真值表
① 怎么将真值表转换成逻辑函数表达式
做编程的没几个会电子技术的,你最好去电子方面的网站上搜下!在这里你很难得到满意的答案
② 离散数学编程:要求编写一段代码,输入任意一个复合命题公式,判断该命题的真值并输出真值表
你学号多少?
③ 真值表可以用来表示数字量的逻辑运算关系吗
与-或式;与非-与非式;与或非式;或非-或非式;
逻辑函数的几种表示方法
◆ 布尔代数法
按一定逻辑规律进行运算的代数.与普通代数不同,布尔代数中的变量是二元值的逻辑变量.
◆ 真值表法
采用一种表格来表示逻辑函数的运算关系,其中输入部分列出输入逻辑变量的所有可能组合,输出部分给出相应的输出逻辑变量值.
◆ 逻辑图法
采用规定的图形符号,来构成逻辑函数运算关系的网络图形.
◆ 卡诺图法
卡诺图是一种几何图形,可以用来表示和简化逻辑函数表达式.
◆ 波形图法
一种表示输入输出变量动态变化的图形,反映了函数值随时间变化的规律.
◆ 点阵图法
是早期可编程逻辑器件中直观描述逻辑函数的一种方法.◆ 硬件设计语言法法
④ 用C++编程构造(P∧(P→Q))→Q的真值表
(P∧(P->Q))->Q
p->Q等价于(┐P)∨Q写成C/C++语言就是(!P)||Q
P∧(P->Q)等价于P∧((┐p)∨Q)写成C/C++就是P&&((!P)||Q))
(P∧(P->Q))->Q等价于(┐(P∧((┐p)∨Q)))∨Q写成C/C++语言就是(!(P&&((!P)||Q))))||Q
Programe Code:
#include <iostream>
using namespace std;
int main()
{
int Q,P;
cout<<"P Q (P∧(P->Q))->Q\n";
for(P=0;P<=1;P++)
for(Q=0;Q<=1;Q++)
cout<<P<<" "<<Q<<" "
<<((!(P&&((!P)||Q)))||Q)<<endl;
}
//运行结果
P Q (P∧(P->Q))->Q
0 0 1
0 1 1
1 0 1
1 1 1
其实你可以将表达式化简:
┐(P∧((┐p)∨Q))∨Q
<=> ┐((P∧┐p)∨(P∧Q)))∨Q
<=> ┐(0∨(P∨Q)))∨Q
<=> 1 ∨((┐(P∨Q))∨Q)
<=> 1
⑤ 用C语言编程:输入命题公式的合式公式,求出公式的真值表,并输出该公式的主合取范式和主析取范式
A-Z + is OR * is AND _ is → # is⊕(圆圈里加个+) @ is ⊙
$ is ↑ 命题的"与非" 运算( "与非门" )
% is ↓ 命题的"或非"运算( "或非门" )
Input the source formula:
A*!S+R
NORMALc: (!A*!B*!R)+(A*!B*!R)+(!A*B*!R)+(A*B*!R)+(!A*!B*R)+(!A*B*R)+(A*B*R)
NORMALd (!A+B+!R)
Error!
Input the source formula:
A#B
Here!
4countTerms
NORMALc: (A*!B)+(!A*B)
NORMALd (A+B)*(!A+!B)
Error!
Input the source formula:
stack<char> stk;
bool isVar(char ch)const;
void addMin(int minterm);
void addMax(int maxterm);
bool compute(int minterm);
void getInversePoland();
int countTerms(int n);
void assign(int minterm);
stack<bool> boolStk;
public:
formulaBase();
formulaBase(const formulaBase& rhs);
~formulaBase();
void getSource();
cout<<"Invalid input !"
"Operate again:"<<endl;
cin>>sourceFormula;*/
}
void formulaBase::getInversePoland()
{
char temp,temp1;
for(int i=0;sourceFormula[i]!='