Code Monkey home page Code Monkey logo

ex04-constructor's Introduction

Constructor

Aim:

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

Algorithm:

Step 1:

Create a new Class named employee.

Step 2:

Create a constructor

Step 3:

Create two methods one is Salary & other is Display

Step 4:

Create a main function and get name, designation, experience, basic salary and insurance amount from the User.

Step 5:

Create a object and pass the input as parameters

Step 6:

Call the salary method to calculate the salary

Step 7:

Call the display method to display the details

Step 8:

End of the Program.

Program:

Name: Gunaseelan G
Reg.no: 212221230031
using System;
namespace sample { 
class employee
{
    string name;
    string designation;
    int basic_salary;
    int experience;
    int insurance;
    float gross_salary;
    float hra, da;
    public employee(string name, string designation, int basic_salary, int experience, int insurance)
    {
        this.name = name;
        this.designation = designation;
        this.basic_salary = basic_salary;
        this.experience = experience;
        this.insurance = insurance;
        salary(basic_salary, experience);
        display();

    }
    public void salary(int basic_salary, int insurance)
    {

        hra = (20 / 100) * basic_salary;
        da = (10 / 100) * basic_salary;
        gross_salary = basic_salary + hra + da - insurance;

    }
    void display()
    {
        Console.WriteLine("Name of the employee: " + this.name);
        Console.WriteLine("Designation: " + this.designation);
        Console.WriteLine("Experience: " + this.experience + " years");
        Console.WriteLine("Gross salary: " + gross_salary);

    }
}
    class program
    {
        public static void Main(string[] args)
        {
            int basic_salary;
            int experience;
            int insurance;
            string name,designation;
            Console.Write("Enter the name of the employee: ");
            name = Console.ReadLine();
            Console.Write("Enter the designation of the employee: ");
            designation = Console.ReadLine();
            Console.Write("Enter the experience: ");
            experience = Convert.ToInt32(Console.ReadLine());
            Console.Write("Insurance: ");
            insurance = Convert.ToInt32(Console.ReadLine());
            Console.Write("Enter the basic salary: ");
            basic_salary = Convert.ToInt32(Console.ReadLine());
            Console.WriteLine("---------------------------------------------");
            employee emp = new employee(name,designation, basic_salary,experience, insurance);
        }
    }
}

Output:

ex4 arvr

Result:

Hence, a C# program to calculate the salary of an employee by passing the name, designation, years of experience, basic salary and insurance amount through constructor is executed successfully

ex04-constructor's People

Contributors

archanasharikalharinarayanan avatar guru-guna 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.