using System; using System.Collections.Generic; using System.Text; namespace class_topolja { class person { public string surname; //поле фамилия public string status; //поле статус int age; //поле возраст double salary; //поле зарплата public string isNameLong; //поле длина имени string name; //поле име public person() { } //пустой конструктор public string condition; //поле условие public string Surname //свойство фамилия { set { if (surname == null) surname = value; } //если фамилия не указана, ставим значение фамилии get { return surname; } //возвращаем фамилию } public string Name //свойство имя { set //устанавливаем статус пользователя на основе полученных данных { name = value; if (name.Length < 5) { isNameLong = "short"; } else if (name.Length < 10) { isNameLong = "medium"; } else { isNameLong = "long"; } } get { return name; } //возвращаем имя } public person(string Name, string Surname) //совмещаем данные { surname = Surname; name = Name; } public string IsNameLong { get { return isNameLong; } } //получаем длину имени public double Salary //свойство зарплаты { set //устанавливаем уровень жизни пользователя на основе полученных данных { salary = value; if (salary<500) { condition = "poor"; } else if (salary<1500) { condition = "wealthy"; } else { condition = "rich"; } } } public string Condition { get { return condition; } } //получаем public int Age //свойства возроста { get { return age; } //возвращаем возраст set { } //получем возраст } public string Status { //свойства статуса get//устанавливаем статус пользователя на основе полученных данных { if (age < 7) { status = "kid"; } else if (age < 17) { status = "teen"; } else if (age < 24) { status = "young"; } else { status = "adult"; } return status; //возвращаем статус } } public person(string Surname, language Language)//получаем данные о языке { surname = Surname; //this.surname = surname; } public void Greeting()//метод приветствия { if (surname=="" && age == 0) { Console.WriteLine("Hello!"); } else if (age.ToString()=="") { Console.WriteLine($"My śurname is: {surname}"); } else if (surname=="") { Console.WriteLine($"My age is: {age}"); } else { Console.WriteLine($"My śurname is: {surname}"); Console.WriteLine($"My age is: {age}"); } Console.WriteLine($"My status is {Status}"); //Console.WriteLine($"My name is {isNameLong}"); //Console.WriteLine($"I'm {condition}"); } } }
using System; namespace class_topolja { class Program { static void Main(string[] args) { //person woman = new person("Efirova"); //woman.Age = int.Parse(Console.ReadLine()); //woman.Greeting(); person man = new person(); man.Surname = "Efirov"; man.Age = 45; Console.WriteLine($"{man.Surname} is {man.Age}"); man.Greeting(); person[] people = new person[1]; for (int i = 0; i < 1; i++) { people[i] = new person(); Console.WriteLine("What's your surname?"); people[i].Surname = Console.ReadLine(); Console.WriteLine("Your age?"); try { people[i].Age = int.Parse(Console.ReadLine()); } catch (Exception) { } Console.WriteLine("Your name?"); people[i].Name = Console.ReadLine(); Console.WriteLine("Your salary?"); people[i].Salary = double.Parse(Console.ReadLine()); } foreach (var person in people) { person.Greeting(); } Console.ReadKey(); } } }