阳光石油网|石油技术交流|石油人论坛

 找回密码
 欢迎注册
查看: 1381|回复: 3

[基本理论] 建模与编程2

[复制链接]
  • TA的每日心情
    慵懒
    2012-11-8 10:13
  • 签到天数: 15 天

    [LV.4]偶尔看看III

    发表于 2016-1-31 21:15:23 | 显示全部楼层 |阅读模式

    马上注册,下载丰富资料,享用更多功能,让你轻松玩转阳光石油论坛。

    您需要 登录 才可以下载或查看,没有账号?欢迎注册

    x
    大家好,第二期来了
    abstract class ShapesClass !地质体形态类
    {    abstract public int Area();  !储量面积函数,然而如何计算?}class Square : ShapesClass   !正方形地质体类
    {    int side = 0;              public Square(int n)       !边长函数(n)    {        side = n;    }
        public override int Area() !计算正方形地质体面积,我们知道area是地质体类的一个函数,但是我们这里要给他填满
        {        return side * side;    }[size=13.142857551574707px]
    [size=13.142857551574707px]// [size=13.142857551574707px]Square[size=13.142857551574707px] 类必须提供 [size=13.142857551574707px]Area[size=13.142857551574707px] 的重写实现,因为 [size=13.142857551574707px]Area[size=13.142857551574707px] 继承自抽象的 [size=13.142857551574707px]ShapesClass    static void Main()      {        Square sq = new Square(12);  ! 生成正方形类的一个对象        Console.WriteLine("Area of the square = {0}", sq.Area());调用对象的面积函数    }
        interface I
        {        void M();    }    abstract class C : I
        {        public abstract void M();    }
    }

    重写属性声明必须指定与继承属性完全相同的访问修饰符、类型和名称,

    并且被重写的属性必须是 virtualabstractoverride 的。




    [size=13.142857551574707px]
    class TestOverride 地质体类{    public class Employee 地质体子类
        {        public string name; 地质体名称        // Basepay is defined as protected, so that it may be
            // accessed only by this class and derrived classes.
            protected decimal basepay; 地质体体积        // Constructor to set the name and basepay values.
            public Employee(string name, decimal basepay) 构造函数,地质体名称,地质体体积        {            this.name = name;            this.basepay = basepay;        }
            // Declared virtual so it can be overridden.这里我们声明一个虚拟的,以后再改写哈哈        public virtual decimal CalculatePay()  计算地质体净体积
            {            return basepay;
            }
        }
        public class SalesEmployee : Employee 孙子地质体类是从爸爸地质体类继承的
        {        // New field that will affect the base pay.        private decimal salesbonus;
            // The constructor calls the base-class version, and
            // initializes the salesbonus field.
            public SalesEmployee(string name, decimal basepay,  构造函数,地质体名称,砂岩体积,泥岩体积
                      decimal salesbonus) : base(name, basepay)        {
                this.salesbonus = salesbonus;        }        // 重写计算地质体体积方法考虑        //
            public override decimal CalculatePay()
            {            return basepay + salesbonus;     砂岩体积+泥岩体积   }
        }[size=13.142857551574707px]
        [size=13.142857551574707px]  [size=13.142857551574707px]static[size=13.142857551574707px] [size=13.142857551574707px]void[size=13.142857551574707px] Main()    {        // 来一些新的地质体 河道,天然堤
            SalesEmployee employee1 = new SalesEmployee("Alice",
                          1000, 500); alice地质体,1000,500,不错哈哈        [size=13.142857551574707px]

    [size=13.142857551574707px]








  • TA的每日心情
    开心
    2025-1-24 09:50
  • 签到天数: 1516 天

    [LV.Master]伴坛终老

    发表于 2016-2-1 09:25:07 | 显示全部楼层
    高手!!
    回复 支持 反对

    使用道具 举报

  • TA的每日心情
    无聊
    2017-2-26 17:13
  • 签到天数: 301 天

    [LV.8]以坛为家I

    发表于 2016-2-2 22:09:45 | 显示全部楼层
    回复 支持 反对

    使用道具 举报

  • TA的每日心情
    奋斗
    2025-1-9 09:42
  • 签到天数: 521 天

    [LV.9]以坛为家II

    发表于 2016-10-26 11:28:18 | 显示全部楼层
    写petrel插件?
    回复 支持 反对

    使用道具 举报

    您需要登录后才可以回帖 登录 | 欢迎注册

    本版积分规则

    QQ|Archiver|手机版|小黑屋|阳光石油网 ( 鲁ICP备2021003870号-1 )

    GMT+8, 2025-2-2 12:12 , Processed in 0.054771 second(s), 24 queries .

    Powered by Discuz! X3.4 Licensed

    Copyright © 2001-2021, Tencent Cloud.

    快速回复 返回顶部 返回列表