Coder Social home page Coder Social logo

ex04-constructor's Introduction

Constructor

Aim:

To write a C# program to calculate the salary of an employee by passing the name, designation, noofexperience, basic salary and insurance amount through constructor.

Algorithm:

Step1:

Start

Step2:

Create a class and a constructor

Step3:

Get name, designation, noofexperience, basic salary and insurance amount from the User.

Step4:

call salary method in constructor to calculate salary.

Step5:

call display method to display the output.

Step6:

stop

Program:

using System;
class Employee
{
   string name,designation;
   int experience,basicsalary,insurance;
   double hra,ta,salary1;
   public Employee(string name,string designation,int experience,int basicsalary,int insurance)
   {
       this.name=name;
       this.designation=designation;
       this.experience=experience;
       this.basicsalary=basicsalary;
       this.insurance=insurance;
   }
   public void salary()
   {
       hra = 0.2*this.basicsalary;
       ta = 0.1*this.basicsalary;
       salary1 = hra+ta+this.basicsalary-this.insurance;
   }
   public void display()
   {
       Console.WriteLine("name of employee is {0} having {1} of experience ,working as {2}",this.name,this.experience,this.designation);
       Console.WriteLine("receives {0} of salary",salary1);
   }
   public static void Main(string[] args)
   {
       Employee emp1 = new Employee("Hari","Tester",10,30000,1000);
       emp1.salary();
       emp1.display();
       Employee emp2 = new Employee("Latha","Developer",5,25000,1000);
       emp2.salary();
       emp2.display();
   }
}

Output:

image

Result:

Thus C# program to calculate the salary of an employee by passing the name, designation, noofexperience, basic salary and insurance amount through constructor is executed successfully.

ex04-constructor's People

Contributors

archanasharikalharinarayanan avatar khadar134 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.