Exemple #1
0
        static void Main(string[] args)
        {
            string s, n, p;
            int d, m, y;

            Console.WriteLine("Введите фамилию");
            s = Console.ReadLine();
            Console.WriteLine("Введите имя");
            n = Console.ReadLine();
            Console.WriteLine("Введите отчество");
            p = Console.ReadLine();
            Console.WriteLine("Введите дату рождения:");
            Console.Write("День:");
            d = Convert.ToInt32(Console.ReadLine());
            Console.Write("Месяц:");
            m = Convert.ToInt32(Console.ReadLine());
            Console.Write("Год:");
            y = Convert.ToInt32(Console.ReadLine());
            Console.WriteLine();
            User U = new User(s, n, p, d, m, y);
            U.Print();

            Console.Write("\nНажмите любую клавишу для закрытия программы.");
            Console.ReadKey();
        }
Exemple #2
0
        static void Main(string[] args)
        {
            Console.WriteLine("Задание №3{0}Данная программа создает пользователя{1}Пожалуйста, задайте параметры пользователя!", Environment.NewLine, Environment.NewLine);

            Console.Write("Имя пользователя: ");
            string name = Console.ReadLine();
            Console.Write("Отчество пользователя: ");
            string fatherName = Console.ReadLine();
            Console.Write("Фамилия пользователя: ");
            string surName = Console.ReadLine();

            Console.Write("Введите дату рождения пользователя в формате (dd/mm/yyyy): ");
            DateTime birthDay;
            if (!DateTime.TryParse(Console.ReadLine(), out birthDay) || birthDay>DateTime.Now)
            {
                Console.WriteLine("Некорректная дата рождения\nПользователь не создан");
            }
            else
            {
                User user = new User(surName, name, fatherName, birthDay);
                Console.WriteLine("{0}Имя: {1}", Environment.NewLine, user.Name);
                Console.WriteLine("Отчество: {0}", user.FatherName);
                Console.WriteLine("Фамилия: {0}", user.Surname);
                Console.WriteLine("Возраст - {0}", user.Age);
            }

            Console.WriteLine("{0}Для выхода нажмите клавишу Enter...", Environment.NewLine);
            Console.ReadLine();
        }
        static void Main(string[] args)
        {
            User person; //пользователь

            //переменные для считывания значений
            string surname, name, middlename;
            int day, month, year;

            //ввод значений
            Console.WriteLine("Введите пользователя:");
            Console.Write("  Введите фамилию: ");
            surname = Console.ReadLine();
            Console.Write("  Введите имя: ");
            name = Console.ReadLine();
            Console.Write("  Введите отчество: ");
            middlename = Console.ReadLine();

            Console.WriteLine("  Введите дату рождения:");
            Console.Write("    Год: ");
            while (int.TryParse(Console.ReadLine(), out year) == false || year > DateTime.Now.Year || year < 1900)
                Console.Write("    Неверный ввод. Введите целое число в диапазоне от 1900 до {0}: ", DateTime.Now.Year);

            Console.Write("    Месяц: ");
            if (year == DateTime.Now.Year)
                while (int.TryParse(Console.ReadLine(), out month) == false || month > DateTime.Now.Month)
                    Console.Write("    Неверный ввод. Введите целое число в диапазоне от 1 до {0}: ", DateTime.Now.Month);
            else
                while (int.TryParse(Console.ReadLine(), out month) == false || month > 12)
                    Console.Write("    Неверный ввод. Введите целое число в диапазоне от 1 до 12: ");

            Console.Write("    День: ");
            if (month == 2)
            {
                if (year % 4 == 0 && year % 100 != 0 || year % 400 == 0)
                    while (int.TryParse(Console.ReadLine(), out day) == false || day > 29)
                        Console.Write("    Неверный ввод. Введите целое число в диапазоне от 1 до 29: ");
                else
                    while (int.TryParse(Console.ReadLine(), out day) == false || day > 28)
                        Console.Write("    Неверный ввод. Введите целое число в диапазоне от 1 до 28: ");
            }
            else
            {
                if (month == 4 || month == 6 || month == 9 || month == 11)
                    while (int.TryParse(Console.ReadLine(), out day) == false || day > 30)
                        Console.Write("    Неверный ввод. Введите целое число в диапазоне от 1 до 30: ");
                else
                    while (int.TryParse(Console.ReadLine(), out day) == false || day > 31)
                        Console.Write("    Неверный ввод. Введите целое число в диапазоне от 1 до 31: ");
            }

            //создание пользователя
            person = new User(surname, name, middlename, new DateTime(year, month, day));

            //вывод на консоль
            Console.WriteLine(person);
            Console.ReadKey();
        }
Exemple #4
0
 private static void WriteUser(User u)
 {
     DateTime a = new DateTime(0001, 01, 01);
     Console.WriteLine("Имя:{0}", u.firstname);
     Console.WriteLine("Фамилия:{0}", u.secondname);
     Console.WriteLine("Отчество:{0}", u.patron);
     if (u.birthday.Equals(a)) Console.WriteLine("Дата рождения не введена");
     else Console.WriteLine("Дата рождения: {0}", u.birthday.ToString("d"));
     Console.WriteLine("Возраст: {0}", u.age);
     Console.WriteLine();
 }
Exemple #5
0
 static void Main(string[] args)
 {
     User u1 = new User();
     User u2 = new User();
     User u3 = new User();
     Console.WriteLine("Введите трех пользователей");
     Console.WriteLine("Первый пользователь:");
     ReadUser(ref u1);
     Console.WriteLine("Второй пользователь:");
     ReadUser(ref u2);
     Console.WriteLine("Третий пользователь:");
     ReadUser(ref u3);
     Console.WriteLine();
     WriteUser(u1);
     WriteUser(u2);
     WriteUser(u3);
     Console.ReadKey();
 }
Exemple #6
0
        private static void ReadUser(ref User u)
        {
            string _readString;
            DateTime birthday;
            int age;

            Console.WriteLine("Имя:");
            _readString = Console.ReadLine();
            if (string.IsNullOrWhiteSpace(_readString)) { u.firstname = "FirstNameIsNull"; Console.WriteLine("Вы ничего не ввели"); }
            else u.firstname = _readString;

            Console.WriteLine("Фамилия:");
            _readString = Console.ReadLine();
            if (string.IsNullOrWhiteSpace(_readString)) { u.secondname = "SecondNameIsNull"; Console.WriteLine("Вы ничего не ввели"); }
            else u.secondname = _readString;

            Console.WriteLine("Отчество:");
            _readString = Console.ReadLine();
            if (string.IsNullOrWhiteSpace(_readString)) { u.patron = "PatronNameIsNull";  Console.WriteLine("Вы ничего не ввели"); }
            else u.patron = _readString;

            Console.WriteLine("Дата рождения в формате ГГГГ.ММ.ДД");
            if (DateTime.TryParse(Console.ReadLine(), out birthday)) u.birthday = birthday;
            else
            {
                Console.WriteLine("Вы неверно ввели дату рождения");
            }

            Console.WriteLine("Введите возраст");
            _readString = Console.ReadLine();
            if (int.TryParse(_readString, out age)) u.age = age;
            else
            {
                u.age = 0;
                Console.WriteLine("Введено неверне значение");
            }

            Console.WriteLine();
        }
Exemple #7
0
 static void Main(string[] args)
 {
     User user1 = new User("User1","John","Volyk",22,"20.08.15");
     user1.ShowUserInfo();
 }
Exemple #8
0
        static void Main(string[] args)
        {
            var user1 = new User();
            Console.WriteLine("Введите Имя:");
            user1.setName(Console.ReadLine());

            Console.WriteLine("Введите Фамилию:");
            user1.setSurname(Console.ReadLine());

            Console.WriteLine("Введите Отчество:");
            user1.setSecondName(Console.ReadLine());

            Console.WriteLine("Введите Возраст:");
            user1.setAge(int.Parse(Console.ReadLine()));

            Console.WriteLine("Введите Дату рождения:");
            user1.setBirthday(Console.ReadLine());

            user1.Print();
            
            Console.WriteLine("Изменить: ");
            do
            {
                int num;
                Console.WriteLine("1. Имя.");
                Console.WriteLine("2. Фамилию.");
                Console.WriteLine("3. Отчество.");
                Console.WriteLine("4. Возраст.");
                Console.WriteLine("5. Дату рождения.");
                num = int.Parse(Console.ReadLine());
                switch (num)
                {
                    case 1:
                        Console.WriteLine("Введите имя:");
                        user1.setName(Console.ReadLine());
                        user1.Print();
                        break;
                    case 2:
                        Console.WriteLine("Введите Фамилию:");
                        user1.setSurname(Console.ReadLine());
                        user1.Print();
                        break;
                    case 3:
                        Console.WriteLine("Введите Отчество:");
                        user1.setSecondName(Console.ReadLine());
                        user1.Print();
                        break;
                    case 4:
                        Console.WriteLine("Введите Возраст:");
                        user1.setAge(int.Parse(Console.ReadLine()));
                        user1.Print();
                        break;
                    case 5:
                        Console.WriteLine("Введите Дату рождения:");
                        user1.setBirthday(Console.ReadLine());
                        user1.Print();
                        break;
                } 
            } while (true);

        }