fork download
  1. //#include "stdafx.h"
  2. #include <iostream>
  3. #include <assert.h>
  4. using namespace std;
  5. class calendar {
  6. private:
  7. int year;
  8. int month;
  9. int day;
  10. public:
  11. calendar(int = 0, int = 0, int = 0);
  12. ~calendar();
  13. calendar operator += (calendar & );
  14. calendar operator -= (calendar & );
  15. calendar operator = (calendar & );
  16. calendar operator != (calendar & );
  17. calendar operator > (calendar & );
  18. calendar operator < (calendar & );
  19. calendar operator >= (calendar & );
  20. calendar operator <= (calendar & );
  21. calendar operator == (calendar & );
  22. friend istream & operator >> (istream & , calendar & );
  23. friend ostream & operator << (ostream & , calendar & );
  24. };
  25. calendar::calendar(int y, int m, int d) {
  26. year = y;
  27. month = m;
  28. day = d;
  29. }
  30. calendar calendar::operator = (calendar & y) {
  31. return (year = y.year,
  32. month = y.month,
  33. day = y.day);
  34. }
  35. calendar calendar::operator += (calendar & y) {
  36. year = y.year + year;
  37. month = y.month + month;
  38. if (month > 12) {
  39. year++;
  40. month = month - 12;
  41. }
  42. day =
  43. y.day +
  44. day;
  45. if (month == 1 || month == 3 || month == 5 || month == 7 || month == 9 ||
  46. month == 11) {
  47. if (day > 31) {
  48. month++;
  49. day = day - 31;
  50. }
  51. }
  52. if (
  53. month == 4 || month == 6 || month == 8 || month == 10 || month == 12) {
  54. if (day > 30) {
  55. month++;
  56. day = day - 30;
  57. }
  58. }
  59. if (
  60. month == 2) {
  61. if (day > 28) {
  62. month++;
  63. day = day - 28;
  64. }
  65. }
  66. return calendar(year, month, day);
  67. }
  68. calendar calendar::operator -= (calendar & y) {
  69. year = y.year - year;
  70. month = y.month - month;
  71. if (month < 1) {
  72. year--;
  73. month = month + 12;
  74. }
  75. day =
  76. y.day -
  77. day;
  78. if (month == 1 || month == 5 || month == 7 || month == 9 || month == 11) {
  79. if (day < 1) {
  80. month--;
  81. day = day + 30;
  82. }
  83. }
  84. if (
  85. month == 2 || month == 4 || month == 6 || month == 8 || month == 10 ||
  86. month == 12) {
  87. if (day < 1) {
  88. month--;
  89. day = day + 31;
  90. }
  91. }
  92. if (
  93. month == 3) {
  94. if (day < 1) {
  95. month--;
  96. day = day + 28;
  97. }
  98. }
  99. return calendar(year, month, day);
  100. }
  101. calendar calendar::operator != (calendar & y) {
  102. if (year != y.year) {
  103. cout << "rizni daty " << endl;
  104. } else {
  105. if (month != y.month) {
  106. cout << "rizni daty " << endl;
  107. } else {
  108. if (day != y.day) {
  109. cout << "rizni daty " << endl;
  110. } else {
  111. cout << "Error. Odnakovi daty" << endl;
  112. }
  113. }
  114. }
  115. return calendar(year, month, day);
  116. }
  117. calendar calendar::operator == (calendar & y) {
  118. if (year != y.year) {
  119. cout << "Error. Rizni daty " << endl;
  120. } else {
  121. if (month != y.month) {
  122. cout << "Error. Rizni daty " << endl;
  123. } else {
  124. if (day != y.day) {
  125. cout << "Error. Rizni daty " << endl;
  126. } else {
  127. cout << "Odnakovi daty" << endl;
  128. }
  129. }
  130. }
  131. return calendar(year, month, day);
  132. }
  133. calendar calendar::operator < (calendar & y) {
  134. if (year > y.year) {
  135. cout << "Error. First date is 'bigger' " << endl;
  136. }
  137. if (
  138. year < y.year) {
  139. cout << "First date is lower" << endl;
  140. }
  141. if (
  142. year == y.year) {
  143. if (month > y.month) {
  144. cout << "Error. First date is 'bigger' " << endl;
  145. }
  146. if (
  147. month < y.month) {
  148. cout << "First date is lower" << endl;
  149. }
  150. if (
  151. month == y.month) {
  152. if (day > y.day) {
  153. cout << "Error. First date is 'bigger' " << endl;
  154. }
  155. if (
  156. day < y.day) {
  157. cout << "First date is lower" << endl;
  158. }
  159. if (
  160. day == y.day) {
  161. cout << "Error. Odnakovi daty" << endl;
  162. }
  163. }
  164. }
  165. return calendar(year, month, day);
  166. }
  167. calendar calendar::operator > (calendar & y) {
  168. if (year > y.year) {
  169. cout << "First date is 'bigger' " << endl;
  170. }
  171. if (
  172. year < y.year) {
  173. cout << "Error.First date is lower" << endl;
  174. }
  175. if (
  176. year == y.year) {
  177. if (month > y.month) {
  178. cout << "First date is 'bigger' " << endl;
  179. }
  180. if (
  181. month < y.month) {
  182. cout << "Error. First date is lower" << endl;
  183. }
  184. if (
  185. month == y.month) {
  186. if (day > y.day) {
  187. cout << "First date is 'bigger' " << endl;
  188. }
  189. if (
  190. day < y.day) {
  191. cout << "Error. First date is lower" << endl;
  192. }
  193. if (
  194. day == y.day) {
  195. cout << "Error. Odnakovi daty" << endl;
  196. }
  197. }
  198. }
  199. return calendar(year, month, day);
  200. }
  201. calendar calendar::operator <= (calendar & y) {
  202. if (year > y.year) {
  203. cout << "Error. First date is 'bigger' " << endl;
  204. }
  205. if (
  206. year < y.year) {
  207. cout << "First date is lower" << endl;
  208. }
  209. if (
  210. year == y.year) {
  211. if (month > y.month) {
  212. cout << "Error. First date is 'bigger' " << endl;
  213. }
  214. if (
  215. month < y.month) {
  216. cout << "First date is lower" << endl;
  217. }
  218. if (
  219. month == y.month) {
  220. if (day > y.day) {
  221. cout << "Error. First date is 'bigger' " << endl;
  222. }
  223. if (
  224. day < y.day) {
  225. cout << "First date is lower" << endl;
  226. }
  227. if (
  228. day == y.day) {
  229. cout << "Odnakovi daty" << endl;
  230. }
  231. }
  232. }
  233. return calendar(year, month, day);
  234. }
  235. calendar calendar::operator >= (calendar & y) {
  236. if (year > y.year) {
  237. cout << "First date is 'bigger' " << endl;
  238. }
  239. if (
  240. year < y.year) {
  241. cout << "Error.First date is lower" << endl;
  242. }
  243. if (
  244. year == y.year) {
  245. if (month > y.month) {
  246. cout << "First date is 'bigger' " << endl;
  247. }
  248. if (
  249. month < y.month) {
  250. cout << "Error. First date is lower" << endl;
  251. }
  252. if (
  253. month == y.month) {
  254. if (day > y.day) {
  255. cout << "First date is 'bigger' " << endl;
  256. }
  257. if (
  258. day < y.day) {
  259. cout << "Error. First date is lower" << endl;
  260. }
  261. if (
  262. day == y.day) {
  263. cout << "Odnakovi daty" << endl;
  264. }
  265. }
  266. }
  267. return calendar(year, month, day);
  268. }
  269. istream & operator >> (istream & is, calendar & x) {
  270. char c;
  271. cout << "vveditj datu:" << endl;
  272. cin >> x.year;
  273. cin >> c;
  274. assert(c == '.');
  275. cin >> x.month;
  276. cin >> c;
  277. assert(c == '.');
  278. cin >> x.day;
  279. return is;
  280. }
  281. ostream & operator << (ostream & os, calendar & x) {
  282. cout << "date:" << endl;
  283. os << x.year << '.' << x.month << '.' << x.day << endl;
  284. return os;
  285. }
  286. calendar::~calendar() {}
  287. int main(int argc, char * * argv) {
  288. calendar a(1999, 12, 9);
  289. calendar b(2000, 6, 20);
  290. cin >> b;
  291. cout << b << endl;
  292. a += b;
  293. cout << "addition " << a << endl;
  294. a > b;
  295. return 0;
  296. }
Success #stdin #stdout 0s 4324KB
stdin
1998.8.11
stdout
vveditj datu:
date:
1998.8.11

addition date:
3998.8.20

First date is 'bigger'