C#计算工资(派生类)
生活随笔
收集整理的這篇文章主要介紹了
C#计算工资(派生类)
小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
功能
編寫控制臺(tái)應(yīng)用程序,設(shè)計(jì)一個(gè)普通職工類Employee,其工資為基本工資(1000)加上工齡工資(每年增加30元)。從Employee類派生一個(gè)本科生類UEmployee,其工資為普通職工算法的1.5倍;另從Employee類派生一個(gè)研究生類SEmployee,其工資為普通職工算法的2倍,要求計(jì)算工資用虛方法實(shí)現(xiàn);分別用相關(guān)數(shù)據(jù)進(jìn)行測(cè)試。
程序
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("工作年數(shù):");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();}}}}運(yùn)行結(jié)果
后續(xù)
如果想了解更多物聯(lián)網(wǎng)、智能家居項(xiàng)目知識(shí),可以關(guān)注我的程序設(shè)計(jì)專欄。
或者關(guān)注公眾號(hào)。
編寫不易,感謝支持。
總結(jié)
以上是生活随笔為你收集整理的C#计算工资(派生类)的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: Maven 创建 Spring、Spri
- 下一篇: RHS 和 LHS