Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- abstract public class Person: IComparable
- {
- abstract public void Print();
- abstract public int Age();
- public int CompareTo(object obj)
- {
- Person a = (Person) obj;
- if (this.Age() == a.Age()) return 0;
- else if (this.Age() < a.Age()) return -1;
- else return 1;
- }
- }
- class Enrollee: Person
- {
- private string name;
- private string DOB;
- private string faculty;
- public Enrollee (string _name, string _DOB, string _faculty)
- {
- name = _name;
- DOB = _DOB;
- faculty = _faculty;
- }
- public override void Print()
- {
- Console.Write("{0}, {1}, {2}, ", name, DOB, faculty);
- }
- public override int Age()
- {
- string time = DateTime.Now.ToShortDateString();
- int day1 = int.Parse(DOB.Substring(0, 2));
- int month1 = int.Parse(DOB.Substring(3, 2));
- int year1 = int.Parse(DOB.Substring(6));
- int day2 = int.Parse(time.Substring(0, 2));
- int month2 = int.Parse(time.Substring(3, 2));
- int year2 = int.Parse(time.Substring(6));
- if (month1 < month2) return year2 - year1;
- else if (month1 == month2)
- {
- if (day1 <= day2)
- return year2 - year1;
- else return year2 - year1 - 1;
- }
- else return year2 - year1 - 1;
- }
- }
- class Student: Person
- {
- private string name;
- private string DOB;
- private string faculty;
- private int course;
- public Student(string _name, string _DOB, string _faculty, int _course)
- {
- name = _name;
- DOB = _DOB;
- faculty = _faculty;
- course = _course;
- }
- public override void Print ()
- {
- Console.Write("{0}, {1}, {2}, {3}, ", name, DOB, faculty, course);
- }
- public override int Age()
- {
- string time = DateTime.Now.ToShortDateString();
- int day1 = int.Parse(DOB.Substring(0, 2));
- int month1 = int.Parse(DOB.Substring(3, 2));
- int year1 = int.Parse(DOB.Substring(6));
- int day2 = int.Parse(time.Substring(0, 2));
- int month2 = int.Parse(time.Substring(3, 2));
- int year2 = int.Parse(time.Substring(6));
- if (month1 < month2) return year2 - year1;
- else if (month1 == month2)
- {
- if (day1 <= day2)
- return year2 - year1;
- else return year2 - year1 - 1;
- }
- else return year2 - year1 - 1;
- }
- }
- class Teacher: Person
- {
- private string name;
- private string DOB;
- private string faculty;
- private string post;
- private int experience;
- public Teacher (string _name, string _DOB, string _faculty, string _post, int _experience)
- {
- name = _name;
- DOB = _DOB;
- faculty = _faculty;
- post = _post;
- experience = _experience;
- }
- public override void Print ()
- {
- Console.Write("{0}, {1}, {2}, {3}, {4}, ",name, DOB, faculty, post, experience);
- }
- public override int Age()
- {
- string time = DateTime.Now.ToShortDateString();
- int day1 = int.Parse(DOB.Substring(0, 2));
- int month1 = int.Parse(DOB.Substring(3, 2));
- int year1 = int.Parse(DOB.Substring(6));
- int day2 = int.Parse(time.Substring(0, 2));
- int month2 = int.Parse(time.Substring(3, 2));
- int year2 = int.Parse(time.Substring(6));
- if (month1 < month2) return year2 - year1;
- else if (month1 == month2)
- {
- if (day1 <= day2)
- return year2 - year1;
- else return year2 - year1 - 1;
- }
- else return year2 - year1 - 1;
- }
- }
- class Program
- {
- static void Print(List<Person> list)
- {
- foreach (Person item in list)
- {
- item.Print();
- Console.WriteLine("{0}", item.Age());
- }
- }
- static List<Person> Read()
- {
- using (StreamReader fin = new StreamReader("D:/input.txt"))
- {
- int n = int.Parse(fin.ReadLine());
- List<Person> list = new List<Person>();
- for (int i = 0; i < n; i++)
- {
- string[] text = fin.ReadLine().Split(' ');
- if (text.Length == 3)
- list.Add(new Enrollee(text[0], text[1], text[2]));
- else if (text.Length == 4)
- list.Add(new Student(text[0], text[1], text[2], int.Parse(text[3])));
- else if (text.Length == 5)
- list.Add(new Teacher(text[0], text[1], text[2], text[3], int.Parse(text[4])));
- else Console.WriteLine("В {0}-ой строчке ошибка в данных", i+1);
- }
- return list;
- }
- }
- static void Search(List<Person> list)
- {
- Console.WriteLine("Enter range og the age a: ");
- int a = int.Parse(Console.ReadLine());
- Console.WriteLine("b: ");
- int b = int.Parse(Console.ReadLine());
- foreach (Person item in list)
- {
- if ((item.Age() >= a) && (item.Age() <= b))
- {
- item.Print();
- Console.WriteLine(item.Age());
- }
- }
- }
- static void Main(string[] args)
- {
- List<Person> list = Read();
- Print(list);
- Search(list);
- Console.WriteLine();
- list.Sort();
- Print(list);
- }
- 10
- Akunin 15.12.1996 Biofac 4
- Fedorov 21.12.2001 Himfac
- Chernov 30.04.1947 Fisfac 3
- Gorina 26.01.1982 IFIG assistent 5
- Kuzmina 15.03.1973 KNIIT
- Leshin 01.09.1976 NLP dotzent 12
- Kudrin 03.11.1994 Fisfac
- Rodnin 30.11.1973 Himfac
- Voevodina 01.12.1969 KNIIT prepodavatel' 23
- Burkina 29.11.1996 KNIIT 1
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement