fork(59) 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. if (month==end.month)
  37. res=end.day-day;
  38. else res = mas[month-1]-day+end.day;
  39. return res;
  40. }
  41.  
  42. Cdate (int res){}//конструктор для переопределения res к Cdate
  43.  
  44. //--------------перегрузка плюса----------------------------
  45. Cdate operator+ (const Cdate &end)
  46. {
  47. int tmp=0;
  48. int mas[]={31,28,31,30,31,30,31,31,30,31,30,31};
  49.  
  50. for (int counter = month-1, j=year; counter!=end.month-1||j!=end.year; counter++)
  51. {
  52.  
  53. if (counter>=11)
  54. {
  55. if (j>year)
  56. {
  57. tmp+=mas[counter];
  58. }
  59. counter=0;
  60. j++;
  61. }
  62.  
  63. if (counter==end.month-1&&j==end.year)
  64. break;
  65.  
  66. if (((j%4==0) && !(j%100==0))||(j%400==0))
  67. mas[1]=29;
  68. else
  69. mas[1]=28;
  70.  
  71.  
  72. tmp+=mas[counter];
  73.  
  74. }
  75. cout<<res+tmp<<endl<<endl;
  76. return res;
  77. }
  78. //----------------------------------------------------------
  79.  
  80.  
  81. operator int ()
  82. {
  83. return res;
  84. }
  85.  
  86. private:
  87. int day;
  88. int month;
  89. int year;
  90. int res;
  91. }D;
  92.  
  93.  
  94.  
  95. void main()
  96. {
  97. SetConsoleCP(1251);
  98. SetConsoleOutputCP(1251);
  99.  
  100. while(true)
  101. {
  102.  
  103.  
  104. Cdate start (19, 12, 2012);
  105. Cdate end (13, 1, 2014);
  106.  
  107. cout<< "начальная дата: ";
  108. start.print();//показ начальной даты
  109. cout<< "конечная дата: ";
  110. end.print();//показ конечной даты
  111. int result = start-end;
  112. cout<<"дней между датами: ";
  113. result = start+end;
  114.  
  115. //D.Plus(start, end, mas);
  116.  
  117.  
  118.  
  119. system("pause");
  120. system("cls");
  121. }
  122. }
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:95: error: ‘::main’ must return ‘int’
prog.cpp: In function ‘int main()’:
prog.cpp:97: error: ‘SetConsoleCP’ was not declared in this scope
prog.cpp:98: error: ‘SetConsoleOutputCP’ was not declared in this scope
prog.cpp:119: error: ‘system’ was not declared in this scope
stdout
Standard output is empty