Lab 7 Part 1

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 3

‫ نادية محمود حسين‬.‫م‬.‫م‬ ‫ ندى ذنون أحمد‬.‫م‬.

‫أ‬ ‫مرحلة ثانية‬ ‫مختبر برمجة كيانية‬

Q1: write C# program to create three classes where they contain the following
components:

Person
-name:string
-address:string
-age: int
Constructor (default)
Property(set , get)
+ print: void

Teacher
- salary: double
- Salarydeductions : double
Constructor (default)
Property (set , get)
+totalsalary:double
‫ نادية محمود حسين‬.‫م‬.‫م‬ ‫ ندى ذنون أحمد‬.‫م‬.‫أ‬ ‫مرحلة ثانية‬ ‫مختبر برمجة كيانية‬

class Program
{
static void Main(string[] args)
{
Person P1 = new Person();
P1.print();

Console.WriteLine("\n*************************************");
Teacher t1 = new Teacher( );
Console.Write("enter teacher name : ");
t1.setgetname = Console.ReadLine();
Console.Write("\nenter address of teacher : ");
t1.setgetaddress = Console.ReadLine();
Console.Write("\nenter age of teacher : ");
t1.setgetage = Int32.Parse(Console.ReadLine());
Console.Write("\nenter salary of teacher : ");
t1.setgetsalary= Double.Parse(Console.ReadLine());
Console.Write("\nenter salarydeductoins of teacher : ");
t1.setgetsalarydeductions = Double.Parse(Console.ReadLine());
Console.WriteLine("\n_____________________________________");
t1.print();
t1.printte();
Console.WriteLine("total salary = " + t1.totalsalary());
Console.ReadLine();
}
}
class Person
{
private string name, address;
private int age;
public Person( )
{
name = "Ali";
address = "iraq";
age = 40;
}
public string setgetname
{
get { return name; }
set { name = value; }
}
public string setgetaddress
{
get { return address; }
set { address = value; }
}
public int setgetage
{
get { return age; }
set { age = value; }
}
public void print()
{
Console.WriteLine("Name : " + name + "\nAddress : " + address + "\nAge : " +
age);
‫ نادية محمود حسين‬.‫م‬.‫م‬ ‫ ندى ذنون أحمد‬.‫م‬.‫أ‬ ‫مرحلة ثانية‬ ‫مختبر برمجة كيانية‬

class Teacher : Person


{
private double salary, salarydeductoins;
public Teacher()

{
salary = 0;
salarydeductoins = 0;
}
public double setgetsalary
{
get { return salary; }
set { salary = value; }
}
public double setgetsalarydeductions
{
get { return salarydeductoins; }
set { salarydeductoins = value; }
}
public void printte()
{
Console.WriteLine("salary : " + setgetsalary + "\nsalary deductoins : " +
setgetsalarydeductions);
}
public double totalsalary()
{
return salary - salarydeductoins;
}
}

You might also like