Untitled
unknown
plain_text
2 years ago
2.5 kB
4
Indexable
using System; namespace StudentClass { class Student { public string FirstName { get; set; } public string LastName { get; set; } public string PersonalId { get; set; } public string Address { get; set; } public string ClassName { get; set; } public void InputData() { Console.Write("Въведете име: "); FirstName = Console.ReadLine(); Console.Write("Въведете фамилия: "); LastName = Console.ReadLine(); Console.Write("Въведете ЕГН: "); PersonalId = Console.ReadLine(); Console.Write("Въведете адрес: "); Address = Console.ReadLine(); Console.Write("Въведете паралелка: "); ClassName = Console.ReadLine(); } public void DisplayData() { Console.WriteLine("Име: " + FirstName); Console.WriteLine("Фамилия: " + LastName); Console.WriteLine("ЕГН: " + PersonalId); Console.WriteLine("Адрес: " + Address); Console.WriteLine("Паралелка: " + ClassName); } public int GetAge() { // Извличане на годината от първите две цифри на ЕГН-то int year = int.Parse(PersonalId.Substring(0, 2)); // Проверка за века и добавяне на съответните години int currentCentury = DateTime.Now.Year / 100; if (year <= (currentCentury - 1) % 100) { year += currentCentury * 100; } else { year += (currentCentury - 1) * 100; } // Връщане на текущата възраст int currentYear = DateTime.Now.Year; int age = currentYear - year; return age; } } class Program { static void Main(string[] args) { Student student = new Student(); student.InputData(); Console.WriteLine("\n--- Данни на ученика ---"); student.DisplayData(); int age = student.GetAge(); Console.WriteLine("\nТекуща възраст на ученика: " + age + " години"); } } }
Editor is loading...