码迷,mamicode.com
首页 > Windows程序 > 详细

(深入.Net平台和C#编程)第六章.上机练习4.20170410

时间:2017-04-11 01:30:18      阅读:349      评论:0      收藏:0      [点我收藏+]

标签:.com   lap   initial   form   equal   c#   .net   load   threading   

---------------------------------------------------父类---------------------------------------------------

技术分享
 1 using System;
 2 using System.Collections.Generic;
 3 using System.Linq;
 4 using System.Text;
 5 using System.Threading.Tasks;
 6 
 7 namespace Calc.entity
 8 {
 9     public class Op
10     {
11         public double No1 { get; set; }
12         public double No2 { get; set; }
13         public virtual double GetResult()
14         {
15             double result = 0;
16             return result;
17         }
18     }
19 }
Op

---------------------------------------------------子类(加)---------------------------------------------------

技术分享
 1 using System;
 2 using System.Collections.Generic;
 3 using System.Linq;
 4 using System.Text;
 5 using System.Threading.Tasks;
 6 
 7 namespace Calc.entity
 8 {
 9     public class Jia :Op
10     {
11 
12         public override double GetResult()
13         {
14             double result = base.No1 + base.No2;
15             return result;
16         }
17     }
18 }
Jia

---------------------------------------------------子类(减)---------------------------------------------------

技术分享
 1 using System;
 2 using System.Collections.Generic;
 3 using System.Linq;
 4 using System.Text;
 5 using System.Threading.Tasks;
 6 
 7 namespace Calc.entity
 8 {
 9     public class Jian:Op
10     {
11         public override double GetResult()
12         {
13             double result = base.No1 - base.No2;
14             return result;
15         }
16     }
17 }
Jian

---------------------------------------------------子类(乘)---------------------------------------------------

技术分享
 1 using System;
 2 using System.Collections.Generic;
 3 using System.Linq;
 4 using System.Text;
 5 using System.Threading.Tasks;
 6 
 7 namespace Calc.entity
 8 {
 9     public class Cheng:Op
10     {
11         public override double GetResult()
12         {
13             double result = base.No1 * base.No2;
14             return result;
15         }
16     }
17 }
Cheng

---------------------------------------------------子类(除)---------------------------------------------------

技术分享
 1 using System;
 2 using System.Collections.Generic;
 3 using System.Linq;
 4 using System.Text;
 5 using System.Threading.Tasks;
 6 
 7 namespace Calc.entity
 8 {
 9     public class Chu : Op
10     {
11         public override double GetResult()
12         {
13             double result = base.No1 / base.No2;
14             return result;
15         }
16     }
17 }
Chu

---------------------------------------------------窗体类---------------------------------------------------

技术分享
 1 using Calc.entity;
 2 using System;
 3 using System.Collections.Generic;
 4 using System.ComponentModel;
 5 using System.Data;
 6 using System.Drawing;
 7 using System.Linq;
 8 using System.Text;
 9 using System.Threading.Tasks;
10 using System.Windows.Forms;
11 
12 namespace Calc
13 {
14     public partial class frmCalc : Form
15     {
16         public frmCalc()
17         {
18             InitializeComponent();
19         }
20 
21         private void btnCalc_Click(object sender, EventArgs e)
22         {
23             Op op = new Op();
24             if (cmbFu.Text.Equals("+"))
25             {
26                 op = new Jia();
27             }
28             if (cmbFu.Text.Equals("-"))
29             {
30                 op = new Jian();
31             }
32             if (cmbFu.Text.Equals("*"))
33             {
34                 op = new Cheng();
35             }
36             if (cmbFu.Text.Equals("/"))
37             {
38                 op = new Chu();
39             }
40             if (string.IsNullOrEmpty(txtNo1.Text.Trim()) || string.IsNullOrEmpty(txtNo2.Text.Trim()))
41             {
42                 MessageBox.Show("不能为空!!!");
43                 return;
44             }
45             op.No1 = double.Parse(txtNo1.Text);
46             op.No2 = double.Parse(txtNo2.Text);
47             lblResult.Text = op.GetResult().ToString();
48         }
49 
50         private void frmCalc_Load(object sender, EventArgs e)
51         {
52             cmbFu.Items.Add("+");
53             cmbFu.Items.Add("-");
54             cmbFu.Items.Add("*");
55             cmbFu.Items.Add("/");
56         }
57     }
58 }
frmCalc.cs

(深入.Net平台和C#编程)第六章.上机练习4.20170410

标签:.com   lap   initial   form   equal   c#   .net   load   threading   

原文地址:http://www.cnblogs.com/1-2-3-4/p/6691437.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!