עליך להתחבר בכדי להוריד קבצים מהאתר
על מנת להבטיח שמשאבינו לא ינוצלו לרעה.
1 : abstract class Person
2 : {
3 : private string firstName;
4 : private string lastName;
5 : private string id;
6 : public Person(string first, string last, string id)
7 : {
8 : this.firstName = first;
9 : this.lastName = last;
10 : this.id = id;
11 : }
12 : public void Print()
13 : {
14 : Console.WriteLine("Name : {0} {1}", lastName, firstName);
15 : Console.WriteLine("ID : {0}", id);
16 : PrintDetails();
17 : }
18 : protected abstract void PrintDetails();
19 : public string FirstName
20 : {
21 : get { return firstName; }
22 : set { firstName = value; }
23 : }
24 : public string LastName
25 : {
26 : get { return lastName; }
27 : set { lastName = value; }
28 : }
29 : public string ID
30 : {
31 : get { return id; }
32 : }
33 : }
1 : abstract class Employee : Person
2 : {
3 : private int empNum;
4 : private string department;
5 : public Employee(string first, string last, string id, int num, string dpt)
6 : : base(first, last, id)
7 : {
8 : this.empNum = num;
9 : this.department = dpt;
10 : }
11 : protected override void PrintDetails()
12 : {
13 : Console.WriteLine("Employee num : {0}\nDepatment : {1}", empNum, department);
14 : }
15 : public int EmpNum
16 : {
17 : get
18 : {
19 : return empNum;
20 : }
21 : set
22 : {
23 : if (value < 0)
24 : empNum = value;
25 : }
26 : }
27 : public string Department
28 : {
29 : get
30 : {
31 : return department;
32 : }
33 : set
34 : {
35 : department = value;
36 : }
37 : }
38 : public float CalcSalary()
39 : {
40 : float bruto = CalcBruto();
41 : return bruto - CalcIncomeTax(bruto) - CalcSocialInsuranceTax(bruto);
42 : }
43 : protected abstract float CalcBruto();
44 : private float CalcIncomeTax(float bruto)
45 : {
46 : return bruto * 0.3f;
47 : }
48 : private float CalcSocialInsuranceTax(float bruto)
49 : {
50 : return bruto * 0.1f;
51 : }
52 : }
1 : class Worker : Employee
2 : {
3 : private float salPerHour;
4 : private float workingHours;
5 : public Worker(string first, string last, string id, int num, string dpt, float sal, float hours)
6 : : base(first, last, id, num, dpt)
7 : {
8 : SalPerHour = sal;
9 : WorkingHours = hours;
10 : }
11 : public float SalPerHour
12 : {
13 : get
14 : {
15 : return salPerHour;
16 : }
17 : set
18 : {
19 : if (value > 15.5f)
20 : salPerHour = value;
21 : }
22 : }
23 : public float WorkingHours
24 : {
25 : get
26 : {
27 : return workingHours;
28 : }
29 : set
30 : {
31 : if (value >= 0)
32 : workingHours = value;
33 : }
34 : }
35 : protected override void PrintDetails()
36 : {
37 : base.PrintDetails();
38 : Console.WriteLine("Salary Rate = {0}", salPerHour);
39 : Console.WriteLine("Monthly Working Hours = {0}", workingHours);
40 : Console.WriteLine("Salary = {0}", CalcSalary());
41 : }
42 : protected override float CalcBruto()
43 : {
44 : return salPerHour * workingHours;
45 : }
46 : }
1 : class SalesMan : Employee
2 : {
3 : private float totalSales;
4 : public SalesMan(string first, string last, string id, int num, string dpt, float total)
5 : : base(first, last, id, num, dpt)
6 : {
7 : TotalSales = total;
8 : }
9 : public float TotalSales
10 : {
11 : get
12 : {
13 : return totalSales;
14 : }
15 : set
16 : {
17 : if (value >= 0)
18 : totalSales = value;
19 : }
20 : }
21 : protected override void PrintDetails()
22 : {
23 : base.PrintDetails();
24 : Console.WriteLine("Total Sales = {0}", totalSales);
25 : Console.WriteLine("Salary = {0}", CalcSalary());
26 : }
27 : protected override float CalcBruto()
28 : {
29 : return totalSales * 0.03f;
30 : }
31 : }
1 : class Manager : Employee
2 : {
3 : private float monthlySalary;
4 : public Manager(string first, string last, string id, int num, string dpt, float salary)
5 : : base(first, last, id, num, dpt)
6 : {
7 : Salary = salary;
8 : }
9 : public float Salary
10 : {
11 : get { return monthlySalary; }
12 : set { if (value >= 0)monthlySalary = value; }
13 : }
14 : protected override void PrintDetails()
15 : {
16 : base.PrintDetails();
17 : Console.WriteLine("Salary = {0}", CalcSalary());
18 : }
19 : protected override float CalcBruto()
20 : {
21 : return monthlySalary;
22 : }
23 : }
1 : class SeniorManager : Manager
2 : {
3 : private float bonus;
4 : public SeniorManager(string first, string last, string id, int num, string dpt, float
5 : sal, float bonus)
6 : : base(first, last, id, num, dpt, sal)
7 : {
8 : Bonus = bonus;
9 : }
10 : public float Bonus
11 : {
12 : get { return bonus; }
13 : set
14 : {
15 : if (value >= 0)
16 : bonus = value;
17 : }
18 : }
19 : protected override void PrintDetails()
20 : {
21 : Console.WriteLine("Salary = {0}", CalcSalary() + Bonus);
22 : }
23 : protected override float CalcBruto()
24 : {
25 : return base.CalcBruto() + bonus;
26 : }
27 : }
1 : class Program
2 : {
3 : static void Main(string[] args)
4 : {
5 : Worker worker = new Worker("Moshe", "ben moshe", "123456789", 123, "CNC", 32.45f, 181f);
6 : worker.Print();
7 :
8 : SalesMan salesman = new SalesMan("Dina", "batdina", "344555656", 128, "Sales", 180000);
9 : salesman.Print();
10 :
11 : Manager manager = new Manager("Ronen", "Mitlonen", "353444675", 1, "Sales", 24000f);
12 : manager.Print();
13 : }
14 : }