0% found this document useful (0 votes)
3 views

Lab 4 Answers

The document contains C# code for a lab assignment involving employee management with two types of employees: ContractEmployee and PermanentEmployee, each with their own salary calculation methods. It also includes a console application that prompts the user to input employee details and calculates the final salary based on the employee type. Additionally, there is a simple shape hierarchy demonstrating polymorphism with classes for Shape, Triangle, and Circle.

Uploaded by

Vijay jakune
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views

Lab 4 Answers

The document contains C# code for a lab assignment involving employee management with two types of employees: ContractEmployee and PermanentEmployee, each with their own salary calculation methods. It also includes a console application that prompts the user to input employee details and calculates the final salary based on the employee type. Additionally, there is a simple shape hierarchy demonstrating polymorphism with classes for Shape, Triangle, and Circle.

Uploaded by

Vijay jakune
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 3

Lab 4:

Dll File
Employee.cs //for Q1
using System;
namespace Lab4lib
{
public abstract class Employee
{
int employeeId;
string employeeName;
string address;
string city;
string department;
int salary;
public int EmployeeId
{
get; set;
}
public string EmployeeName
{
get; set;
}
public string Address
{
get; set;
}
public string City
{
get; set;
}
public string Department
{
get; set;
}
public int Salary
{
get; set;
}
public Employee(int employeeId, string employeeName, string address,
string city, string department, int salary)
{
this.EmployeeId = employeeId;
this.EmployeeName = employeeName;
this.Address = address;
this.City = city;
this.Department = department;
this.Salary = salary;
}
public abstract double getSalary();
}
public class ContractEmployee : Employee
{
public ContractEmployee(double perks,int employeeId,string
employeeName,string address,string city,string department,int salary):
base(employeeId,employeeName,address,city,department,salary)
{
this.Perks = perks;
}
public double Perks { get; set; }
public override double getSalary()
{
return this.Salary + Perks;
}
}
public class PermanentEmployee : Employee
{
public int NoOfLeaves { get; set; }
public double ProvidendFund { get; set; }
public PermanentEmployee(double providentFund,int noOfLeaves, int
employeeId, string employeeName, string address, string city, string department,
int salary) : base(employeeId, employeeName, address, city, department, salary)
{
this.ProvidendFund = providentFund;
this.NoOfLeaves = noOfLeaves;
}
public override double getSalary()
{
return this.Salary - this.ProvidendFund;
}
}
}
Console File
Answer 1:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Lab4lib;
namespace Lab4
{
class Program1
{
static void Main(string[] args)
{
Console.WriteLine("Select the type of Employee :\n1. Contract
Employee\n2. Permanent Employee");
int c = int.Parse(Console.ReadLine());
Console.Write("Enter employee id: ");
int employeeId = int.Parse(Console.ReadLine());
Console.Write("Enter employee name: ");
string employeeName = Console.ReadLine();
Console.Write("Enter address: ");
string address = Console.ReadLine();
Console.Write("Enter city: ");
string city = Console.ReadLine();
Console.Write("Enter department: ");
string department = Console.ReadLine();
Console.Write("Enter salary: ");
int salary = int.Parse(Console.ReadLine());
if (c == 1)
{
Console.Write("Enter Perks");
double perks = double.Parse(Console.ReadLine());
ContractEmployee ce = new ContractEmployee(perks, employeeId,
employeeName, address, city, department, salary);
double res = ce.getSalary();
Console.WriteLine("The final salary will be: {1}", res) ;
}
else if(c == 2){
Console.Write("Enter Providend Fund: ");
double providendFund= double.Parse(Console.ReadLine());
Console.Write("Enter No. of leaves: ");
int noOfLeaves = int.Parse(Console.ReadLine());
PermanentEmployee pe = new PermanentEmployee(providendFund,
noOfLeaves, employeeId, employeeName, address, city, department, salary);
double res = pe.getSalary();
Console.WriteLine("The final salary will be: {0}", res);
}
else Console.WriteLine("Invalid choice");
Console.ReadLine();
}
}
}
Answer 2:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Lab4
{
public class Shape
{
public virtual void WhoamI()
{
Console.WriteLine("I m Shape");
}
}
class Triangle : Shape
{
public override void WhoamI()
{
Console.WriteLine("I m Triangle");
}
}
public class Circle : Shape
{
public override void WhoamI()
{
Console.WriteLine("I m Circle");
}
}
class Program
{
static void Main(string[] args)
{
Shape s;
s = new Triangle();
s.WhoamI();
s = new Circle();
s.WhoamI();
Console.ReadKey();
}
}
}

You might also like