C# Lab04
C# Lab04
Session Objectives
In this session, you will be practicing with
Abstract classes and Interface.
}
Step 5: Create new file is Program.cs and write code in it
public class Program{
static void Main(string[] args){
Circle c1 = new Circle(2.45, "Blue", 23);
Console.WriteLine("Circle before change: " + c1.ToString());
//using properties
c1.PColor = "red";
c1.PWeight = 2.56;
2. Indexers demo
set{intList[index] = value;}
}
}
class IndexerDemo
{
static void Main()
{
int i, j = 0;
IndexerExample indexTest = new IndexerExample();
for (i = 1; i < 10; i += 2)
{
indexTest[j] = i;
j++;
}
for (i = 0; i < 5; i++)
Console.WriteLine("indexTest[{0}] is {1}", i, indexTest[i]);
Console.ReadLine();
}
}
Implement a class named Person and two sub classes of Person named Student and Employee. Make
Faculty and Staff sub classes of Employee. A Person has a name, phone number and email address. A
student has a program to which he/she enrolled ( Business, Computer Science...) . An Employee has a
department, salary and the date hired. A faculty member has office hours and a rank. A staff member has
a title. You are required to:
1. Override the ToString() to display the class name and the person's name and email address.
2. Provide properties in each class to read and write it's fields
3. Define a CalculateBonus and CalculateVacation as abstract methods in Employee class and
implement them in Faculty and Staff as follows
o Faculty get 1000 + 0.05 x Salary and Staff get 0.06 x Salary
o Faculty get 5 weeks if they are employed more than 3 years and additional one week if
he/she is "Senior Lecturer". Otherwise 4 weeks. Staff get 4 weeks for 5 year service.
Otherwise get 3 weeks