Search
 
SCRIPT & CODE EXAMPLE
 

CPP

adding two dates using necessary member function in c++

//adding two dates using necessary member function **sudipnext**
#include <iostream>
using namespace std;

class time
{
    int hour, minute, second, day;

public:
    time()
    {
        hour = 0;
        minute = 0;
        second = 0;
        day = 0;
    }
    void getData()
    {
        cout << "Enter the date in day, hour, minute and second respectively:-" << endl;
        cin >> day >> hour >> minute >> second;
    }
    time add(time a, time b)
    {
        time temp;
        temp.second = a.second + b.second;
        temp.minute = a.minute + b.minute;
        temp.hour = a.hour + b.hour;
        temp.day = a.day + b.day;
        if (temp.second >= 60)
        {

            temp.second -= ((temp.second / 60)*60);
            temp.minute += temp.second / 60;
        }
        else if (temp.minute >= 60)
        {

            temp.minute -= ((temp.minute / 60)*60);
            temp.hour += temp.minute / 60;
        }
        else if (temp.hour >= 24)
        {


            temp.hour -= ((temp.hour / 24)*24);
            temp.day += temp.hour / 24;
        }
        return temp;
    }
    void display()
    {
        cout << "The result is day:- " << day << " hour:- " << hour << " minute:- " << minute << " second:- " << second << endl;
    }
};

int main()
{
    time obj1, obj2, obj3;
    obj1.getData();
    obj2.getData();
    obj3 = obj3.add(obj1, obj2);
    obj3.display();
}
Comment

PREVIOUS NEXT
Code Example
Cpp :: C++ Detect when user presses arrow key 
Cpp :: triangle angle sum 
Cpp :: forkortelse for intet 
Cpp :: identity 
Cpp :: c++ execute thread and forget 
Cpp :: jquery datepicker default date not working 
Cpp :: function and function prototype. 
Cpp :: what c++ library is arccos in 
Cpp :: c ++ Prefix Sum of Matrix (Or 2D Array) 
Cpp :: function param pointer to struct prototype in c 
Cpp :: second smallest element in array using one loop 
Cpp :: ordine crescente di numeri indefiniti in c++ 
Cpp :: dinamic 
Cpp :: .txt file into .cpp 
Cpp :: powershell script query mssql windows authentication 
Cpp :: Write a CPP program to calculate sum of first N natural numbers 
Cpp :: how to add values in empty array using python 
Cpp :: Use of Scope Resolution operator for namespace 
Cpp :: statement that causes a function to end in c++ 
Cpp :: cudaMalloc 
Cpp :: c++ program to convert time in seconds to hours minutes and seconds 
Cpp :: c++ string to const char* 
Cpp :: c++ start thread later 
Cpp :: esp8266 wifi.localip() to string 
Cpp :: generate consecutive numbers at compile time 
Cpp :: cpp-variadics/problem? 
Cpp :: how to make a running text in c++ 
Cpp :: time out search element in linked list c++ 
Cpp :: // A C++ program to show that we can use reference to 
Cpp :: Swift if...else Statement 
ADD CONTENT
Topic
Content
Source link
Name
1+2 =