⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 form1.cs

📁 Visual C#2005程序设计教程
💻 CS
字号:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace WinApp6_7构造函数长方体
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            if (radCuboid.Checked)
            {
                double l = double.Parse(txtL.Text);
                double w = double.Parse(txtW.Text);
                double h = double.Parse(txtH.Text);
                Cuboid cuboid = new Cuboid(l, w, h);
                lblInfo.Text = "对象创建成功!\n" + "长方体的长、宽、高为:"
                    + cuboid.Length + "、" + cuboid.Width + "、" + cuboid.High + "\n"
                    + "长方体的体积为:" + cuboid.CuboidCubage();
            }
            else
            {
                double l = double.Parse(txtL.Text);
                Cube cube = new Cube(l);
                lblInfo.Text = "对象创建成功!\n" + "正方体的棱长为:"
                    + cube.Length + "\n" + "正方体的体积为:" + cube.CubeCubage();
            }
        }

        private void radCube_CheckedChanged(object sender, EventArgs e)
        {
            if (radCube.Checked)
            {
                txtW.Visible = false;
                txtH.Visible = false;
                label2.Visible = false;
                label3.Visible = false;
                label1.Text = "棱长";
            }
        }

        private void radCuboid_CheckedChanged(object sender, EventArgs e)
        {
            if (radCuboid.Checked)
            {
                txtW.Visible = true;
                txtH.Visible = true;
                label2.Visible = true;
                label3.Visible = true;
                label1.Text = "长";
            }
        }
    }

    public class Cuboid
    {
        protected double length;
        private double width;
        private double high;
        public double Length { get { return length; } set { length = value; } }
        public double Width { get { return width; } set { width = value; } }
        public double High { get { return high; } set { high = value; } }
        public Cuboid(double l, double w, double h)
        { length = l; width = w; high = h; }
        public double CuboidCubage()
        { return length * width * high; }
    }
    public class Cube : Cuboid
    {
        public Cube(double l) : base(l, 0, 0) { }
        public double CubeCubage()
        { return length * length * length; }
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -