離散數(shù)學(xué)實(shí)驗(yàn)二:命題邏輯(2)_第1頁(yè)
離散數(shù)學(xué)實(shí)驗(yàn)二:命題邏輯(2)_第2頁(yè)
離散數(shù)學(xué)實(shí)驗(yàn)二:命題邏輯(2)_第3頁(yè)
離散數(shù)學(xué)實(shí)驗(yàn)二:命題邏輯(2)_第4頁(yè)
離散數(shù)學(xué)實(shí)驗(yàn)二:命題邏輯(2)_第5頁(yè)
已閱讀5頁(yè),還剩16頁(yè)未讀, 繼續(xù)免費(fèi)閱讀

下載本文檔

版權(quán)說(shuō)明:本文檔由用戶(hù)提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)

文檔簡(jiǎn)介

1、離散數(shù)學(xué)實(shí)驗(yàn)報(bào)告1【實(shí)驗(yàn)序號(hào)】實(shí)驗(yàn)二 命題邏輯(2)2【實(shí)驗(yàn)?zāi)康摹渴煜ふ莆彰}邏輯中真值表,進(jìn)一步能用它們來(lái)解決實(shí)際問(wèn)題。3【實(shí)驗(yàn)內(nèi)容】求任意一個(gè)命題公式的真值表4. 【實(shí)驗(yàn)要求】對(duì)于給定的命題公式,生成相應(yīng)真值表,然后用函數(shù)運(yùn)算,輸出結(jié)果:如生成邏輯非、合取、析取、條件、雙條件表達(dá)式的真值表,例如:輸入 !a輸出真值表如下:a !a0 11 0輸入a&&b輸出真值表如下:a b ab0 0 00 1 01 0 01 1 1輸入a|b輸出真值表如下:a b ab0 0 00 1 11 0 11 1 1輸入a->b輸出真值表如下:a b ab0 0 10 1 11 0 01

2、 1 1輸入a<>b (其中<>表示雙條件)輸出真值表如下:a b ab0 0 10 1 01 0 01 1 1通過(guò)以下界面提示實(shí)現(xiàn)相應(yīng)邏輯運(yùn)算,列出其真值表*請(qǐng)選擇(16)要進(jìn)行的真值表運(yùn)算:1. 邏輯非( P)2. 合?。≒Q)3. 析?。≒Q)4. 條件(PQ)5. 雙條件(PQ)6. 繼續(xù)/退出(y/n)*5. 【算法描述】真值表:列出命題公式真假值的表,通常以1表示真,0 表示假。命題公式的取值由組成命題公式的命題變?cè)娜≈岛兔}聯(lián)結(jié)詞決定,命題聯(lián)結(jié)詞的真值表給出了真假值的算法。 6. 【源程序(帶注釋?zhuān)?include<iostream>#in

3、clude<stdlib.h>using namespace std;class mathchar p, q;int result;public:math(char x, char y);int pdp(char x);int pdq(char y);void luojifei(char x, int t);void hequ(char x, char y, int t);void xiqu(char x, char y, int t);void tiaojian(char x, char y, int t);void shuangtiaojian(char x, char y,

4、int t);void caidan();void yunsuancaidan();void zzbcaidan();void zzbluojifei();void zzbhequ();void zzbxiqu();void zzbtiaojian();void zzbshuangtiaojian();void fengefu();math:math(char x, char y)p = x; q = y;/判斷p是否為1或0int math:pdp(char x)int a = 1;p = x;if (x != '0'&&x != '1')a

5、= 0;cin.clear();cin.ignore(100000, 'n');return a;/判斷q是否為1或0int math:pdq(char y)q = y;int a = 1;if (y != '0'&&y != '1')a = 0;cin.clear();cin.ignore(100000, 'n');return a;void math:luojifei(char x, int t)p = x; result = t;if (x = '1') t = 0;else if (x =

6、'0') t = 1;cout << "真值為:" << t <<",請(qǐng)繼續(xù)選擇選擇(1-6)要進(jìn)行的邏輯運(yùn)算:"/合取運(yùn)算void math:hequ(char x, char y, int t)p = x; q = y; result = t;if (x = '1'&&y = '1') t = 1;else t = 0;cout << "真值為:" << t <<",請(qǐng)繼續(xù)選擇選擇(1-

7、6)要進(jìn)行的邏輯運(yùn)算:"/析取運(yùn)算void math:xiqu(char x, char y, int t)p = x; q = y; result = t;if (x = '0'&&y = '0') t = 0;else t = 1;cout << "真值為:" << t <<",請(qǐng)繼續(xù)選擇選擇(1-6)要進(jìn)行的邏輯運(yùn)算:"/條件運(yùn)算void math:tiaojian(char x, char y, int t)p = x; q = y; result =

8、t;if (x = '1'&&y = '0') t = 0;else t = 1;cout << "真值為:" << t <<",請(qǐng)繼續(xù)選擇選擇(1-6)要進(jìn)行的邏輯運(yùn)算:"/雙條件運(yùn)算void math:shuangtiaojian(char x, char y, int t)p = x; q = y; result = t;if (x = y) t = 1;else t = 0;cout << "真值為:" << t <

