zoukankan      html  css  js  c++  java
  • 第六章 lesson6-4作业

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    
    namespace Lesson6_4
    {
        /// <summary>
        ///减法类
        /// </summary>
        public class OperationJian:Operation
        {
            public override double GetResult()
            {
                double result = NumberA - NumberB;
                return result;
            }
        }
    }
    减法类
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    
    namespace Lesson6_4
    {
        /// <summary>
        /// 加法类
        /// </summary>
        public class OperationAdd:Operation
        {
            public override double GetResult()
            {
                double result = NumberA + NumberB;
                return result;
            }
        }
    }
    加法类
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    
    namespace Lesson6_4
    {
        /// <summary>
        /// 除法类
        /// </summary>
        public class OperationDiv:Operation
        {
            public override double GetResult()
            {
                if (NumberB == 0)
                {
                    throw new Exception("除数不能为0!");
                }
                double result = NumberA / NumberB;
                return result;
            }
        }
    }
    除法类
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    
    namespace Lesson6_4
    {
        /// <summary>
        /// 乘法类
        /// </summary>
         public class OperationChen:Operation
        {
             public override double GetResult()
             {
                 double result = NumberA * NumberB;
                 return result;
             }
        }
    }
    乘法类
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    
    namespace Lesson6_4
    {
        public class Operation
        {
            public double NumberA { get; set; }
            public double NumberB { get; set; }
            public virtual double GetResult()
            {
                double result = 0;
                return result;
            }
        }
    }
    父类
    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    using System.Windows.Forms;
    
    namespace Lesson6_4
    {
        public partial class Form1 : Form
        {
            public Form1()
            {
                InitializeComponent();
                this.cmbfu.SelectedIndex = 0;//初始的运算符
            }
            /// <summary>
            /// 计算数值并判断
            /// </summary>
            /// <param name="sender"></param>
            /// <param name="e"></param>
            private void btnCalc_Click(object sender, EventArgs e)
            {
                if (string.IsNullOrEmpty(this.txtnum1.Text.Trim()))
                {
                    MessageBox.Show("操作数不能为空!");
                    this.txtnum1.Focus();
                    return;
                }
                else if (string.IsNullOrEmpty(this.txtnum2.Text.Trim()))
                {
                    MessageBox.Show("操作数不能为空!");
                    this.txtnum2.Focus();
                    return;
                }
                else
                {
                    //计算数据
                    try
                    {
                        Operation opr = new Operation();
                        switch (this.cmbfu.SelectedItem.ToString().Trim())
                        {
                            case "+":
                                opr = new OperationAdd();
                                break;
                            case "-":
                                opr = new OperationJian();
                                break;
                            case "*":
                                opr = new OperationChen();
                                break;
                            case "/":
                                opr = new OperationDiv();
                                break;
                        }
                        opr.NumberA = double.Parse(this.txtnum1.Text.Trim());
                        opr.NumberB = double.Parse(this.txtnum2.Text.Trim());
                        this.lblCalc.Text = opr.GetResult().ToString();
                        this.lblJieguo.Visible = true;
                        this.lblCalc.Visible = true;
                    }
                    catch (Exception ex)
                    {
    
                        MessageBox.Show("发生错误!" + ex.Message);
                    }
                }
            }
        }
    }
    frmMain
  • 相关阅读:
    Redhat各个版本和内核对照
    Java8 lambda表达式总结
    conda 安装指定版本的指定包
    git初始化的几句shell
    MYsqli 绑定插入与查询实例
    按天去除重复数据,为0则取0,否则取最大的那个值
    存储过程,循环插入1000条记录
    主表如何统计在附表中的出现次数?
    Invalid argument supplied for foreach()
    二十、mysql mysqldump备份工具
  • 原文地址:https://www.cnblogs.com/zhangxiaoyu123/p/6691715.html
Copyright © 2011-2022 走看看