Dear Friends

Please provide me solution code of this programme.
A C++ program which contains a class named Time having three data members.
• Hours
• Minutes
• Seconds

The class must have
• A default and parameterized constructor
• show() method to display the time in proper format like HH:MM:SS on the screen
• get() method to get time from user
• Overloaded Plus (+) and Minus (-) operators
• A destructor

You will overload + and - operator for this class.

In main program make 3 objects of the Time class time1, time2 and time3 and call the get() functions for time1 and time2 then perform time3 = tim1+time2 and then you will display time3 using its show() function.

Note1: While Adding the time keep in mind do not just add the hours into hours and minutes into minutes and seconds in seconds , e.g
10:25:10
+01:45:25
---------------------
11: 70: 35

Will not be correct, instead your code should add times like, Note that as number of minutes have increased 60, hour have been increased.

10:25:10
+ 01:45:25
-------------------
12: 10: 35

I need source code only.

Regards

Yasir

Sir,

Since you are new here and this is your first post let me bring to your notice that no one here will give you a code on a platter. This is not a code writing machine here. Please try it on your own and post the code if you face any problems and then someone will help you cross the hurdles. That's how we work here!!

hope to see your code soon.

Dear Friends

Please provide me solution code of this programme.
A C++ program which contains a class named Time having three data members.
• Hours
• Minutes
• Seconds

The class must have
• A default and parameterized constructor
• show() method to display the time in proper format like HH:MM:SS on the screen
• get() method to get time from user
• Overloaded Plus (+) and Minus (-) operators
• A destructor

You will overload + and - operator for this class.

In main program make 3 objects of the Time class time1, time2 and time3 and call the get() functions for time1 and time2 then perform time3 = tim1+time2 and then you will display time3 using its show() function.

Note1: While Adding the time keep in mind do not just add the hours into hours and minutes into minutes and seconds in seconds , e.g
10:25:10
+01:45:25
---------------------
11: 70: 35

Will not be correct, instead your code should add times like, Note that as number of minutes have increased 60, hour have been increased.

10:25:10
+ 01:45:25
-------------------
12: 10: 35

I need source code only.

Regards

Yasir

Here you go

class Homework {
Homework() { cout << "Do your homework yourself" << endl; }

}
// kindly complete this code
// date class with set methods to set the day, month and year

# include <iostream>
using namespace std;
#  include <cstring>


class Time // defining the date class
{     
      public:          // interface of the class
             void display ();         // to display the date on the screen
             void printUniversal ();
             void printStandard();
             int setHour (int );
             void setMinute (int );    // setting the day
           
             void setSecond (int );
             int getHour();         // getting the value of day
             int getMinute();
             int getSecond();
      // constructor of the class
            
            Time ();
            Time (int,int);
            Time (int,int,int);
             
            Time operator +(Time &date2);
            
            //destructor of the class
            ~Time();
            // hidden part of the class
      private: 
               int hour;
              int minute;
               int second;
};
               // defening the constructor
               Time::Time()
               {
                hour = 0;
                minute = 0;
                second = 0;
                cout << "Default constructor is called:\n";
                }
                
                // constructor with  two arguments
                
                Time::Time ( int hour1 , int minute1)
                {
                hour = hour1;
                minute = minute1;
                second = 0;
                cout << "Constructor with two arguments is called:\n";
                }
                
                // constructor wit three arguments
                Time::Time ( int hour2, int minute2,int second2)
                {
                hour = hour2;
                minute = minute2;
                second = second2;
                cout << "Constructor with three arguments is called:\n";
                }
                
                // destructor
                Time::~Time()
                {
                cout << " the object is destoryed\n ";
                }
      // the display function of the class date
      void Time::display()
      {
           cout << "\nThe time is: " << hour <<":"<< minute << ":" << second <<endl<< endl;
           }
           
           // setting the  value of the day
           
           int Time::setHour (int h)
           {
                if ( h>=0 && h<24)
                hour = h;
                else
                hour = 1;
                
                }
                
           // setting the value of the month
           
           void Time::setMinute (int m)
           {
                if ( m>= 0 && m<=60)
                minute= m;
                else
                minute = 1;
                }
           // setting the value of the year
           
           void Time::setSecond (int s)
           {
                 if( s>= 0 && s <60)
                second = s;
                else
                second = 1;
            
                }
                
           // getting the value of the day
           
           int Time::getHour()
           {
                cout << "enter hour:";   
                  cin >> hour;       
               
               }
           // getting the value of the month
           
           int Time::getMinute()
           {
                cout << "enter minute:";
                cin >> minute; 
              
               }

           // getting the value of the year
           
           int Time::getSecond()
           {
              cout <<"enter second:";
              cin >> second;
               
               }
           
           Time Time :: operator +(Time &t)
           {
                Time tmp;
                tmp.hour = hour + t.hour;
                tmp.minute = minute + t.minute;
                tmp.second  = second + t.second;
                return tmp;
                }
                
 int main () // main program
 {
     Time time1; // taking object of the Date class
     Time time2;
     Time time3;
     // setting the value and displaying object date1
     time1.getHour();
     time1.getMinute();
     time1.getSecond();
     time2.getHour();
     time2.getMinute();
     time2.getSecond ();

     time1.display ();
     time2.display ();
     time3 = time1 + time2;
     time3.display();
     
     system("pause");
     return 0;
}

Umm...and...what is the problem? And why did you create 2 accounts? That's not very good use of the server's spare resources.

NIce peoples, nice replies!!
thanks to everybody.I got the solution with your helps.
Thanks to those who suggusted me to do my home work myself.

Special thanks to YOUNAS KHAN

NIce peoples, nice replies!!
thanks to everybody.I got the solution with your helps.
Thanks to those who suggusted me to do my home work myself.

Special thanks to YOUNAS KHAN

Please don't ever post here again.

This article has been dead for over six months. Start a new discussion instead.