• 沒有找到結果。

電腦軟體設計丙級術科講義(小阿中)

N/A
N/A
Protected

Academic year: 2021

Share "電腦軟體設計丙級術科講義(小阿中)"

Copied!
6
0
0

加載中.... (立即查看全文)

全文

(1)

Private Sub ex1()

Dim a As String '必須設為字串

Open "a:\940301.sm" For Input As #1 Input #1, a Close #1 aa = a b = "" For i = 1 To 100 '因為不知題目長度,所以假設 100 b = b & a Mod 10 '字串反轉 a = a \ 10 '去掉個位數

If a = 0 Then Exit For Next i

If aa = b Then

Printer.Print "第一題結果: " & aa & " is a palindrome" Else

Printer.Print "第一題結果: " & aa & " is not a palindrome" End If

End Sub

Open "a:\940302.sm" For Input As #1 Input #1, a Close #1 Printer.Print "第二題結果: " For i = 1 To a For j = 1 To i Printer.Print j; Next j Printer.Print Next i End Sub

Private Sub ex1()

Dim a As String '必須設為字串

Open "a:\940301.sm" For Input As #1 Input #1, a Close #1 aa = a b = "" Do While a <> 0 b = b & a Mod 10 '字串反轉 a = a \ 10 '去掉個位數 Loop If aa = b Then

Printer.Print "第一題結果: " & aa & " is a palindrome" Else

Printer.Print "第一題結果: " & aa & " is not a palindrome" End If

End Sub

Private Sub ex2()

Open "a:\940302.sm" For Input As #1 Input #1, a Close #1 Printer.Print "第二題結果: " i = 1 '第一個迴圈的初值 Do While i <= a j = 1 '第二個迴圈的初值 Do While j <= i Printer.Print j; j = j + 1 Loop Printer.Print i = i + 1 Loop End Sub

Private Sub ex1()

Dim a As String '必須設為字串

Open "a:\940301.sm" For Input As #1 Input #1, a Close #1 aa = a b = "" Do b = b & a Mod 10 '字串反轉 a = a \ 10 '去掉個位數 Loop While a <> 0 If aa = b Then

Printer.Print "第一題結果: " & aa & " is a palindrome" Else

Printer.Print "第一題結果: " & aa & " is not a palindrome" End If

End Sub

Private Sub ex2()

Open "a:\940302.sm" For Input As #1 Input #1, a Close #1 Printer.Print "第二題結果: " i = 1 '第一個迴圈的初值 Do j = 1 '第二個迴圈的初值 Do Printer.Print j; j = j + 1 Loop While j <= i Printer.Print i = i + 1 Loop While i <= a End Sub

(2)

Private Sub ex3()

Open "a:\940303.sm" For Input As #1 Input #1, a

Close #1 test = 1

For i = 2 To a – 1 ‘因為質數是不能被 1 與自己本身整除的數

test = test * (a Mod i) if test > 1 then test = 1 Next i

If test = 0 Then

Printer.Print "第三題結果:" & a & " is not a prime number." Else

Printer.Print "第三題結果:" & a & " is a prime number." End If

End Sub

Private Sub ex4()

Dim a(99), B As Integer 'B 要設為整數,否則 BMI 會有小數

Open "a:\940304.sm" For Input As #1 For i = 1 To 6 Input #1, a(i) Next i Close #1 bmi = 99 '假設 BMI 最大為 99 For i = 1 To 6 Step 2 B = a(i + 1) / (a(i) / 100) ^ 2 + 0.5 '第一位要四捨五入

If B < bmi Then bmi = B '取最小值

Next i

If bmi < 20 Or bmi > 25 Then

Printer.Print "第四題結果: 最小 BMI 值=" & bmi & ",不正常" Else

Printer.Print "第四題結果: 最小 BMI 值=" & bmi & ",正常" End If

Private Sub ex3()

Open "a:\940303.sm" For Input As #1 Input #1, a

Close #1 test = 1

i = 2 '設定初值

Do While i <= a - 1 '設定結束值

