命题公式的主合取范式C语言,用C或C++编写程序,要求:输入命题公式,给出它的主合取范式和主析取范式....

共回答了18个问题采纳率:83.3%

A-Z + is OR * is AND _ is → # is♁(圆圈里加个+) @ is ⊙

$ is ↑ 命题的"与非" 运算( "与非门" )

% is ↓ 命题的"或非"运算( "或非门" )

Input the source formula:

A*!S+R

Here!

8countTerms

NORMALc:(A*!S*!R)+(!A*!S*R)+(A*!S*R)+(!A*S*R)+(A*S*R)

NORMALd (A+S+R)*(A+!S+R)*(!A+!S+R)

!A+S*!R

Input the source formula:

(!A+B)_R

Here!

8countTerms

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:

A@B

Here!

4countTerms

NORMALc:(!A*!B)+(A*B)

NORMALd (!A+B)*(A+!B)

Error!

#include

#include

#include

#include

using namespace std;

class formulaBase

{

private:

int numVar;//The number of the variables in the formula

bool variables[100];//To store the value of the variables

string sourceFormula;

string normalCFormula;

string normalDFormula;

string dualFormula;

vector vctofVar;

vector vctofPoland;

stack 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 boolStk;

public:

formulaBase();

formulaBase(const formulaBase& rhs);

formulaBase();

void getSource();

string generateNormalC();

string generateNormalD();

string getDual();

void printSource()const{cout

1年前

7

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
C语言是一种广泛应用于系统编程和嵌入式开发的编程语言,它提供了丰富的语法和库函数来实现各种功能。在C语言中,输出真值表的合取范式主析取范式可以通过逻辑运算符和条件语句来实现。 合取范式(Conjunctive Normal Form,CNF)是一个逻辑表达式的一种标准形式,它由多个子句的合取构成,每个子句由多个文字的析取构成。在C语言中,可以使用逻辑运算符 &&(逻辑与)和 ||(逻辑或)来实现合取范式。 下面是一个示例代码,用于输出一个逻辑表达式的合取范式: ```c #include <stdio.h> int main() { int a, b, c; printf("a\tb\tc\tResult\n"); for (a = 0; a <= 1; a++) { for (b = 0; b <= 1; b++) { for (c = 0; c <= 1; c++) { int result = (a && b) || (!b && c); printf("%d\t%d\t%d\t%d\n", a, b, c, result); } } } return 0; } ``` 上述代码中,使用三个嵌套的循环遍历所有可能的输入组合,并计算逻辑表达式 `(a && b) || (!b && c)` 的结果。然后,将输入和结果输出到控制台。 主析取范式(Disjunctive Normal Form,DNF)是一个逻辑表达式的一种标准形式,它由多个子句的析取构成,每个子句由多个文字的合取构成。在C语言中,可以使用逻辑运算符 &&(逻辑与)和 ||(逻辑或)来实现主析取范式。 下面是一个示例代码,用于输出一个逻辑表达式的主析取范式: ```c #include <stdio.h> int main() { int a, b, c; printf("a\tb\tc\tResult\n"); for (a = 0; a <= 1; a++) { for (b = 0; b <= 1; b++) { for (c = 0; c <= 1; c++) { int result = (a || b) && (!b || c); printf("%d\t%d\t%d\t%d\n", a, b, c, result); } } } return 0; } ``` 上述代码中,同样使用三个嵌套的循环遍历所有可能的输入组合,并计算逻辑表达式 `(a || b) && (!b || c)` 的结果。然后,将输入和结果输出到控制台。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值