三角函数计算器(窗体程序,包含继承的运用)

namespace YL4_3
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            this.Text = "三角函数计算器";
            RadioSin.Checked = true;
            LabelResult.Text = "";
        }

        private void ButtonOK_Click(object sender, EventArgs e)
        {
            if (RadioSin.Checked)
            {
                SinFunc SinVal = new SinFunc();
                SinVal.Angle = double.Parse(TextAngle.Text.Trim());//Angle是从TriFunc类中继承来的属性
                LabelResult.Text = "Sin " + TextAngle.Text + "º = " + SinVal.GetResult().ToString("f4");
            }
            if (RadioCos.Checked)
            {
                CosFunc CosVal = new CosFunc();
                CosVal.Angle = double.Parse(TextAngle.Text.Trim());//Angle是从TriFunc类中继承来的属性
                LabelResult.Text = "Cos " + TextAngle.Text + "º = " + CosVal.GetResult().ToString("f4");
            }
            if (RadioTan.Checked)
            {
                TanFunc TanVal = new TanFunc();
                TanVal.Angle = double.Parse(TextAngle.Text.Trim());//Angle是从TriFunc类中继承来的属性
                LabelResult.Text = "tg " + TextAngle.Text + "º = " + TanVal.GetResult().ToString("f4");
            }
            if (RadioCtg.Checked)
            {
                TanFunc TanVal = new TanFunc();
                TanVal.Angle = double.Parse(TextAngle.Text.Trim());//Angle是从TriFunc类中继承来的属性
                LabelResult.Text = "tg " + TextAngle.Text + "º = " + (1 / TanVal.GetResult()).ToString("f4");
            }
        }
    }
}
namespace Function
{
    public class TriFunc  //声明一个三角函数类
    {
        //定义成员变量
        private double angle;
        //定义角度属性
        public double Angle 
        {
            get { return angle; }
            set { angle = value; }
        }
        //将角度转换为弧度值的方法
        public double TransAngle(double a)
        {
            a = a * Math.PI / 180;
            return a;
        }
    }
    public class SinFunc : TriFunc//继承于TriFunc(三角函数)类的SinFunc(正弦函数)类
    {
        public double GetResult()
        {
            Angle = TransAngle(Angle);
            return Math.Sin(Angle);
        }
    }
    public class CosFunc : TriFunc//继承于TriFunc(三角函数)类的CosFunc(余弦函数)类
    {
        public double GetResult()
        {
            Angle = TransAngle(Angle);
            return Math.Cos(Angle);
        }
    }
    public class TanFunc : TriFunc//继承于TriFunc(三角函数)类的TanFunc(正切函数)类
    {
        public double GetResult()
        {
            Angle = TransAngle(Angle);
            return Math.Tan(Angle);
        }
    }
    public class CtgFunc : TriFunc//继承于TriFunc(三角函数)类的CtgFunc(余切函数)类
    {
        public double GetResult()
        {
            Angle = TransAngle(Angle);
            return 1 / Math.Tan(Angle);
        }
    }
}
  • 0
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值