9、;<",請(qǐng)繼續(xù)選擇選擇(1-6)要進(jìn)行的邏輯運(yùn)算:"/邏輯運(yùn)算菜單void math:caidan()cout << "1.邏輯運(yùn)算真值表" << endl;cout << "2.邏輯運(yùn)算" << endl;cout << "3.退出/繼續(xù)" << endl;cout << "請(qǐng)選擇(1-3)要進(jìn)行操作:"void math:yunsuancaidan()/*/cout << "1.邏

10、輯非( P)" << endl;cout << "2.合取運(yùn)算(PQ)" << endl;cout << "3.析取運(yùn)算(PQ)" << endl;cout << "4.條件運(yùn)算(PQ)" << endl;cout << "5.雙條件運(yùn)算(PQ)" << endl;cout << "6.返回上級(jí)菜單" << endl;cout << "

11、;請(qǐng)選擇(1-6)要進(jìn)行的邏輯運(yùn)算:"void math:zzbcaidan()cout << "1.邏輯非( P)真值表" << endl;cout << "2.合取運(yùn)算(PQ)真值表" << endl;cout << "3.析取運(yùn)算(PQ)真值表" << endl;cout << "4.條件運(yùn)算(PQ)真值表" << endl;cout << "5.雙條件運(yùn)算(PQ)真值表"

12、 << endl;cout << "6.返回上級(jí)菜單" << endl;cout << "請(qǐng)選擇(1-6)查看真值表:"void math:zzbluojifei()cout << "a !a" << endl;cout << "0 1" << endl;cout << "1 0" << endl;cout << "請(qǐng)選擇(1-6)查看真值表:"

13、void math:zzbhequ()cout << "a b ab" << endl;cout << "0 0 0" << endl;cout << "0 1 0" << endl;cout << "1 0 0" << endl;cout << "1 1 1" << endl;cout << "請(qǐng)選擇(1-6)查看真值表:"void math:

14、zzbxiqu()cout << "a b ab" << endl;cout << "0 0 0" << endl;cout << "0 1 1" << endl;cout << "1 0 1" << endl;cout << "1 1 1" << endl;cout << "請(qǐng)選擇(1-6)查看真值表:"void math:zzbtiaojia

15、n()cout << "a b ab" << endl;cout << "0 0 1" << endl;cout << "0 1 1" << endl;cout << "1 0 0" << endl;cout << "1 1 1" << endl;cout << "請(qǐng)選擇(1-6)查看真值表:"void math:zzbshuangtiaojia

16、n()cout << "a b ab" << endl;cout << "0 0 1" << endl;cout << "0 1 0" << endl;cout << "1 0 0" << endl;cout << "1 1 1" << endl;cout << "請(qǐng)選擇(1-6)查看真值表:" ;void math:fengefu()cout

17、<< "#" << endl;void main()char x = '0', y = '0', n = '0', n1, n2, n3;int t = 0;math math1(x, y);loop:cin.clear();cin.sync();math1.fengefu();math1.caidan();while (n)switch (n = cin.get()case '1':cin.clear();/cin.ignore(100000, 'n');cin.syn

18、c();math1.fengefu();math1.zzbcaidan();loop2:switch (n1 = cin.get()case '1':math1.zzbluojifei();break;case '2':math1.zzbhequ();break;case '3':math1.zzbxiqu();break;case '4':math1.zzbtiaojian();break;case '5':math1.zzbshuangtiaojian();break;case '6':goto

19、 loop;break;default:cin.clear();/cin.ignore(100000, 'n');cin.sync();cout << "輸入錯(cuò)誤,請(qǐng)選擇(1-6)查看真值表:"goto loop2;break;cin.clear();cin.sync();goto loop2;break;case '2':cin.clear();/cin.ignore(100000, 'n');cin.sync();math1.fengefu();cout << "輸入P:"x =

20、 cin.get();while (math1.pdp(x) = 0)cout << "輸入錯(cuò)誤,重新輸入P:"x = cin.get();cout << "輸入Q:"y = cin.get();while (math1.pdq(y) = 0)cout << "輸入錯(cuò)誤,重新輸入Q:"y = cin.get();math1.yunsuancaidan();loop3:switch (n2 = cin.get()/*case '1':math1.luojifei(x, t);break

21、;case '2':math1.hequ(x, y, t);break;case '3':math1.xiqu(x, y, t);break;case '4':math1.tiaojian(x, y, t);break;case '5':math1.shuangtiaojian(x, y, t);break;case '6':goto loop;break;*/case '1':math1.luojifei(x, t);break;case '2':math1.hequ(x, y, t);break;case '3':math1.xiqu(x, y, t);break;case '4':math1.tiaojian(x, y, t);break;case '5':math1.shuangtiaoj

溫馨提示

  • 1. 本站所有資源如無(wú)特殊說(shuō)明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶(hù)所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁(yè)內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒(méi)有圖紙預(yù)覽就沒(méi)有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫(kù)網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶(hù)上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶(hù)上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶(hù)因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。

評(píng)論

0/150

提交評(píng)論