Advertisement
Guest User

Untitled

a guest
May 5th, 2016
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.61 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace _32._2._1
  8. {
  9. class Date
  10. {
  11. public int d, m, y;
  12.  
  13. public void setDate()
  14. {
  15. try
  16. {
  17. Console.WriteLine("Введите дату: ");
  18. d = int.Parse(Console.ReadLine());
  19. m = int.Parse(Console.ReadLine());
  20. y = int.Parse(Console.ReadLine());
  21.  
  22. if (d > 30 || d < 0 || m > 12 || m < 0)
  23. {
  24. throw new Exception();
  25. }
  26. }
  27. catch
  28. {
  29. Console.WriteLine("Ошибка ввода");
  30. }
  31. }
  32. public void getDate()
  33. {
  34. Console.WriteLine("Дата: {0} / {1} / {2}", d, m, y);
  35. }
  36. public void changeDate()
  37. {
  38. Console.Write("Измение \n1) Числа\n2) Месяца\n3) Года\n-> ");
  39. int p = int.Parse(Console.ReadLine());
  40. Console.Write("Введите изменение: ");
  41. int k = int.Parse(Console.ReadLine());
  42.  
  43. try
  44. {
  45. switch (p)
  46. {
  47. case 1:
  48. d += k;
  49. if (d > 30 || d < 0)
  50. {
  51. throw new Exception();
  52. }
  53. break;
  54. case 2:
  55. m += k;
  56. if (m > 12 || m < 0)
  57. {
  58. throw new Exception();
  59. }
  60. break;
  61. case 3:
  62. y += k;
  63. break;
  64. default:
  65. Console.WriteLine("Ошибка ввода");
  66. break;
  67. }
  68. }
  69. catch
  70. {
  71. Console.WriteLine("Ошибка ввода");
  72. }
  73. }
  74. }
  75.  
  76. class Program
  77. {
  78. static void Main(string[] args)
  79. {
  80. Date date = new Date();
  81.  
  82. date.setDate();
  83. date.getDate();
  84. date.changeDate();
  85. date.getDate();
  86.  
  87. Console.ReadKey();
  88. }
  89. }
  90. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement