第六章,上机练习4(计算机)

 1 using System;
 2 using System.Collections.Generic;
 3 using System.ComponentModel;
 4 using System.Data;
 5 using System.Drawing;
 6 using System.Linq;
 7 using System.Text;
 8 using System.Threading.Tasks;
 9 using System.Windows.Forms;
10
11 namespace SJ
12 {
13     public partial class Form1 : Form
14     {
15         public Form1()
16         {
17             InitializeComponent();
18         }
19
20         /// <summary>
21         /// 加载事件
22         /// </summary>
23         /// <param name="sender"></param>
24         /// <param name="e"></param>
25         private void Form1_Load(object sender, EventArgs e)
26         {
27             cmbAdd();
28         }
29         /// <summary>
30         /// 添加运算符
31         /// </summary>
32         public void cmbAdd()
33         {
34             comboBox1.Items.Add("+");
35             comboBox1.Items.Add("-");
36             comboBox1.Items.Add("*");
37             comboBox1.Items.Add("/");
38         }
39
40         /// <summary>
41         /// 点击事件
42         /// </summary>
43         /// <param name="sender"></param>
44         /// <param name="e"></param>
45         private void btn_Click(object sender, EventArgs e)
46         {
47             if (string.IsNullOrEmpty(textBox1.Text.Trim()) && string.IsNullOrEmpty(textBox2.Text.Trim()))
48             {
49                 MessageBox.Show("不能为空");
50             }
51             Operation op = new Operation();
52             switch (comboBox1.Text.Trim())
53             {
54                 case "+":
55                     op = new jia();
56                     break;
57                 case "-":
58                     op = new Jiang();
59                     break;
60                 case "/":
61                     op = new cu();
62                     break;
63                 case"*":
64                     op = new che();
65                     break;
66             }
67             op.NumberA =double.Parse(textBox1.Text.Trim());
68             op.NumberB= double.Parse(textBox2.Text.Trim());
69             this.label2.Text = op.GetResult().ToString();
70         }
71     }
72 }
 1 using System;
 2 using System.Collections.Generic;
 3 using System.Linq;
 4 using System.Text;
 5 using System.Threading.Tasks;
 6
 7 namespace SJ
 8 {
 9     /// <summary>
10     /// 父类
11     /// </summary>
12     public class Operation
13     {
14         //数字1
15         public double NumberA { get; set; }
16         //数字2
17         public double NumberB { get; set; }
18         //计算方法
19         public virtual  double GetResult()
20         {
21             double result = 0;
22             return result;
23         }
24
25
26     }
27 }
 1 using System;
 2 using System.Collections.Generic;
 3 using System.Linq;
 4 using System.Text;
 5 using System.Threading.Tasks;
 6
 7 namespace SJ
 8 {
 9     /// <summary>
10     /// 乘法
11     /// </summary>
12     public class che:Operation
13     {
14         //计算方法
15         public override double GetResult()
16         {
17             if (NumberA == 0)
18             {
19                 throw new Exception("不能为0");
20             }
21             double result = NumberA - NumberB;
22             return result;
23         }
24     }
25 }
 1 using System;
 2 using System.Collections.Generic;
 3 using System.Linq;
 4 using System.Text;
 5 using System.Threading.Tasks;
 6
 7 namespace SJ
 8 {
 9     /// <summary>
10     /// 除法方法
11     /// </summary>
12     public class cu : Operation
13     {
14        //计算方法
15         public override double GetResult()
16         {
17             if (NumberB == 0)
18             {
19                 throw new Exception("除法不能为0");
20             }
21             double result = NumberA - NumberB;
22             return result;
23         }
24     }
25 }
 1 using System;
 2 using System.Collections.Generic;
 3 using System.Linq;
 4 using System.Text;
 5 using System.Threading.Tasks;
 6
 7 namespace SJ
 8 {
 9     /// <summary>
10     /// 加法类
11     /// </summary>
12     public  class jia:Operation
13     {
14         //计算方法
15         public override double GetResult()
16         {
17             double result = NumberA + NumberB;
18                 return result;
19         }
20
21     }
22 }
 1 using System;
 2 using System.Collections.Generic;
 3 using System.Linq;
 4 using System.Text;
 5 using System.Threading.Tasks;
 6
 7 namespace SJ
 8 {
 9     /// <summary>
10     /// 减法
11     /// </summary>
12     public class Jiang:Operation
13     {
14         //计算方法
15         public override double GetResult()
16         {
17             double result = NumberA - NumberB;
18             return result;
19         }
20     }
21 }
时间: 2024-08-10 19:17:50

