Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cstdlib>
- using namespace std;
- class Time {
- private:
- int hours = 0, minutes = 0, seconds = 0;
- int hours1 = 0, minutes1 = 0, seconds1 = 0;
- int totalSec = 0;
- public:
- void setHours(int data);
- void setMinutes(int data);
- void setSeconds(int data);
- void setHours1(int data);
- void setMinutes1(int data);
- void setSeconds1(int data);
- void plusData(int hours, int minutes, int seconds, int hours1, int minutes1, int seconds1);
- void minusData(int hours, int minutes, int seconds, int hours1, int minutes1, int seconds1);
- void showResult ();
- Time(string data, string data1) {
- char buf[3] = "";
- buf[0] = data[0];
- buf[1] = data[1];
- setHours(atoi(buf));
- buf[0] = data[3];
- buf[1] = data[4];
- setMinutes(atoi(buf));
- buf[0] = data[6];
- buf[1] = data[7];
- setSeconds(atoi(buf));
- buf[0] = data1[0];
- buf[1] = data1[1];
- setHours1(atoi(buf));
- buf[0] = data1[3];
- buf[1] = data1[4];
- setMinutes1(atoi(buf));
- buf[0] = data1[6];
- buf[1] = data1[7];
- setSeconds1(atoi(buf));
- plusData(hours, minutes, seconds, hours1, minutes1, seconds1);
- }
- };
- void Time::setHours(int data) {
- hours = data;
- }
- void Time::setMinutes(int data) {
- minutes = data;
- }
- void Time::setSeconds(int data) {
- seconds = data;
- }
- void Time::setHours1(int data) {
- hours1 = data;
- }
- void Time::setMinutes1(int data) {
- minutes1 = data;
- }
- void Time::setSeconds1(int data) {
- seconds1 = data;
- }
- void Time::plusData(int hours, int minutes, int seconds, int hours1, int minutes1, int seconds1) {
- int totalSeconds = 0;
- totalSeconds = hours * 3600 + hours1 * 3600 + minutes * 60 + minutes1 * 60 + seconds + seconds1;
- totalSec = totalSeconds;
- }
- void Time::minusData(int hours, int minutes, int seconds, int hours1, int minutes1, int seconds1) {
- int totalSeconds = 0;
- totalSeconds = hours * 3600 - hours1 * 3600 + minutes * 60 - minutes1 * 60 + seconds - seconds1;
- totalSec = totalSeconds;
- }
- void Time::showResult () {
- int hoursTotal = 0, minutesTotal = 0, secondsTotal = 0;
- cout << totalSec;
- hoursTotal = totalSec / 3600;
- totalSec = totalSec % 3600;
- minutes = totalSec / 60;
- totalSec = totalSec % 60;
- secondsTotal = totalSec;
- cout << hoursTotal << ":" << minutesTotal << ":" << secondsTotal << endl;
- }
- int main()
- {
- setlocale(LC_ALL, "rus");
- cout << "Введите время в формате чч:мм:сс" << endl;
- string str, str2;
- cin >> str; cin >> str2;
- Time time (str, str2);
- time.showResult();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement