0% found this document useful (0 votes)
23 views3 pages

Lab 7 Part 1

The document contains a C# program to create three classes: Person, Teacher, and Program. The Person class contains private properties for name, address, and age with default values. It has a print method to output these properties. The Teacher class inherits from Person and adds private properties for salary and salary deductions. It overrides the print method to output these additional properties. The totalsalary method calculates salary minus deductions. The Main method in the Program class creates instances of Person and Teacher. It gets user input to set the properties and calls the print and totalsalary methods.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
23 views3 pages

Lab 7 Part 1

The document contains a C# program to create three classes: Person, Teacher, and Program. The Person class contains private properties for name, address, and age with default values. It has a print method to output these properties. The Teacher class inherits from Person and adds private properties for salary and salary deductions. It overrides the print method to output these additional properties. The totalsalary method calculates salary minus deductions. The Main method in the Program class creates instances of Person and Teacher. It gets user input to set the properties and calls the print and totalsalary methods.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 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