真值表编程
‘壹’ 怎么用C语言写一个程序,判断真值表的
//---------------------------------------------------------------------------
#include <stdio.h>
int main(void)
{
int p,q;
printf("%9c!P\t!Q\tP&Q\tP|Q\tP^Q\n");
for (p=0; p<2; p++) {
for (q=0; q<2; q++) {
printf("P=%d,Q=%d\t%3d\t%2d\t%2d\t%2d\t%2d\n",p,q,!p?1:0,!q?1:0,p&&q?1:0,p||q?1:0,p^q?1:0);
}
}
return 0;
}
//---------------------------------------------------------------------------
‘贰’ 用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]!='