fork download
  1. /*Создайте класс Date, который будет содержать информацию
  2. о дате (день, месяц, год). С помощью механизма перегрузки
  3. операторов, определите операцию разности двух дат (результат
  4. в виде количества дней между датами), а также операцию
  5. увеличения даты на определенное количество дней. */
  6.  
  7. #include <iostream>
  8. #include <string.h>
  9. #include <Windows.h>
  10.  
  11. using namespace std;
  12.  
  13. class Cdate
  14. {
  15. public:
  16. //---------ввод/вывод данных-------------------------
  17. Cdate(){}//конструктор по умолчанию
  18.  
  19. Cdate (int a,int b,int c)//конструктор
  20. {
  21. day=a; month=b; year=c;
  22. }
  23.  
  24.  
  25.  
  26. void print()//печать
  27. {
  28. cout<<day<<"."<<month<<"."<<year<<endl;
  29. }
  30. //--------------перегрузка минуса--------------------------
  31. Cdate operator- (const Cdate &end)
  32. {
  33. int mas[]={31,28,31,30,31,30,31,31,30,31,30,31};
  34. if (year%4==0)
  35. mas[1]=29;
  36. res = mas[month-1]-day+end.day;
  37. return res;
  38. }
  39.  
  40. Cdate (int res){}//конструктор для переопределения res к Cdate
  41.  
  42. //--------------перегрузка плюса----------------------------
  43. Cdate operator+ (const Cdate &end)
  44. {
  45. int tmp=0;
  46. int mas[]={31,28,31,30,31,30,31,31,30,31,30,31};
  47.  
  48. for (int counter = month-1, j=year; (counter!=end.month-1||j!=end.year) &&
  49. (counter+1!=end.month-1||year!=end.year) ; counter++)
  50. {
  51.  
  52. if (counter>=11)
  53. {
  54. if (j>year)
  55. {
  56. tmp+=mas[counter];
  57. }
  58. counter=0;
  59. j++;
  60. }
  61.  
  62. if (((j%4==0) && !(j%100==0))||(j%400==0))
  63. mas[1]=29;
  64. else
  65. mas[1]=28;
  66.  
  67.  
  68. tmp+=mas[counter+1];
  69.  
  70. }
  71. cout<<res+tmp<<endl<<endl;
  72. return res;
  73. }
  74. //----------------------------------------------------------
  75.  
  76.  
  77. operator int ()
  78. {
  79. return res;
  80. }
  81.  
  82. private:
  83. int day;
  84. int month;
  85. int year;
  86. int res;
  87. }D;
  88.  
  89.  
  90.  
  91. void main()
  92. {
  93. SetConsoleCP(1251);
  94. SetConsoleOutputCP(1251);
  95.  
  96. while(true)
  97. {
  98.  
  99.  
  100. Cdate start (15, 12, 2012);
  101. Cdate end (13, 5, 2014);
  102.  
  103. cout<< "начальная дата: ";
  104. start.print();//показ начальной даты
  105. cout<< "конечная дата: ";
  106. end.print();//показ конечной даты
  107. int result = start-end;
  108. cout<<"дней между датами: ";
  109. result = start+end;
  110.  
  111. //D.Plus(start, end, mas);
  112.  
  113.  
  114.  
  115. system("pause");
  116. system("cls");
  117. }
  118. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp:9:21: error: Windows.h: No such file or directory
prog.cpp:91: error: ‘::main’ must return ‘int’
prog.cpp: In function ‘int main()’:
prog.cpp:93: error: ‘SetConsoleCP’ was not declared in this scope
prog.cpp:94: error: ‘SetConsoleOutputCP’ was not declared in this scope
prog.cpp:115: error: ‘system’ was not declared in this scope
stdout
Standard output is empty