您当前的位置: 首页 >  c#

跋扈洋

暂无认证

  • 5浏览

    0关注

    221博文

    0收益

  • 0浏览

    0点赞

    0打赏

    0留言

私信
关注
热门博文

C#计算工资(派生类)

跋扈洋 发布时间:2021-04-16 10:56:39 ,浏览量:5

功能

编写控制台应用程序,设计一个普通职工类Employee,其工资为基本工资(1000)加上工龄工资(每年增加30元)。从Employee类派生一个本科生类UEmployee,其工资为普通职工算法的1.5倍;另从Employee类派生一个研究生类SEmployee,其工资为普通职工算法的2倍,要求计算工资用虚方法实现;分别用相关数据进行测试。

程序
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApplication1
{ 
    public class Employee
    {
        private double bsalary = 1000;
        private double psalary;
        private int n;
        public int Pn
        {
            get { return n; }
            set { n = value; }
        }
        public virtual double ComSalary()
        {
            Console.Write("工作年数:");
            Pn = int.Parse(Console.ReadLine());
            psalary = bsalary + 30 * Pn;
            return psalary;
        }
        public class UEmployee : Employee
        {
            new public double ComSalary()
            {
                return 1.5 * base.ComSalary();
            }
        }
        public class SEmployee : Employee
        {
            public override double ComSalary()
            {
                return 2 * base.ComSalary();
            }
        }
        class Program
        {
            static void Main(string[] args)
            {
                Console.WriteLine("普通职工:");
                Employee emp1 = new Employee();
                Console.WriteLine("该普通职工的工资为:{0}", emp1.ComSalary());
                Console.WriteLine("本科生职工:");

                UEmployee emp2 = new UEmployee();

                Console.WriteLine("本科生职工的工资为:{0}", emp2.ComSalary());

                Console.WriteLine("研究生职工:");

                SEmployee emp3 = new SEmployee();

                Console.WriteLine("研究生职工的工资为:{0}", emp3.ComSalary());
                Console.ReadKey();

            }

        }

    }

}

运行结果

后续

如果想了解更多物联网、智能家居项目知识,可以关注我的程序设计专栏。 或者关注公众号。 在这里插入图片描述

编写不易,感谢支持。

关注
打赏
1663745539
查看更多评论
立即登录/注册

微信扫码登录

0.0448s