zoukankan      html  css  js  c++  java
  • 用C#设计一个 Windows应用程序,在该程序定义平面图形抽象类和其派生类圆、矩形和三角形。该程序实现的功能包括:输入相应图形的参数,如矩形的长和宽,单击相应的按钮,枓据输入參数创建图形类并输出该图形的面积。程序运行结果如图所示

    1.题目要求如下:

     用C#设计一个 Windows应用程序,在该程序定义平面图形抽象类和其派生类圆、矩形和三角形。该程序实现的功能包括:输入相应图形的参数,如矩形的长和宽,单击相应的按钮,枓据输入參数创建图形类并输出该图形的面积。程序运行结果如图所示
     
    2.来吧展示,代码如下:
    using System;
    using System.Windows.Forms;
    
    namespace Different_Graphic_Areas_4._2
    {
        public partial class Form1 : Form
        {
            public Form1()
            {
                InitializeComponent();
            }
            private void button1_Click(object sender, EventArgs e)
            {
                Circle c = new Circle(Convert.ToDouble(textBox1.Text));
                richTextBox1.Text = "圆的面积为:" + c.Area();
            }
            private void button2_Click(object sender, EventArgs e)
            {
                Trangle t = new Trangle(Convert.ToDouble(textBox1.Text), Convert.ToDouble(textBox2.Text));
                richTextBox1.Text = "矩形的面积为:" + t.Area();
            }
    
            private void button3_Click(object sender, EventArgs e)
            {
                S s = new S(Convert.ToDouble(textBox1.Text), Convert.ToDouble(textBox2.Text));
                richTextBox1.Text = "三角形的面积为:" + s.Area();
            }
            public abstract class Figure
            {
                public abstract double Area();
            }
            public class Circle:Figure
            {
                double r;
                public Circle(double r)
                {
                    this.r = r;
                }
                public override double Area()
                {
                    return r * r * 3.14;
                }
            }
            public class Trangle:Figure
            {
                double h;
                double w;
                public Trangle(double h,double w)
                {
                    this.h = h;
                    this.w = w;
                }
                public override double Area()
                {
                    return h*w;
                }
            }
            public class S:Figure
            {
                double h;
                double w;
                public S(double h,double w)
                {
                    this.h = h;
                    this.w = w;
                }
                public override double Area()
                {
                    return w * h/2;
                }
            }
            private void Form1_Load(object sender, EventArgs e)
            {
    
            }
        }
    }

    3.运行结果如下:

    我是小关,关注我,带你从初级入门编程
    希望能帮到大家,问你们要一个赞,你们会给吗,谢谢大家
    版权声明:本文版权归作者(@攻城狮小关)和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。
    大家写文都不容易,请尊重劳动成果~
    交流加Q:1909561302
    CSDN地址https://blog.csdn.net/Mumaren6/

  • 相关阅读:
    ionic3开发环境搭建与配置(win10系统)
    angular4打包以后,刷新报404
    css3文字渐变无效果的解决方案
    node-sass安装失败的解决方案
    python logging 重复写日志问题
    进程和线程的概念
    软件开发目录规范
    相对导入
    python引入导入自定义模块和外部文件
    异常处理
  • 原文地址:https://www.cnblogs.com/guanguan-com/p/14241734.html
Copyright © 2011-2022 走看看