第六章,上机练习4(计算机)的相关文章

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

----------父类---------- 1 using Lesson6.上机练习2.enums; 2 using System; 3 using System.Collections.Generic; 4 using System.Linq; 5 using System.Text; 6 using System.Threading.Tasks; 7 8 namespace Lesson6.上机练习2 9 { 10 /// <summary> 11 /// 父类 12 /// </

第六章.上机练习4

1 using System; 2 using System.Collections.Generic; 3 using System.ComponentModel; 4 using System.Data; 5 using System.Drawing; 6 using System.Linq; 7 using System.Text; 8 using System.Threading.Tasks; 9 using System.Windows.Forms; 10 11 namespace le

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

---------------------------------------------------父类--------------------------------------------------- 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.

(深入.Net平台和C#编程)第六章上机练习4.李向阳.20170411

1 ==============加法类================ 2 using System; 3 using System.Collections.Generic; 4 using System.Linq; 5 using System.Text; 6 using System.Threading.Tasks; 7 8 namespace Sj4.Entity 9 { 10 /// <summary> 11 /// 加法 12 /// </summary> 13 publ

(深入.Net平台和C#编程)第六章上机练习1.李向阳.20170411

1 =============Truck类========== 2 using System; 3 using System.Collections.Generic; 4 using System.Linq; 5 using System.Text; 6 using System.Threading.Tasks; 7 8 namespace SJ1.entity 9 { 10 /// <summary> 11 /// 卡车类 12 /// </summary> 13 public

(深入.Net平台和C#编程)第六章上机练习3.李向阳.20170411

1 =======父类========== 2 using System; 3 using System.Collections.Generic; 4 using System.Linq; 5 using System.Text; 6 using System.Threading.Tasks; 7 8 namespace Sj3.Entity 9 { 10 /// <summary> 11 /// 父类 12 /// </summary> 13 public class Emplo

第六章 上机2

using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace CarRun { public class Vehicle { //带参构造函数 public Vehicle(string place, string type) { this.Place = place; this.Type = type; }

2014年计算机软考《网络管理》知识点-【第六章】

51CTO学院,在软考备考季特别整理了"2014年计算机软考<网络管理>知识点",帮助各位学院顺利过关!更多软件水平考试辅导及试题,请关注51CTO学院-软考分类吧! 查看汇总:2014年计算机软考<网络管理>知识点汇总  第六章 服务器与工作站 基本概念 在局域网的实际应用中,最重要的仍然是资源共享,包括高速的或贵重的外围设备的共享.信息共享. 访问文件系统和数据库.网络服务器和网络工作站是局域网实现资源共享的重要组成部分. 6.1 网络服务器 (1) 服务器

CSS3秘笈:第六章

第六章  文本格式化 1.font-family 属性设置字体.除了指定想要的字体之外还要使用备用字体.例如: p{ font-family:Arial ,Helvetica ,sans-serif; } 如果字体的名称中包含多个单词,则必须用双引号(””)将它们括起来. 2.·serif字体,适合冗长的文字信息. ·sans-serif字体看起来干净而整洁因此经常被放在标题上. ·monospaced字体经常用于显示计算机代码.字体中的每个字母都是等宽的. ·其他常用字体:Arial Blac

C++ Primer Plus学习:第六章

C++入门第六章:分支语句和逻辑运算符 if语句 语法: if (test-condition) statement if else语句 if (test-condition) statement1 else statement2 if else if else语句 if (test-condition1) statement1 else if (test-condition2) statement2 else statement3 2 逻辑表达式 逻辑OR运算符:|| 当两个条件中有一个或全部