下载此文档

离散数学实验报告(一).doc


文档分类:高等教育 | 页数:约20页 举报非法文档有奖
1/20
下载提示
  • 1.该资料是网友上传的,本站提供全文预览,预览什么样,下载就什么样。
  • 2.下载该文档所得收入归上传者、原创者。
  • 3.下载的文档,不会出现我们的网址水印。
1/20 下载此文档
文档列表 文档介绍
离散数学实验报告(一).doc—、实验内容:构造任意合式公式的真值表
二、实验源码:
#include <>
#include""
int main()
{
Thesis a[30];
char x='1';
int i=O,N;
cout«"请输入命题变元(不超过30个)(输入O结束 输入):"«endl;
while(int(x)!=48)
{
cin> >x;
{cout«"Error:变元个数太多!"«endl;break;}
if(x!='O')
{
a[i].i nn ame(x);
i++;
}
}
N=i;
int M;
M=N;
string A;
cout«"请输入命题公式(否定:!,合取:& ,析取:
| )"«endl;
cin»A;
cout«A«"的真值表为:"«endl;
for(int j=O;j<M;j++)
cout«char(a[j].getvalue())«""
cout«"真值"«endl;
assig nm ent(A,N,M,&a[O]);
system("pause");
return 0;
}
#include""头文件
#ifndefTHESIS_H
#define THESIS_H
#in clude<string> #in clude<>
#in clude<iostream> using namespace std;
class Thesis 〃命题类
{
int value;char name; //value:命题的真值(0/1 )
name :命题名
public:
Thesis(){value=2;name-A';};
friend Thesis operator !(Thesis &q)
{(1-()); return q;} //
重载逻辑运算符
friend Thesis operator &(Thesis &p,Thesis &q)
{((()+())/2); return
P;}
friend Thesis operator |(Thesis &p,Thesis &q)
{if(()+()>O) (1);
else (O);
return p;}
friend Thesis operator >(Thesis &p,Thesis &q)
{if(()==1&&()==0)
value(O);
else (1);
return p;}
friend Thesis operator <(Thesis &p,Thesis &q)
{if(()==()) value(1);
else (O);
return p;}
void invalue(int x){value=x;} 〃输入 value
void inname(char x){name=x;} 〃输入
n ame
〃获取真值
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(intj=0;j<2;j++)
{
a[N-1].invalue(j);
assignment(A,N-1 ,M,&a[O]);
}
else
{
for(int i=O;i<M;i++)
{
cout«a[i].getvalue()«""
} cout«bds(A,M,&a[0])«endl;
}
}
〃识别输
}
int bds(string A,int N,Thesis a[])
入的表达式并计算真值
Thesis answer,Temp;
char d[5]〃定义运算符号集合

离散数学实验报告(一) 来自淘豆网m.daumloan.com转载请标明出处.

相关文档 更多>>
非法内容举报中心
文档信息
  • 页数20
  • 收藏数0 收藏
  • 顶次数0
  • 上传人蓝天
  • 文件大小72 KB
  • 时间2021-07-22
最近更新