【文章內(nèi)容簡(jiǎn)介】
三角形問題實(shí)現(xiàn)的偽代碼 Program triangle2 ‘ version of simple Dim a,b,c As Integer Dim IsATriangle As Boolean ‘ Step1: Get Input Output(? Enter 3 integers which are sides of a triangle? ) Input(a,b,c) Output(? Side A is ? ,a) Output(? Side B is ? ,b) Output(? Side C is ? ,c) ‘ Step 2:Is A Triangle? If (ab+c) AND(ba+c)AND(ca+b) Then IsATriangle =True Else IsATriangle =False EndIf ‘ step3:Determine Triangle Type If IsATrangle Then if(a=b)AND (b=c) Then Output(? Equilateral? ) Else If(ab)AND(ac)AND(bc) Then Output(? Scalence? ) Else Output(? Isosecles? ) EndIf EndIf Else Output(? NOT a Triangle? ) EndIf End triangle2 IT Education Training 三角形問題實(shí)現(xiàn)的偽代碼 Program triangle3 ‘ improved version Dim a,b,c As Integer Dim IsATriangle As Boolean ‘ Step1: Get Input Do Output(? Enter 3 integers which are sides of a triangle? ) Input(a,b,c) c1=(1=a)AND(a=200) c2=(1=b)AND(b=200) c3=(1=c)AND(c=200) If NOT(c1) Then Output(? Value of a is not in the range of permitted values? ) EndIf If NOT(c2) Then Output(? Value of b is not in the range of permitted values? ) EndIf If NOT(c3) Then Output(? Value of c is not in the range of permitted values? ) EndIf Until c1 AND c2 AND c3 Output(? Side A is ? ,a) Output(? Side B is ? ,b) Output(? Side C is ? ,c) …… ‘ Step2 …… ’ Step3 End triangle3 IT Education Training NextDate函數(shù) ?輸入變量之間的邏輯比較復(fù)雜 ?有兩種復(fù)雜性來源:輸入域和閏年規(guī)則 ? 80%活動(dòng)出現(xiàn)在 20%的空間 IT Education Training NextDate 問題陳述 ? NextDate是一個(gè)有三個(gè)變量(月份、日期和年)的函數(shù)。函數(shù)返回輸入日期后面的那個(gè)日期。變量月份、日期和年都是整數(shù)值,并滿足以下條件: c1: 1=月份 =12 c2: 1=日期 =31 c3: 1812=年 =2023 ? 我們的處理要包括對(duì)月份、日期和年的無效輸入值的響應(yīng)處理,還要對(duì)無效邏輯處理,例如任意年的 4月 31日。 IT Education Training NextDate 的偽代碼實(shí)現(xiàn) Program NextDate1 ‘ Simple version Dim tomorrowDay,tomorrowMonth,tomorrowYear As Integer Dim day,month,year As Integer Output(? Enter today’ s date in the form MM DD YYYY? ) Input(month,day,year) Case month Of Case 1:month Is1,3,5,7,8,or 10:’ 31 day months (excpet 12) If day31 then tomorrowDay=day+1 else tomorrowDay=1 tomorrowMonth=month+1 EndIf Case 2:month Is 4,6,9 or 11