• c#基类继承


    【 塔 · 第 三 条 约 定 】

    编写一个多边形作为基类(成员:定点数)抽象方法(子类实现):体积、边长

    1. 正三角形类:成员 边长
    2. 长方形类:成员 长宽
    using System;
    using System.Collections.Generic;
    using System.Text;
    
    namespace 第三条约定
    {
        abstract class Base
        {
            public static int point;//定点数
            public static double area;//面积
            
        }
        class regular_triangle : Base//定义正三角形类
        {
            public void input()
            {
                Console.WriteLine("请输入正三角形定点数:");
                
                point = Convert.ToInt32(Console.ReadLine());//获取定点数
                if (point != 3)
                {
                    Console.WriteLine("这不是一个三角形");
                }
             
            }
            int length;//私有成员 边长
            public void _regular_triangle()
            {
                Console.WriteLine("请输入正三角形的边长");
                length = Convert.ToInt32(Console.ReadLine()); ;//获取边长
                area = 0.433 * (length * length);
            }
            public void output()
            {
                Console.WriteLine("边长:{0}", length);//输出私有成员边长
                Console.WriteLine("正三角形的面积是:{0}", area);
            }
    
        }
        class orthogon : Base//定义矩形类
        {
    
    
            int length;//私有成员 长
            int width;//私有成员 宽
            public void input()
            {
                Console.WriteLine("请输入矩形的定点数:");
    
                point = Convert.ToInt32(Console.ReadLine());//获取定点数
                if (point != 4)
                {
                    Console.WriteLine("这不是一个矩形");
                }
             
            }
            public void _orthogon()
            {
    
                Console.WriteLine("请输入矩形的长与宽");
                length = Convert.ToInt32(Console.ReadLine());//获取长
                width = Convert.ToInt32(Console.ReadLine());//获取宽
                area = (length * width);
    
            }
            public void output()
            {
                Console.WriteLine("长:{0},宽:{1}", length, width);//输出私有成员长与宽
                Console.WriteLine("矩形的面积是:{0}",area);
            }
        }
    }
    class Program
    {
        static void Main(string[] args)
        {
            第三条约定.regular_triangle a = new 第三条约定.regular_triangle();
                 a.input();
                 a._regular_triangle();
                a.output();//输出形状与面积
            第三条约定.orthogon b = new 第三条约定.orthogon();
                 b.input();
                 b._orthogon();
                b.output();//输出形状与面积
            Console.ReadKey();
        }
        
        public static int point { get; set; }
    }
    

    遇到的问题

    • 在调试的时候程序没有Console.ReadKey();导致调试时没有等待输入,窗口闪退的情况
    • 还有题目理解不明,继承还是有点不明白。
  • 相关阅读:
    大型网站前端使用图片格式的正确姿势
    移动端开发技术文档
    超详细的Web前端开发规范文档
    try 、catch 、finally 、throw 测试js错误
    ajax大并发问题
    jQuery之Ajax--全局Ajax事件处理器
    如何处理ajax中嵌套一个ajax
    关于for循环里面异步操作的问题
    XMLHttpRequest: 网络错误 0x2f78,…00002f78
    【转载】OGRE中用到的设计模式
  • 原文地址:https://www.cnblogs.com/mercuialC/p/6395365.html
Copyright © 2020-2023  润新知