《离散数学》加分题:已知命题p和q的真值,求他们的合取、析取、异或……

1 已知命题p和q的真值,求他们的合取、析取、异或、条件语句和双条件语句的真值。

从命令行输入p、q的真值,计算并输出出组合的真值


代码如下:

#include<iostream>
#include<iomanip>
using namespace std;

template<class R1,class R2>
R1 Conjunction(R1 a,R2 b)
{
	int i;
	if(a==1&&b==1)
		i=1;
	else
		i=0;
	cout<<"p和q的合取:p∧q="<<i<<endl;
	return i;
}

template<class P1,class P2>
P1 Disjunction(P1 a,P2 b)
{
	int i;
	if(a==0||b==0)
		i=0;
	else
		i=1;
	cout<<"p和q的析取:p∨q="<<i<<endl;
	return i;
}

template<class M1,class M2>
M1 C_Statements(M1 a,M2 b)
{
	int i;
	if(a==0||(a==1&&b==1))
		i=1;
	else
		i=0;
	cout<<"p和q的条件语句:p→q="<<i<<endl;
	return i;
}

template<class N1,class N2>
N1 Biconditonals(N1 a,N2 b)
{
	int i;
	if(a==b)
		i=1;
	else
		i=0;
	cout<<"p和q的双条件语句:p<->q="<<i<<endl;
	return i;
}




void main()
{
	int p,q;
	char c='Y';
	cout<<"\t**************************************************"<<endl
		<<"\t**                                              **"<<endl
		<<"\t**已知命题p和q的真值,求他们的合取、析取、异或、**"<<endl
		<<"\t**条件语句和双条件语句的真值。从命令行输入p、q的**"<<endl
		<<"\t**真值,计算并输出出组合的真值                  **"<<endl
		<<"\t**                                              **"<<endl
		<<"\t**************************************************"<<endl;
	cout<<endl;
	while(c=='Y'||c=='y')
	{
	cout<<"请输入p的真值(0或1):";
	cin>>p;
	cout<<"请输入q的真值(0或1):";
	cin>>q;
	Conjunction(p,q);
	Disjunction(p,q);
	C_Statements(p,q);
	Biconditonals(p,q);
	cout<<"是否继续(Y/N):";
	cin>>c;
	cout<<endl;
	}
}




运行结果如下:

《离散数学》加分题:已知命题p和q的真值,求他们的合取、析取、异或……_第1张图片


你可能感兴趣的:(《离散数学》加分题:已知命题p和q的真值,求他们的合取、析取、异或……)