0% found this document useful (0 votes)
8 views6 pages

lab task 4

The document describes two C# programs: one for calculating salaries of employees (Managers and Programmers) with different formulas, and another for demonstrating animal behavior and communication. The Employee class is abstract, with derived classes for Manager and Programmer implementing specific salary calculations. The Animal class is also abstract, with derived classes for Dog, Cat, and Cow showcasing their unique communication and behavior.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views6 pages

lab task 4

The document describes two C# programs: one for calculating salaries of employees (Managers and Programmers) with different formulas, and another for demonstrating animal behavior and communication. The Employee class is abstract, with derived classes for Manager and Programmer implementing specific salary calculations. The Animal class is also abstract, with derived classes for Dog, Cat, and Cow showcasing their unique communication and behavior.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 6

1. ABC Company has two types of employees Manager and Programmer.

Based on their role they have separate job responsibilities. The company
calculate the salary of their employees. But the calculation formula for
Employee is different for different types of role.

using System;

namespace ABCCompany

// Base class for Employee

abstract class Employee

public string Name { get; set; }

public decimal BaseSalary { get; set; }

public Employee(string name, decimal baseSalary)

Name = name;

BaseSalary = baseSalary;

public abstract decimal CalculateSalary();

// Manager class

class Manager : Employee

public decimal BonusPercentage { get; set; }

public decimal PerformanceIncentives { get; set; }


public Manager(string name, decimal baseSalary, decimal bonusPercentage, decimal
performanceIncentives)

: base(name, baseSalary)

BonusPercentage = bonusPercentage;

PerformanceIncentives = performanceIncentives;

public override decimal CalculateSalary()

decimal bonus = (BonusPercentage / 100) * BaseSalary;

return BaseSalary + bonus + PerformanceIncentives;

// Programmer class

class Programmer : Employee

public decimal SkillLevelMultiplier { get; set; }

public decimal ProjectBonus { get; set; }

public Programmer(string name, decimal baseSalary, decimal skillLevelMultiplier, decimal


projectBonus)

: base(name, baseSalary)

SkillLevelMultiplier = skillLevelMultiplier;

ProjectBonus = projectBonus;

}
public override decimal CalculateSalary()

decimal adjustedSalary = SkillLevelMultiplier * BaseSalary;

return adjustedSalary + ProjectBonus;

class Program

static void Main(string[] args)

// Create a Manager

Manager manager = new Manager("Hasib", 90000m, 30m, 2000m);

Console.WriteLine($"Manager: {manager.Name}, Salary: {manager.CalculateSalary():C}");

// Create a Programmer

Programmer programmer = new Programmer("Rahat", 40000m, 1.1m, 7000m);

Console.WriteLine($"Programmer: {programmer.Name}, Salary:


{programmer.CalculateSalary():C}");

2. Different Animal behaves differently. The communication is also different for each of them.
We know Dog will bark, similarly, cow will moo, cat will meow. Though all of them are
animals they will behave differently.

using System;
namespace AnimalBehavior

// Abstract base class

public abstract class Animal

// Abstract method for communication

public abstract string Communicate();

// Method to describe behavior

public virtual string Behavior()

return "This animal behaves according to its species.";

// Dog class inheriting from Animal

public class Dog : Animal

public override string Communicate()

return "Woof!";

public override string Behavior()

return "Dogs are loyal and friendly.";

}
// Cat class inheriting from Animal

public class Cat : Animal

public override string Communicate()

return "Meow!";

public override string Behavior()

return "Cats are independent and curious.";

// Cow class inheriting from Animal

public class Cow : Animal

public override string Communicate()

return "Moo!";

public override string Behavior()

return "Cows are gentle and social animals.";

}
// Main program

class Program

static void Main(string[] args)

// Create instances of each animal

Animal dog = new Dog();

Animal cat = new Cat();

Animal cow = new Cow();

// Array of animals

Animal[] animals = { dog, cat, cow };

// Loop through each animal and display their communication and behavior

foreach (Animal animal in animals)

Console.WriteLine($"The {animal.GetType().Name} says: {animal.Communicate()}");

Console.WriteLine(animal.Behavior());

Console.WriteLine();

// Wait for user input before closing

Console.WriteLine("Press any key to exit...");

Console.ReadKey();

You might also like