Code Monkey home page Code Monkey logo

ex04-constructor's Introduction

EX NO:4

DATE:27.4.22

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;
namespace Prass
{
   public class exp4
   {
       public string name, designation;
       public int exp, bs, ins, hra = 0, ta = 0, s = 0;
       void salary(int bs,int ins)
       {
           hra = (20 * bs) / 100;
           ta = (10 * bs) / 100;
           s = bs + hra + ta-ins;
       }
       void display()
       {
           Console.WriteLine("Name of the employee is "+this.name+ " having "+this.exp+ " of experience, working as "+this.designation);
           Console.WriteLine("Receives " + s + " of salary");
       }
       public exp4(string name, string designation, int exp, int bs, int ins)
       {
           this.name = name;
           this.designation = designation;
           this.exp = exp;
           this.bs = bs;
           this.ins = ins;
           salary(bs,ins);
           display();
       }
           
   }
   public class program
   {   
       static void Main(String[] args)
       {
           string nam, desig;
           int exp, bs, ins,n;
           Console.WriteLine("Enter no of employees: ");
           n = Convert.ToInt32(Console.ReadLine());
           for (int i = 1; i <= n; i++)
           {
               Console.WriteLine("Enter name of the employee: ");
               nam = Console.ReadLine();
               Console.WriteLine("Enter designation of the employee: ");
               desig = Console.ReadLine();
               Console.WriteLine("Enter years of experience of the employee: ");
               exp = Convert.ToInt32(Console.ReadLine());
               Console.WriteLine("Enter basic salary of the employee: ");
               bs = Convert.ToInt32(Console.ReadLine());
               Console.WriteLine("Enter insurance: ");
               ins = Convert.ToInt32(Console.ReadLine());
               exp4 emp = new exp4(nam,desig,exp,bs,ins);
           }

           
       }
   }
}

Output:

Screenshot (301)

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

prasannakumar019 avatar archanasharikalharinarayanan 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.