下載/瀏覽

Download Report

Transcript 下載/瀏覽

計算機程式及實習
期末報告
題目:販劍~製杖~武器店
結帳系統
南台科技大學
機械工程系 車輛一甲
學號:4A115111
學生:蕭偉呈
老師:謝慶存
學習重點
程式設計:設計程式商店結帳系
統,店名,商品自行設計,商品數
量至少3種,另外再加打折辦法
題目說明:武器
店結帳系統
試設計武器店結帳系統,填
寫數量再按下計算鈕之後,
即會顯示結帳總金額。按
「清除」按鈕,再輸入數量,
並點選「會員*0.9」,再按
下「計算」鈕,得到打9折
後的那一筆總金額資料。
附加練習
為程式加入強化加5000元功能,特別
注意到是每支強化都必須加5000元。另
外,若總金額超過三百萬元之單一筆訂
單則免收強化費用功能。
程式開始畫面
販劍
改劍數量為10按
「結帳」按鈕後,
得到第1筆結帳資料
會員買弓
按「清除」按鈕,清除
剛剛的10把劍後,再輸
入弓的數量為2,並點
選「會員」,再按下
「計算」鈕,得到打9
折後的那一筆64800元資
料。
鑽石會員75折
在杖旁的數量欄中輸入
10並按下「計算」鈕。
因為是鑽石會員,所以
點選畫面中鑽石會員的
選項,若消費超過一千
萬在程式運作下會自動
選取75折的優惠。
如果想刪除消費紀錄,
使用者只需直接以滑鼠
點選這筆資料,這筆資
料就會自動被刪除,同
時,累計值會自動把這
筆資料,從累計金額中
扣除。
版面配置
屬性設定
數量
價格
TBoxPrice1 TBoxQty1
TBoxPrice2 TBoxQty2
TBoxPrice3 TBoxQty3
強化
CheckBox1
CheckBox2
CheckBox3
武器
Label1
Label2
Label3
優待GroupBox1
RadioButton1
RadioButton2
RadioButton3
消費資料
ListBox1
Button1
Button2
金額
Label6
Label7
程式碼設計
 Public Class Form1

Dim total, accTotal As Integer

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs)
Handles MyBase.Load

Label6.Text = "$" & total & "元"

Label7.Text = "累計:$" & accTotal & "元"

Label6.Font = New Font("新細明體", 24)

Label6.ForeColor = Color.Red

total = 0

accTotal = 0

End Sub
 Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click

total = Val(TBoxPrice1.Text) * Val(TBoxQty1.Text) + Val(TBoxPrice2.Text)
* Val(TBoxQty2.Text) + Val(TBoxPrice3.Text) * Val(TBoxQty3.Text)
 If total > 10000000 Then RadioButton3.Checked = True

If RadioButton1.Checked = True Then total = (total1 + total2 + total3) *
0.9

If RadioButton2.Checked = True Then total = (total1 + total2 + total3) *
0.8

0.75
If RadioButton3.Checked = True Then total = (total1 + total2 + total3) *

Label6.Text = "$" & total & "元"

accTotal = accTotal + total

Label7.Text = "累計:$" & accTotal & "元"

ListBox1.Items.Add(total & "-->" & "劍" & TBoxPrice1.Text & "*" & TBoxQty1.Text & "杖"
& TBoxPrice2.Text & "*" & TBoxQty2.Text & "弓" & TBoxPrice3.Text & "*" & TBoxQty3.Text)

End Sub

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
Handles Button2.Click

TBoxQty1.Text = 0

TBoxQty2.Text = 0

TBoxQty3.Text = 0

total = 0

Label6.Text = "$" & total & "元"

End Sub
 Private Sub ListBox1_MouseUp(ByVal sender As Object, ByVal e
As System.Windows.Forms.MouseEventArgs) Handles
ListBox1.MouseUp

accTotal = accTotal - (Val(ListBox1.SelectedItem))

ListBox1.Items.RemoveAt(ListBox1.SelectedIndex)

Label7.Text = "累計:$" & accTotal & "元"

End Sub
 End Class
程式說明
 第2行定義總金額及累計金額的參數。
 第13行求出單筆交易的總金額。
 第15行讓總金額>10000000元時RadioButton3 (即>10000000元*
0.75鈕)自動選取。
 第16-18行處理折扣動作。
 第20行累加至累計金額。
 第22行把單筆交易記錄至ListBox1中
第25-31行為「清除」按鈕的歸零動作。
第33-38行處理利用滑鼠在ListBox1上點選時,
放開滑鼠左鍵的刪除記錄動作。
• 第34行扣除該筆記錄在累加值中的數值。
• 第35行實際於ListBox1中刪除,刪除該筆
記錄。
• 第36行把更正後的累加值,再度顯示出來。
附加練習
 為程式加入強化加5000元功能,特別注意到是每支強化都必須加5000元。另
外,若總金額超過三百萬元之單一筆訂單則免收強化費用功能。
 程式第14行加入
 If total < 3000000 Then

If CheckBox1.Checked Then total1 = (Val(TBoxPrice1.Text) *
Val(TBoxQty1.Text)) + (5000 * Val(TBoxQty1.Text))

If CheckBox2.Checked Then total2 = (Val(TBoxPrice2.Text) *
Val(TBoxQty2.Text)) + (5000 * Val(TBoxQty2.Text))

If CheckBox3.Checked Then total3 = (Val(TBoxPrice3.Text) *
Val(TBoxQty3.Text)) + (5000 * Val(TBoxQty3.Text))
 If Not CheckBox1.Checked Then total1 =
(Val(TBoxPrice1.Text) * Val(TBoxQty1.Text))

If Not CheckBox2.Checked Then total2 =
(Val(TBoxPrice2.Text) * Val(TBoxQty2.Text))

If Not CheckBox3.Checked Then total3 =
(Val(TBoxPrice3.Text) * Val(TBoxQty3.Text))


total = total1 + total2 + total3
End If
心得
 好困難,花了我半天的時間才做完。平時看老師示範感覺很
簡單,換自己做就完全不一樣。哪裡有問題就要自己一一去解
開。去想想解決辦法。不過還是努力的想要去解決這些問題,
然後解決之後就變得很有成就感。
 這次老師叫我們設計程式,雖然有難度,但是還是要實際去
操作才明白其中的奧妙,謝謝老師。
 也謝謝老師你上課幽默詼諧的專業解說 !!超酷的!!!
參考文獻
 Visual Basic2010基礎必修課
 林義証、蔡文龍、張傑瑞、何叡 著
 吳明哲 策劃