fork(3) download
  1. #include <iostream>
  2. #include <string>
  3.  
  4. using namespace std;
  5.  
  6. class time
  7. {
  8. public:
  9. time(){}
  10. int hour;
  11. int minute;
  12. };
  13.  
  14. ostream & operator<<(ostream &out, time &a)
  15. {
  16. if (a.hour <= 9)
  17. out << 0 << a.hour << ":";
  18. else
  19. out << a.hour << ":";
  20. if (a.minute <= 9)
  21. out << 0 << a.minute;
  22. else
  23. out << a.minute;
  24. return out;
  25. }
  26.  
  27. istream & operator>>(istream &in, time &a)
  28. {
  29. string x;
  30. in >> x;
  31.  
  32. if (x[0] == 0)
  33. a.hour = x[1] - 48;
  34. else
  35. a.hour = (x[0] - 48) * 10 + x[1] - 48;
  36.  
  37. if (x[3] == 0)
  38. a.minute = x[4] - 48;
  39. else
  40. a.minute = (x[3] - 48) * 10 + x[4] - 48;
  41.  
  42. return in;
  43. }
  44.  
  45. time operator+(time t1, time t2)
  46. {
  47. time t3;
  48. t3.hour = t1.hour + t2.hour;
  49. if (t3.hour >= 24)
  50. t3.hour -= 24;
  51. t3.minute = t1.minute + t2.minute;
  52. while (t3.minute >= 60)
  53. {
  54. t3.hour++;
  55. t3.minute -= 60;
  56. }
  57.  
  58. return t3;
  59. }
  60.  
  61. time operator+(time t1, int b)
  62. {
  63. t1.minute += b;
  64.  
  65. while (t1.minute >= 60)
  66. {
  67. t1.hour++;
  68. t1.minute -= 60;
  69. }
  70.  
  71. while (t1.hour >= 24)
  72. {
  73. t1.hour -= 24;
  74. }
  75.  
  76. return t1;
  77. }
  78.  
  79. int main()
  80. {
  81. time t; cin >> t;
  82. cout << t << ",";
  83. int a;
  84.  
  85. while (cin >> a)
  86. {
  87. t = t + a;
  88. cout << t << ",";
  89. }
  90.  
  91. return 0;
  92. }
  93.  
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
08:00
15
15
15
compilation info
prog.cpp:14: error: 'time' is not a type
prog.cpp: In function 'std::ostream& operator<<(std::ostream&, int&)':
prog.cpp:16: error: request for member 'hour' in 'a', which is of non-class type 'int'
prog.cpp:17: error: request for member 'hour' in 'a', which is of non-class type 'int'
prog.cpp:19: error: request for member 'hour' in 'a', which is of non-class type 'int'
prog.cpp:20: error: request for member 'minute' in 'a', which is of non-class type 'int'
prog.cpp:21: error: request for member 'minute' in 'a', which is of non-class type 'int'
prog.cpp:23: error: request for member 'minute' in 'a', which is of non-class type 'int'
prog.cpp: At global scope:
prog.cpp:27: error: 'time' is not a type
prog.cpp: In function 'std::istream& operator>>(std::istream&, int&)':
prog.cpp:33: error: request for member 'hour' in 'a', which is of non-class type 'int'
prog.cpp:35: error: request for member 'hour' in 'a', which is of non-class type 'int'
prog.cpp:38: error: request for member 'minute' in 'a', which is of non-class type 'int'
prog.cpp:40: error: request for member 'minute' in 'a', which is of non-class type 'int'
prog.cpp: At global scope:
prog.cpp:45: error: expected constructor, destructor, or type conversion before 'operator'
stdout
Standard output is empty