Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace _32._2._1
- {
- class Date
- {
- public int d, m, y;
- public void setDate()
- {
- try
- {
- Console.WriteLine("Введите дату: ");
- d = int.Parse(Console.ReadLine());
- m = int.Parse(Console.ReadLine());
- y = int.Parse(Console.ReadLine());
- if (d > 30 || d < 0 || m > 12 || m < 0)
- {
- throw new Exception();
- }
- }
- catch
- {
- Console.WriteLine("Ошибка ввода");
- }
- }
- public void getDate()
- {
- Console.WriteLine("Дата: {0} / {1} / {2}", d, m, y);
- }
- public void changeDate()
- {
- Console.Write("Измение \n1) Числа\n2) Месяца\n3) Года\n-> ");
- int p = int.Parse(Console.ReadLine());
- Console.Write("Введите изменение: ");
- int k = int.Parse(Console.ReadLine());
- try
- {
- switch (p)
- {
- case 1:
- d += k;
- if (d > 30 || d < 0)
- {
- throw new Exception();
- }
- break;
- case 2:
- m += k;
- if (m > 12 || m < 0)
- {
- throw new Exception();
- }
- break;
- case 3:
- y += k;
- break;
- default:
- Console.WriteLine("Ошибка ввода");
- break;
- }
- }
- catch
- {
- Console.WriteLine("Ошибка ввода");
- }
- }
- }
- class Program
- {
- static void Main(string[] args)
- {
- Date date = new Date();
- date.setDate();
- date.getDate();
- date.changeDate();
- date.getDate();
- Console.ReadKey();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement