fork download
  1.  
  2. #include <iostream>
  3. #include <iomanip>
  4. class Time {
  5. private:
  6. int hours;
  7. int minutes;
  8. public:
  9. Time() : hours(0), minutes(0) {}
  10. void setTime(int h, int m) {
  11. if (h >= 0 && h < 24 && m >= 0 && m < 60) {
  12. hours = h;
  13. minutes = m;
  14. }
  15. else {
  16. std::cout << "taxminiy vaqt:" << std::endl;
  17. }
  18. }
  19. void addMinutes(int m) {
  20. if (m < 0) {
  21. std::cout << "qo'shiladigan vaqt minutlarda:" << std::endl;
  22. return;
  23. }
  24. minutes += m;
  25. hours += minutes / 60;
  26. minutes %= 60;
  27. hours %= 24;
  28. }
  29. void getTime() const {
  30. std::cout << "hozirgi vaqt: " << std::setw(2) << std::setfill('0') << hours << ":"
  31. << std::setw(2) << std::setfill('0') << minutes <<std::endl;
  32. }
  33. };
  34. int main() {
  35. Time time;
  36. time.setTime(19,35);
  37. time.getTime();
  38. time.addMinutes(120);
  39. time.getTime();
  40. return 0;
  41. }
  42.  
Success #stdin #stdout 0.01s 5280KB
stdin
 
stdout
hozirgi vaqt: 19:35
hozirgi vaqt: 21:35