MohammadZaidan فريق هندسة الحواسب
الجنس : عدد المساهمات : 829
| موضوع: #C برنامج كلاس واحد لشخص 12/30/2010, 13:32 | |
| - الكود:
-
using System; using System.Collections.Generic; using System.Linq; using System.Text;
namespace ConsoleApplication1 { class Person { string name; string address; string phone; public string Name { set {name=value; } get { return name; } } public string Address { set { address = value; } get { return address; } } public string Phone { set { phone = value; } get { return phone; } } public void Set(string n, string a, string p) { name = n; address = a; phone = p; } public virtual void Get(Person p) { name =p.Name ; address = p.Address; phone = p.Phone; } public virtual void Get(string n , string a , string p) { name=n; address=a; phone=p; } public Person() { } public Person(string n, string a, string p) { name = n; address = a; phone = p; } public virtual double Getaverage() { } public Person(Person p) { name = p.Name; address = p.Address; phone = p.Phone; } } class Student : Person { int[] marks; public int this[int index] { set { marks[index] = value; } get { return marks[index]; } } public Student():base() { } public Student(string n, string a, string p, int[] m) : base(n, a, p) { marks = m; } public Student(Student s) : base(s.Name, s.Address, s.Phone) { this.marks = s.marks; } public Student(Person p, int[] m) : base(p) { marks = m; } public void Read() { Console.WriteLine("Enter Name:"); Name = Console.ReadLine(); Console.WriteLine("Enter Address"); Address = Console.ReadLine(); Console.WriteLine("Enter Phone"); Phone = Console.ReadLine(); Console.WriteLine("Enter Length for marks"); int g = Convert.ToInt32(Console.ReadLine()); marks = new int[g]; for (int i = 0; i <marks.Length; i++) { marks[i] = Convert.ToInt32(Console.ReadLine()); } } public void Print() { Console.WriteLine("Name:"+base.Name); Console.WriteLine("Address:" + base.Address); Console.WriteLine("phone:" + base.Phone); int i = 0; foreach(int s in marks) { Console.WriteLine("Mark-"+(++i)+": "+s); } } public double Getaverage() { int sum = 0; for (int i = 0; i < marks.Length; i++) { sum += marks[i]; } return sum/marks.Length; } public override void Set(Person p ,int [] m) { base.Set(p.Name, p.Address, p.Phone); marks = m; } public override void Get(int[] m) { marks = m; } public override void Get(Person p) { base.Get(p); }
} class Program {
static void Main(string[] args) { Person P1 = new Person(); Person P2 = new Person("Ammar Al Taweel", "Damascus BabHsarkee Street 5", "011-4524544"); P1.Set("Ammar Al Taweel", "Damascus BabHsarkee Street 5", "011-5444444"); string name = "enas"; string add = "fahame"; string tel = "011-2244601"; P1.Get(P2); P1.Get(name, add, tel); P1.Name = "Ali"; Console.WriteLine(P1.Name); Student Stud1 = new Student(); int[] Marks = new int[10] { 50, 60, 90, 50, 60, 60, 40, 66, 89, 70 }; Student Stud2 = new Student(name, add, tel, Marks); Student Stud3 = new Student(Stud1); Student Stud4 = new Student(P1, Marks); Stud1.Read(); Stud2.Print(); Stud1[1] = 33; double avg = Stud1.Getaverage(); Console.WriteLine(avg); Console.WriteLine(Stud1[1]); Stud1.Set(P1, Marks); Stud1.Get(Marks); Stud1.Get(P1); } }
} يمثثل كلاس شخص يضم ما يلي اسمه عنوانه رقم الهاتف وال المين الرئيسية وما يلزمه من بواني | |
|