Root فريق هندسة الحواسب
الجنس : عدد المساهمات : 156
| موضوع: شي شارب للتعامل مع كلاس من نوع أستاذ 1/6/2011, 20:08 | |
| - الكود:
-
using System; using System.Collections.Generic; using System.Linq; using System.Text;
namespace ConsoleApplication45 { class teacher { string name, location, subject;
int age; public string Name { set { name = value; } get { return name; } } public string Subject { set { subject = value; } get { return subject; } } public string Location { set { location = value; } get { return location; } } public int Age { set { age = value; } get { return age; } } public teacher () { } public teacher (string name, string subject, string location, int age) { this.name = name; this.subject = subject; this.location = location; this.age = age; } public override string ToString() { return m[i].name + m[i].location; }
}
class Program { static void Main(string[] args) { int n; do { n = Convert.ToInt32(Console.ReadLine()); } while (n <= 0); teacher [] m=new teacher [n]; for (int i=0;i<n;i++) { m[i]=new teacher (); m[i].Name=Console.ReadLine(); m[i].Subject=Console.ReadLine(); m[i].Location=Console.ReadLine(); m[i].Age=Convert.ToInt32(Console.ReadLine()); } //طباعة البيانات ع الشاشة for(int i=0;i<n;i++) Console.WriteLine(m[i]); string str=Console.ReadLine(); int count=0; for(int i=0;i<n;i++) if (m[i].Location == str) { count++;
Console.WriteLine(m[i].Name); } Console.WriteLine(count); //4 Console.WriteLine("Enter name techer"); string stre = Console.ReadLine(); for (int i = 0; i < n; i++) if (m[i].Subject == stre) Console.WriteLine(m[i].Name); //5 Console.WriteLine("Enter name techer old"); for(int i=0;i<n;i++) if(m[i].Age>60) Console.WriteLine(m[i].Name);
} } }
| |
|