Advertisement
Guest User

By Vlad K.

a guest
Jan 19th, 2017
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.75 KB | None | 0 0
  1. #include <iostream>
  2. #include <cstdlib>
  3.  
  4. using namespace std;
  5.  
  6. class Time {
  7. private:
  8.     int hours = 0, minutes = 0, seconds = 0;
  9.     int hours1 = 0, minutes1 = 0, seconds1 = 0;
  10.     int totalSec = 0;
  11. public:
  12.     void setHours(int data);
  13.     void setMinutes(int data);
  14.     void setSeconds(int data);
  15.     void setHours1(int data);
  16.     void setMinutes1(int data);
  17.     void setSeconds1(int data);
  18.  
  19.     void plusData(int hours, int minutes, int seconds, int hours1, int minutes1, int seconds1);
  20.     void minusData(int hours, int minutes, int seconds, int hours1, int minutes1, int seconds1);
  21.     void showResult ();
  22.  
  23.     Time(string data, string data1) {
  24.         char buf[3] = "";
  25.         buf[0] = data[0];
  26.         buf[1] = data[1];
  27.         setHours(atoi(buf));
  28.         buf[0] = data[3];
  29.         buf[1] = data[4];
  30.         setMinutes(atoi(buf));
  31.         buf[0] = data[6];
  32.         buf[1] = data[7];
  33.         setSeconds(atoi(buf));
  34.  
  35.         buf[0] = data1[0];
  36.         buf[1] = data1[1];
  37.         setHours1(atoi(buf));
  38.         buf[0] = data1[3];
  39.         buf[1] = data1[4];
  40.         setMinutes1(atoi(buf));
  41.         buf[0] = data1[6];
  42.         buf[1] = data1[7];
  43.         setSeconds1(atoi(buf));
  44.  
  45.         plusData(hours, minutes, seconds, hours1, minutes1, seconds1);
  46.     }
  47. };
  48.  
  49. void Time::setHours(int data) {
  50.     hours = data;
  51. }
  52.  
  53. void Time::setMinutes(int data) {
  54.     minutes = data;
  55. }
  56.  
  57. void Time::setSeconds(int data) {
  58.     seconds = data;
  59. }
  60.  
  61. void Time::setHours1(int data) {
  62.     hours1 = data;
  63. }
  64.  
  65. void Time::setMinutes1(int data) {
  66.     minutes1 = data;
  67. }
  68.  
  69. void Time::setSeconds1(int data) {
  70.     seconds1 = data;
  71. }
  72.  
  73. void Time::plusData(int hours, int minutes, int seconds, int hours1, int minutes1, int seconds1) {
  74.     int totalSeconds = 0;
  75.     totalSeconds = hours * 3600 + hours1 * 3600 + minutes * 60 + minutes1 * 60 + seconds + seconds1;
  76.     totalSec = totalSeconds;
  77. }
  78.  
  79. void Time::minusData(int hours, int minutes, int seconds, int hours1, int minutes1, int seconds1) {
  80.     int totalSeconds = 0;
  81.     totalSeconds = hours * 3600 - hours1 * 3600 + minutes * 60 - minutes1 * 60 + seconds - seconds1;
  82.     totalSec = totalSeconds;
  83. }
  84.  
  85. void Time::showResult () {
  86.     int hoursTotal = 0, minutesTotal = 0, secondsTotal = 0;
  87.     cout << totalSec;
  88.     hoursTotal = totalSec / 3600;
  89.     totalSec = totalSec % 3600;
  90.     minutes = totalSec / 60;
  91.     totalSec = totalSec % 60;
  92.     secondsTotal = totalSec;
  93.     cout << hoursTotal << ":" << minutesTotal << ":" << secondsTotal << endl;
  94.  
  95. }
  96.  
  97. int main()
  98. {
  99.     setlocale(LC_ALL, "rus");
  100.     cout << "Введите время в формате чч:мм:сс" << endl;
  101.     string str, str2;
  102.     cin >> str; cin >> str2;
  103.     Time time (str, str2);
  104.     time.showResult();
  105.     return 0;
  106. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement