編程真值表
① 怎麼將真值表轉換成邏輯函數表達式
做編程的沒幾個會電子技術的,你最好去電子方面的網站上搜下!在這里你很難得到滿意的答案
② 離散數學編程:要求編寫一段代碼,輸入任意一個復合命題公式,判斷該命題的真值並輸出真值表
你學號多少?
③ 真值表可以用來表示數字量的邏輯運算關系嗎
與-或式;與非-與非式;與或非式;或非-或非式;
邏輯函數的幾種表示方法
◆ 布爾代數法
按一定邏輯規律進行運算的代數.與普通代數不同,布爾代數中的變數是二元值的邏輯變數.
◆ 真值表法
採用一種表格來表示邏輯函數的運算關系,其中輸入部分列出輸入邏輯變數的所有可能組合,輸出部分給出相應的輸出邏輯變數值.
◆ 邏輯圖法
採用規定的圖形符號,來構成邏輯函數運算關系的網路圖形.
◆ 卡諾圖法
卡諾圖是一種幾何圖形,可以用來表示和簡化邏輯函數表達式.
◆ 波形圖法
一種表示輸入輸出變數動態變化的圖形,反映了函數值隨時間變化的規律.
◆ 點陣圖法
是早期可編程邏輯器件中直觀描述邏輯函數的一種方法.◆ 硬體設計語言法法
④ 用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]!='