assignment(A,N,M,&a[0]);
system("pause");
return 0;
}
#include"thesis.h"
#ifndef THESIS_H
#define THESIS_H
#include
#include
#include
using namespace std;
class Thesis //命题类
{
int value;char name; //value:命题的真值
(0/1) name:命题名
public:
Thesis(){value=2;name='A';};
friend Thesis operator !(Thesis &q)
{q.invalue(1-q.getvalue()); return q;} //重载逻辑运算符
friend Thesis operator &(Thesis &p,Thesis &q)
{p.invalue((p.getvalue()+q.getvalue())/2);
return p;}
friend Thesis operator |(Thesis &p,Thesis &q)
{if(p.getvalue()+q.getvalue()>0)
p.invalue(1);
else p.invalue(0);
return p;}
friend Thesis operator >(Thesis &p,Thesis &q)
{if(p.getvalue()==1&&q.getvalue()==0)
p.invalue(0);
else p.invalue(1);
return p;}
friend Thesis operator <(Thesis &p,Thesis &q) {if(p.getvalue()==q.getvalue())
p.invalue(1);
else p.invalue(0);
return p;}
void invalue(int x){value=x;} //输入value
void inname(char x){name=x;} //输入name
int getvalue(){return value;} //获取
真值
int getname(){return name;} //获取命题
名
};
void assignment(string A,int N,int M,Thesis a[]); //声明函数
int bds(string A,int N,Thesis a[]);
int run(string A,int &i,int L,int N,Thesis a[]);
void assignment(string A,int N,int M,Thesis a[])//命题赋值并计算真值
{
for(int j=0;j<2;j++)
{
a[N-1].invalue(j);
if(N>1)
{
assignment(A,N-1,M,&a[0]);
}
else
{
for(int i=0;i{
cout<}
cout<}
}
}
int bds(string A,int N,Thesis a[]) //
识别输入的表达式并计算真值
{
Thesis answer,Temp;
char d[5]={'!','|','&','>','<'}; //定义运算符号集合
int L;
int i=0;
L=strlen(&A[0]); //表达式长度
while(i{
if(A[i]=='(')
{
int k=1;
for(int j=i+2;j{
if(k!=0)
{
if(A[j]=='(')
k++;
if(A[j]==')')
k--;
}