anon

CSharp · Console

/Program.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace KR2
{
	public enum Form
	{
		OOO,
		ZAO,
		OAO,
		Unknown
	}

	public class Person
	{
		private string _name;
		private string _surname;
		private DateTime _birth;
		public Person(string name, string surname, DateTime birth)
		{
			_name = name;
			_surname = surname;
			_birth = birth;
		}

		public Person(): this ("UnknownName", "UnknownSurname", DateTime.Now)
		{
		}

		public DateTime Bith
		{
			get
			{
				return _birth;
			}

			set
			{
				_birth = value;
			}
		}

		public string Name
		{
			get
			{
				return _name;
			}

			set
			{
				_name = value;
			}
		}

		public string Surname
		{
			get
			{
				return _surname;
			}

			set
			{
				_surname = value;
			}
		}

		public int Year
		{
			get
			{
				return _birth.Year;
			}

			set
			{
				_birth = new DateTime(value, _birth.Month, _birth.Day);
			}
		}

		public override string ToString()
		{
			return String.Format("Имя: {0}\nФамилия: {1}\nДата рождения: {2}", _name, _surname, _birth.ToShortDateString());
		}

		public virtual string ToShortString()
		{
			return String.Format("Имя: {0}\nФамилия: {1}", _name, _surname);
		}
	}

	public class Employee
	{
		public Person _pers;
		private string _position;
		private DateTime _work;
		public Employee(Person pers, string position, DateTime work)
		{
			_pers = pers;
			_position = position;
			_work = work;
		}

		public Employee(): this (default (Person), "UnknownPosition", DateTime.Now)
		{
		}

		public DateTime Work
		{
			get
			{
				return _work;
			}

			set
			{
				_work = value;
			}
		}

		public string Position
		{
			get
			{
				return _position;
			}

			set
			{
				_position = value;
			}
		}

		public int Year
		{
			get
			{
				return _work.Year;
			}

			set
			{
				_work = new DateTime(value, _work.Month, _work.Day);
			}
		}

		public Person EmpPers
		{
			get
			{
				return _pers;
			}

			set
			{
				_pers = value;
			}
		}

		public override string ToString()
		{
			return String.Format("Работник {0}\n\n Должность: {1}\n Дата принятия на работу: {2}", _pers, _position, _work);
		}

		public virtual string ToShortString()
		{
			return String.Format("Работник {0}\n\n Должность: {1}", _pers, _position);
		}
	}

	public class Organisation
	{
		private string _orgname;
		private int _regnum;
		private Form _form;
		private Employee[] _emp;
		public Organisation(string orgname, int regnum, Form form, Employee[] emp)
		{
			_orgname = orgname;
			_regnum = regnum;
			_form = form;
			_emp = emp;
		}

		public Organisation(): this ("UnknownOrgName", Convert.ToInt32("0"), Form.Unknown, default (Employee[]))
		{
		}

		public string OrgName
		{
			get
			{
				return _orgname;
			}

			set
			{
				_orgname = value;
			}
		}

		public int RegNum
		{
			get
			{
				return _regnum;
			}

			set
			{
				_regnum = value;
			}
		}

		public Form FormForm
		{
			get
			{
				return _form;
			}

			set
			{
				_form = value;
			}
		}

		public Employee[] Emp
		{
			get
			{
				return _emp;
			}

			set
			{
				_emp = value;
			}
		}

		//    public Person DatePer
		//   {
		//     get
		//   {
		//     return _dateper = Employee.Work(DateTime.MinValue);
		//  }
		//      public Form this[int index]
		//     public void AddEmployee(params Employee[] employees)
		public override string ToString()
		{
			return String.Format("Название организации: {0}\nРегистрационный номер: {1}\nПравовая форма: {2}\nРаботники: {3}", _orgname, _regnum, _form, _emp);
		}

		public virtual string ToShortString()
		{
			return String.Format("Название организации: {0}\nПравовая форма: {1}", _orgname, _form);
		}
	}

	class Program
	{
		static void Main(string[] args)
		{
			Person pers1 = new Person();
			Console.WriteLine("Экземпляр класса с полями, заполненными по умолчанию");
			Console.WriteLine(pers1.ToString());
			Console.WriteLine(pers1.ToShortString());
			Person pers2;
			Console.WriteLine();
			Console.WriteLine("Введите имя, фамилию, дату рождения через Enter");
			try
			{
				pers2 = new Person(Console.ReadLine(), Console.ReadLine(), DateTime.Parse(Console.ReadLine()));
			}
			catch (Exception ex)
			{
				Console.WriteLine("Возникла следующая ошибка: {0}", ex.Message);
				pers2 = new Person();
			}

			Console.WriteLine("\nРезультат заполнения:\n{0}", pers2.ToString());
			Employee emp1 = new Employee();
			emp1.EmpPers = pers2;
			emp1.Position = "Садовник";
			emp1.Work = DateTime.Parse("23.12.1234");
			Console.WriteLine(emp1.ToString());
			Console.WriteLine();
			Organisation org1 = new Organisation();
			Console.WriteLine("Экземпляр класса с полями, заполненными по умолчанию");
			Console.WriteLine(org1.ToString());
			Console.WriteLine(org1.ToShortString());
			Console.WriteLine();
			org1.OrgName = "Васильки";
			org1.RegNum = Convert.ToInt32("225695");
			org1.FormForm = Form.ZAO;
			Console.WriteLine("\nИзмененные свойства объекта org1:");
			Console.WriteLine(org1.ToString());
			Console.ReadKey();
		}
	}
}
;