• 第六章 继承和多态 计算项目代码


    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    
    namespace ConsoleApplication1
    {
        public class Program
        {
            public class Operate
            {
                protected int a, b;
                public Operate(int a, int b)
                {
                    this.a = a;
                    this.b = b;
                }
                public virtual int op()
                {
                    return -1;
                }
            }
            /// <summary>
            /// 整数相加
            /// </summary>
            public class Sum : Operate
            {
                public Sum(int a, int b)
                    : base(a, b)
                { }
                public override int op()
                {
                    return this.a + this.b;
                }
            }
            /// <summary>
            /// 整数相减
            /// </summary>
            public class Sub : Operate
            {
                public Sub(int a, int b)
                    : base(a, b)
                { }
                public override int op()
                {
                    return this.a - this.b;
                }
            }
            /// <summary>
            /// 整数相乘
            /// </summary>
            public class Muli : Operate
            {
                public Muli(int a, int b)
                    : base(a, b)
                { }
                public override int op()
                {
                    return this.a * this.b;
                }
            }
    
          public  class Programdgd
            {
                static void Main(string[] args)
                {
                    Console.WriteLine("请录入两个整数:");
                    int num1 = int.Parse(Console.ReadLine());
                    int num2 = int.Parse(Console.ReadLine());
    
    
                    Operate sum = new Sum(num1, num2);
                    int result1 = sum.op();
                    Console.WriteLine("相加的结果:{0}", result1);
    
                    Operate sub = new Sub(num1, num2);
                    int result2 = sub.op();
                    Console.WriteLine("相减的结果:{0}", result2);
    
                    Operate muli = new Muli(num1, num2);
                    int result3 = muli.op();
                    Console.WriteLine("相乘的结果:{0}", result3);
                    Console.ReadLine();
                }
            }
        }
    }
  • 相关阅读:
    checkbox美化
    JS 之简单计算器
    python实现简单用户认证和角色制授权
    搭建高性能web服务
    纯JS实现fadeIn 和fadeOut
    纯CSS实现气泡框
    javascript之对象(二)&& 继承问题
    JavaScript之对象(一)
    Web发展史
    [LeetCode 256] Paint House
  • 原文地址:https://www.cnblogs.com/SFHa/p/8796377.html
Copyright © 2020-2023  润新知