Employee Salary, Payroll Program. Example for Program to calculate gross salary, deduction. Program to print employee. This is Payroll Management System Software. Here all the details of the employee's salary are stored. Here the perfect calculation of the particular employee is. C# 4. 0 Tutorial: Inheritance II 2. The Details of Inheritance. In this section, we'll create a more complex example using Employee class we made in Encapsulation Services. We'll create two new classes (Sales. Person and Manager) leveraging the functionality of the Employee class. In our example, the Manager class extends Employee by recording the number of stock options, while the Sales. Person class maintains the number of sales made. Here are the new classes. Employees. . We have two ways of doing this: Project - > Add New Item menu options - > Once we click the Add button, we'll be presented with a blank designer surface - > To add types to a class designer, simply drag each file from the Solution Explorer window onto the surface. When we do so, the IDE responds by automatically including all types on the designer surface. Simply click View Class Diagram icon. Here is the Diagram for Employee class Hierarchy. The base Keyword. The Sales. Person and Manager were created using default constructor. We'll add six- argument constructor to the Manager type. So, we cannot assign the incoming string parameter to this field.
C Sharp Program For Employee Salary Calculation After TaxesAfter this point, the current implementation accesses various public properties of the Employee base class to establish its state. So, we have really made seven hits (five inherited properties and two constructor calls) during the creation of a Manager object. To optimize the creation of a derived class, we'll do well to implement our subclass constructors to explicitly call an appropriate custom base class constructor, rather than the default. In this way, we can reduce the number of calls to inherited initialization members. Let's update the constructor of the Manager type using the base keyword. Manager(string full. Name, int age, int emp. ID. float cur. Pay, string ssn, int numb. Of. Opts). : base(full. Name, age, emp. ID, cur. Pay, ssn). . In our case, we're explicitly calling the five- argument constructor defined by Employee and saving ourselves unnecessary calls during creation of the child class. Here is Sales. Person constructor. Sales. Person(string full. Name, int age, int emp. ID. float cur. Pay, string ssn, int num. Of. Sales). : base(full. Name, age, emp. ID, cur. Pay, ssn). . So, we need to redefine the default constructor for the Sales. Person and Manager types. For instance. public Sales. Person() . So, if we want to allow the Sales. Person and Manager child classes to directly access the data defined by Employee, we need to update the original Employee class as follows. Employee. . For example, assume we have added yet another class, Part. Time. Sales. Person to our program that extends the existing Sales. Person type. If we want to build a new class that leverages the functionality of a sealed class, our only option is to forego classical inheritance and use the containment/delegation model. Here are the files we made so far. System. Collections. Generic. using System. Linq. using System. Text. namespace Employees. Let's extend our existing Employee class by adding an employee benefits package. Benefit. Package. But it should be clear that some sort of relationship exist between the two. Certainly, it makes sense to establish has- a relationship because each employee has- a. Benefit. Package. Here is an update for Employee class definition. Benefit. Package emp. Benefits = new Benefit. Package(). So, with the added line above, we actually contained another object. However, to expose the functionality of the contained object to the outside world needs delegation. Delegation is simply the act of adding members to the containing class which uses the contained object's functionality. In our example, we could update the Employee class to expose the contained emp. Benefits object using a custom property as well as using its functionality internally utilizing a new method Get. Benefit. Cost(). So, here is another update for our Main() method interacting with the internal Benefit. Package type. The inner (or nested) type is considered a member of the outer (or nesting) class. To the runtime it can be manipulated like any other member. Here is the syntax. Outer. Class. . But if we want to use a nested type from outside of the containing type, we must qualify it by the scope of the nesting type. Let's look at the following code. Main(string. This means we're binding the connection tight between Employee, Benefit. Package, and Benefit. Package. Level. Now our hierarchy of types includes inheritance, containment, and nested types as shown in the picture below: Here are our codes so far. System. Collections. Generic. using System. Linq. using System. Text. namespace Employees. Your tax constants are a percent, but you're not dividing by 1.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. Archives
September 2016
Categories |