zoukankan      html  css  js  c++  java
  • 第六章 简答题

    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();
                }
            }
        }
    }
    复制代码
  • 相关阅读:
    投产包错误的思考
    Oracle----用户操作
    3.27 学习记录
    3.26 学习记录
    3.25 学习记录
    3.24 学习记录
    3. 23构建之法读后感
    3.22 学习记录
    3. 21学习记录
    3.20 学习记录
  • 原文地址:https://www.cnblogs.com/wuayn/p/8810303.html
Copyright © 2011-2022 走看看