test = test * (a Mod i if test > 1 then test = 1 i = i + 1 '設定遞增值

Loop

If test = 0 Then

Printer.Print "第三題結果:" & a & " is not a prime number." Else

Printer.Print "第三題結果:" & a & " is a prime number." End If

End Sub

Private Sub ex4()

Dim a(99), B As Integer 'B 要設為整數,否則 BMI 會有小數

Open "a\940304.sm" For Input As #1 i = 1 Do While i <= 6 Input #1, a(i) i = i + 1 Loop Close #1 bmi = 99 '假設 BMI 最大為 99 i = 1 Do While i <= 6 B = a(i + 1) / (a(i) / 100) ^ 2 + 0.5 '第一位要四捨五入

If B < bmi Then bmi = B '取最小值

i = i + 2 '設定遞增值

Loop

If bmi < 20 Or bmi > 25 Then

Print "第四題結果: 最小 BMI 值=" & bmi & ",不正常" Else

Print "第四題結果: 最小 BMI 值=" & bmi & ",正常" End If

End Sub

Private Sub ex3()

Open "a:\940303.sm" For Input As #1 Input #1, a

Close #1 test = 1

i = 2 '設定初值

Do

test = test * (a Mod i) if test > 1 then test = 1 i = i + 1 '設定遞增值

Loop While i <= a - 1 '設定結束值

If test = 0 Then

Printer.Print "第三題結果:" & a & " is not a prime number." Else

Printer.Print "第三題結果:" & a & " is a prime number." End If

End Sub

Private Sub ex4()

Dim a(99), B As Integer 'B 要設為整數,否則 BMI 會有小數

Open "a\940304.sm" For Input As #1 i = 1 Do Input #1, a(i) i = i + 1 Loop While i <= 6 Close #1 bmi = 99 '假設 BMI 最大為 99 i = 1 Do B = a(i + 1) / (a(i) / 100) ^ 2 + 0.5 '第一位要四捨五入

If B < bmi Then bmi = B '取最小值

i = i + 2 '設定遞增值

Loop While i <= 6

If bmi < 20 Or bmi > 25 Then

Print "第四題結果: 最小 BMI 值=" & bmi & ",不正常" Else

Print "第四題結果: 最小 BMI 值=" & bmi & ",正常" End If

(3)

Private Sub ex5()

Dim M1(2, 2), M2(2, 2) As Integer Open "a:\940305.sm" For Input As #1

Input #1, M1(1, 1), M1(1, 2), M1(2, 1), M1(2, 2) Input #1, M2(1, 1), M2(1, 2), M2(2, 1), M2(2, 2) Close #1 Printer.Print "第五題結果:" For i = 1 To 2 Printer.Print "["; For j = 1 To 2 If j = 2 Then

Printer.Print M1(i, j) + M2(i, j) & "]" Else

Printer.Print M1(i, j) + M2(i, j), End If

Next j Next i End Sub

Private Sub ex5()

Dim M1(2, 2), M2(2, 2) As Integer Open "a:\940305.sm" For Input As #1

Input #1, M1(1, 1), M1(1, 2), M1(2, 1), M1(2, 2) Input #1, M2(1, 1), M2(1, 2), M2(2, 1), M2(2, 2) Close #1 Printer.Print "第五題結果:" i = 1 '設定初值 Do While i <= 2 '設定結束值 Printer.Print "["; j = 1 '設定初值 Do While j <= 2 '設定結束值 If j = 2 Then

Printer.Print M1(i, j) + M2(i, j) & "]" Else

Printer.Print M1(i, j) + M2(i, j), End If j = j + 1 '設定遞增值 Loop i = i + 1 '設定遞增值 Loop End Sub

Private Sub ex5()

Dim M1(2, 2), M2(2, 2) As Integer Open "a:\940305.sm" For Input As #1

Input #1, M1(1, 1), M1(1, 2), M1(2, 1), M1(2, 2) Input #1, M2(1, 1), M2(1, 2), M2(2, 1), M2(2, 2) Close #1 Printer.Print "第五題結果:" i = 1 '設定初值 Do Printer.Print "["; j = 1 '設定初值 Do If j = 2 Then

Printer.Print M1(i, j) + M2(i, j) & "]" Else

Printer.Print M1(i, j) + M2(i, j), End If j = j + 1 '設定遞增值 Loop While j <= 2 '設定結束值 i = i + 1 '設定遞增值 Loop While i <= 2 '設定結束值 End Sub

 執行結果列印如下:

PS:實際評分是要將結果列印出來,而且連程式碼也要

小阿中提醒各位:

 基本題五題抽 3 題,三種迴圈種類再抽一種作答  平時練習沒有軟碟機,則 Shell("a:\title.exe", 1)不可執行  平時練習沒有軟碟機,所以 a:\ 軟碟機改為『a\』資料夾取代  平時練習沒有印表機,則將 Printer.Print 全部取代為『Print』  確認答案沒問題,再全部取代為『Printer.Print』,以便列印出來  每題片頭皆須底下程式,務必熟記

Private Sub Command1_Click() ‘或用 Form_Click()亦可

Open "a:\title.txt" For Input As #1 Input #1, a, B, c, d Close #1 Print "姓 名:" & a, Print "准考證號碼:" & c '2,3 欄位相反 Print "座 號:" & B, Print "日 期:" & d ex1 ex2 ex3 ex4 ex5 End Sub

Private Sub Form_Load()

a = Shell("a:\title.exe", 1) '若無軟碟機,該程式無法執行

(4)

 第二站_高速公路車輛統計

Dim sum, sumb, sumc, sumd, sume As Long Dim W1, W2, W3, W4, W5, W6, W7 As Long Private Sub Command1_Click()

Frame2.Caption = Command1.Caption For I = 0 To 13 '將所有物件顯示 Label5(I).Visible = True Next I For I = 0 To 6 Shape1(I).Visible = True Next I Label5(0).Caption = "星期一" Label5(1).Caption = "星期二" Label5(2).Caption = "星期三" Label5(3).Caption = "星期四" Label5(4).Caption = "星期五" Label5(5).Caption = "星期六" Label5(6).Caption = "星期日"

Shape1(0).Width = Int(W1 / sum * 3000) Shape1(1).Width = Int(W2 / sum * 3000) Shape1(2).Width = Int(W3 / sum * 3000) Shape1(3).Width = Int(W4 / sum * 3000) Shape1(4).Width = Int(W5 / sum * 3000) Shape1(5).Width = Int(W6 / sum * 3000) Shape1(6).Width = Int(W7 / sum * 3000)

Label5(7).Left = Shape1(0).Left + Shape1(0).Width + 200 Label5(7).Caption = Format(W1, "###,###,###")

Label5(8).Left = Shape1(1).Left + Shape1(1).Width + 200 Label5(8).Caption = Format(W2, "###,###,###")

Label5(9).Left = Shape1(2).Left + Shape1(2).Width + 200 Label5(9).Caption = Format(W3, "###,###,###")

Label5(10).Left = Shape1(3).Left + Shape1(3).Width + 200 Label5(10).Caption = Format(W4, "###,###,###")

Label5(11).Left = Shape1(4).Left + Shape1(4).Width + 200 Label5(11).Caption = Format(W5, "###,###,###")

Label5(12).Left = Shape1(5).Left + Shape1(5).Width + 200 Label5(12).Caption = Format(W6, "###,###,###")

Label5(13).Left = Shape1(6).Left + Shape1(6).Width + 200 Label5(13).Caption = Format(W7, "###,###,###")

End Sub

Private Sub Command2_Click() Frame2.Caption = Command2.Caption Label5(0).Visible = False '將沒用物件隱藏 Label5(1).Visible = False Label5(6).Visible = False Label5(7).Visible = False Label5(8).Visible = False Label5(13).Visible = False Shape1(0).Visible = False Shape1(1).Visible = False Shape1(6).Visible = False addr = 2 '顯示起始位置 For I = 1 To 9999999 '假設最大能統計的數字

If sumb = I Then Label5(addr).Caption = "大型車":

Shape1(addr).Width = Int(3000 * sumb / sum): Label5(addr + 7).Left = Shape1(addr).Left + Shape1(addr).Width + 200: Label5(addr + 7).Caption = Format(sumb, "###,###,###"): addr = addr + 1 If sumc = I Then Label5(addr).Caption = "中型車":

Shape1(addr).Width = Int(3000 * sumc / sum): Label5(addr + 7).Left = Shape1(addr).Left + Shape1(addr).Width + 200: Label5(addr + 7).Caption = Format(sumc, "###,###,###"): addr = addr + 1 If sumd = I Then Label5(addr).Caption = "小型車":

Shape1(addr).Width = Int(3000 * sumd / sum): Label5(addr + 7).Left = Shape1(addr).Left + Shape1(addr).Width + 200: Label5(addr + 7).Caption = Format(sumd, "###,###,###"): addr = addr + 1 If sume = I Then Label5(addr).Caption = "公務車": Shape1(addr).Width = Int(3000 * sume / sum): Label5(addr + 7).Left = Shape1(addr).Left + Shape1(addr).Width + 200:

Label5(addr + 7).Caption = Format(sume, "###,###,###"): addr = addr + 1

Next I End Sub

Private Sub Form_Load() Dim a(100) As String

Dim b(100), c(100), d(100), e(100) As Long sumb = 0: sumc = 0: sumd = 0: sume = 0

W1 = 0: W2 = 0: W3 = 0: W4 = 0: W5 = 0: W6 = 0: W7 = 0

aa = Val(InputBox("請選擇 ? (1-3): " & vbCr & "1.範例檔 2.測試 檔 3.結束"))

If aa = 3 Then End If aa = 1 Then

Open "a\940307.sm" For Input As #1 Else

Open "a\940307.t01" For Input As #1 End If For I = 1 To 1000 Input #1, a(I) Input #1, b(I) Input #1, c(I) Input #1, d(I) Input #1, e(I)

sumb = sumb + b(I) sumc = sumc + c(I) sumd = sumd + d(I) sume = sume + e(I)

If a(I) = "MONDAY" Then W1 = W1 + b(I) + c(I) + d(I) + e(I) If a(I) = "TUESDAY" Then W2 = W2 + b(I) + c(I) + d(I) + e(I) If a(I) = "WEDNESDAY" Then W3 = W3 + b(I) + c(I) + d(I) + e(I) If a(I) = "THURSDAY" Then W4 = W4 + b(I) + c(I) + d(I) + e(I) If a(I) = "FRIDAY" Then W5 = W5 + b(I) + c(I) + d(I) + e(I) If a(I) = "SATURDAY" Then W6 = W6 + b(I) + c(I) + d(I) + e(I) If a(I) = "SUNDAY" Then W7 = W7 + b(I) + c(I) + d(I) + e(I) If EOF(1) Then Exit For

Next I

sum = sumb + sumc + sumd + sume Close #1

Call Command1_Click '一開始就先執行依星期統計 End Sub

(5)

第二站_身份證號碼檢查

Private Sub Form_Load()

Dim a(100), b(100), c(100), err(100), d(10) As String Dim t(35) As String t(10) = "A" t(11) = "B" t(12) = "C" t(13) = "D" t(14) = "E" t(15) = "F" t(16) = "G" t(17) = "H" t(18) = "J" t(19) = "K" t(20) = "L" t(21) = "M" t(22) = "N" t(23) = "P" t(24) = "Q" t(25) = "R" t(26) = "S" t(27) = "T" t(28) = "U" t(29) = "V" t(30) = "X" t(31) = "Y" t(32) = "W" t(33) = "Z" t(34) = "I" t(35) = "O"

aa = Val(InputBox("請選擇 ? (1-3): " & vbCr & "1.範例檔 2.測試 檔 3.結束"))

If aa = 3 Then End If aa = 1 Then

Open "a:\940306.sm1" For Input As #1 Else

Open "a:\940306.t01" For Input As #1 End If

For i = 1 To 1000

Input #1, a(i), b(i), c(i) ferr = 1 '測試格式是否有錯 For j = 10 To 35 If Left(a(i), 1) = t(j) Then X1 = Val(Left(Format(Str(j), "##"), 1)) ' 十位數, 未用 Format 則為 0 X2 = Val(Right(Str(j), 1)) ' 個位數 ferr = 0 Exit For End If Next j For j = 1 To 9 d(j) = Mid(a(i), j + 1, 1)

If d(j) < "0" Or d(j) > "9" Then ferr = 1: Exit For Next j

If Len(a(i)) <> 10 Then ferr = 1 '因身份證有 11 碼的可能錯誤

SERR = 1 '測試性別是否有錯

If d(1) = "1" And c(i) = "M" Then SERR = 0 If d(1) = "2" And c(i) = "F" Then SERR = 0 If ferr <> 1 Then '若格式有錯,則不用做 step3

Y = X1 + 9 * X2 + 8 * Val(d(1)) + 7 * Val(d(2)) + 6 * Val(d(3)) + 5 * Val(d(4)) + 4 * Val(d(5)) + 3 * Val(d(6)) + 2 * Val(d(7)) + Val(d(8)) + Val(d(9))

End If

If ferr = 1 Then err(i) = "FORMAT ERROR": GoTo AAA If SERR = 1 Then err(i) = "SEX CODE ERROR": GoTo AAA If Y Mod 10 = 0 Then err(i) = "" Else err(i) = "CHECK SUM ERROR" AAA:If EOF(1) Then Exit For

Next i Close #1 '變數 i 即為資料數量 With MSFlexGrid1 .Rows = i + 1 '第一列為標題 .ColWidth(0) = 500 '設定欄寬 .ColWidth(1) = 2000 .ColWidth(2) = 1000 .ColWidth(3) = 500 .ColWidth(4) = 4000 .Row = 0 .Col = 1

.Text = "ID NO" .Col = 2 .Text = "NAME" .Col = 3 .Text = "SEX" .Col = 4 .Text = "ERROR" End With For j = 1 To i With MSFlexGrid1 .Row = j .Col = 1 .Text = a(j) .Col = 2 .Text = b(j) .Col = 3 .Text = c(j) .Col = 4 .Text = err(j) End With Next j MSFlexGrid1.Col = 1 ' 按欄位 1(身分證號碼)排序 MSFlexGrid1.Sort = 5 End Sub

 範例檔測試資料執行畫面如下:

 測試檔執行畫面如下:

(6)

 第二站_分數的加、減、乘、除運算

Private Sub Form_Load()

On Error Resume Next

Dim a(100), b(100), x(100), y(100), op(100), ans(100) As String aa = Val(InputBox("請選擇 ? (1-3): " & vbCr & "1.範例檔 2.測試 檔 3.結束"))

If aa = 3 Then End If aa = 1 Then

Open "a:\940308.sm1" For Input As #1 Else

Open "a:\940308.t01" For Input As #1 End If

For i = 1 To 1000

Input #1, b(i), a(i), op(i), y(i), x(i)

If op(i) = "+" Then X1 = b(i) * x(i) + a(i) * y(i): X2 = a(i) * x(i)

If op(i) = "-" Then X1 = b(i) * x(i) - a(i) * y(i): X2 = a(i) * x(i)

If op(i) = "*" Then X1 = b(i) * y(i): X2 = a(i) * x(i) If op(i) = "/" Then X1 = b(i) * x(i): X2 = a(i) * y(i) If X1 = 0 Then ans(i) = "0": GoTo AAA

If X1 = X2 Then ans(i) = "1": GoTo AAA For j = X1 - 1 To 1 Step -1

If X1 Mod j = 0 And X2 Mod j = 0 Then ans(i) = X1 / j & "/" & X2 / j: Exit For

Next j

AAA: If EOF(1) Then Exit For Next i Close #1 '變數 i 即為資料數量 With MSFlexGrid1 .Rows = i + 1 '第一列為標題 .ColWidth(0) = 500 '設定欄寬 .ColWidth(1) = 2000 .ColWidth(2) = 2000 .ColWidth(3) = 2000 .ColWidth(4) = 2000 .ColAlignment(1) = 4 '設定置中對齊 .ColAlignment(2) = 4 '設定置中對齊 .ColAlignment(3) = 4 '設定置中對齊 .ColAlignment(4) = 4 '設定置中對齊 .Row = 0 .Col = 1 .Text = "value1" .Col = 2 .Text = "OP" .Col = 3 .Text = "value2" .Col = 4 .Text = "answer" End With For j = 1 To i '利用 MSFlexGrid1 顯示全部資料 With MSFlexGrid1 .Row = j .Col = 1

.Text = b(j) & "/" & a(j) .Col = 2

.Text = op(j) .Col = 3

.Text = y(j) & "/" & x(j) .Col = 4 .Text = ans(j) End With Next j End Sub 

開始執行畫面如下:(進階題三題都要)

 範例檔測試資料執行畫面如下:

 測試檔執行畫面如下:

參考文獻

相關文件

[r]

3.丙級:包括應用作業系統、安裝軟體與使用電腦週邊設 備、設定繪圖環境、控制圖形螢幕、輸出圖形與 管理圖面等基本工作及繪製單件立體圖、立體剖

[r]

[r]

【5+2產業】亞洲矽谷 電腦資訊技術類 物聯網自動灌溉與排水系統設計班. 【5+2產業】亞洲矽谷

由於較大型網路的 規劃必須考慮到資料傳 輸效率的問題,所以在 規劃時必須將網路切割 成多個子網路,稱為網 際網路。橋接器是最早

802.14為主流,參與成員多為電腦及電話 公司,協定的主體已經確立,預計在今年 十一月完成標準草案的制定,1998年六月 正式成為IEEE標準。基本上來說,IEEE 802.14受到四個標準單位影響:

參、技術士技能檢定建築物室內設計乙級術 科試題.