20090403_pcs(p) bài tập c#
TRANSCRIPT
-
8/9/2019 20090403_pcs(p) Bi tp C#
1/5
Programming in C# Page 1 of 5
Practical
-
8/9/2019 20090403_pcs(p) Bi tp C#
2/5
Question 1
I. Create an interface IEmployee that has the following methods:
- double CalculateBonus(string designation, int tenure, double salary):
calculate bonus of employee.
- void DisplayDetails();
II. Create a class Employee inherits from interface IEmployee.
1. Fields private:
string _EmpName: Name of Employee
int _yearsOfService: time work of Employee.
2. Fields protected
double _bonus: Bonus of employee.
3. Fields public
string Designation: position of Employee.
double Salary: Salary of Employee.
4. Properties:
string EmpName Name of employee: R/W. Length of Name from
6 to 40 characters.
int YearsOfService Years of Service of employee: R/W. Value ofYearsOfService from 0 to 60.
Note:
i. R/W: Read-write property.ii. R: Read property.
iii. W: Write property.
5. Methods: Implement 2 method of interface IEmployee.
- Method CalculateBonus(string designation, int tenure, double salary):Calculate bonus of employee follow formula:
if designation is Manager then
if tenure
-
8/9/2019 20090403_pcs(p) Bi tp C#
3/5
Bonus = salary * 2
if designation is Technician then
if (tenure 3 and tenure
-
8/9/2019 20090403_pcs(p) Bi tp C#
4/5
Question 2 : The program demonstrates the use of Constructor and Indexers.
I. Create class Person:
1. Fields Private:o string _IDCard: ID Card of Person.
o string _name: Name of Person.
o int_age: Age of Person.
2. Properties:
o string IDCard ID Card of Person: ReadOnly.
o string Name Name of Person: ReadOnly.
o int Age Age of Person: ReadOnly
3. Create constructor with three parameters to initialize the ID Card, Name
and Age.
II. Create class PersonVietNam
1. Creating a private array of class Person.
2. Constructor with one parameter to initialise the length of the array.
3. Indexer to set and get the values of Persons in the array.
4. the values stored in the array
Create method call DisplayDetails() to display
III. Create class PersonTest is user to test the PersonVietNam class.
1. Create 2 Person. [0.5]
2. Create 1 PersonVietNam, then assignthese Person into the array via
Indexer
3. Invoking the DisplayDetails method to display the PersonVietNamdetails.
Programming in C# Page 4 of 5
-
8/9/2019 20090403_pcs(p) Bi tp C#
5/5
-----THE END-----
Programming in C# Page 5 of 5