1. Class Time ( Operator Overloading) PLEASE READ THE MAIN FUNCTION. DO NOT CHANGE THE MAIN FUNCTION. COMPLETE THE PROGRAM TO GET THE CORRECT OUTPUT. 【Description】 Write a program to define a class Time, which contains three member variables: hour, minute and second Please realize the following functions with operator overloading: input and output time with >> and << use += and -= increase and decrease the time ,e.g.Time& operator+=(const Time&);Time& operator-=(const Time&); 【Input】 There are two line, each line is the time of a clock Input format:hour minute second。 【Output】 There are two lines. The first line is the output of time1 += time2 ; The second line is the output of time1 -= time2 ; Output format:hour:minute:second; Please read the 【Input example】 21 10 35 10 15 25 【Output example】 07:26:00 21:10:34 THE INCOMPLETE CODE. NOTE: Do not change the main function #include using namespace std; class Time { }; int main() { Time time1,time2; cin>>time1>>time2; time1 += time2; cout<
1. Class Time ( Operator Overloading)
PLEASE READ THE MAIN FUNCTION.
DO NOT CHANGE THE MAIN FUNCTION.
COMPLETE THE
【Description】
Write a program to define a class Time, which contains three member variables: hour, minute and second
Please realize the following functions with operator overloading:
-
input and output time with >> and <<
-
use += and -= increase and decrease the time ,e.g.Time& operator+=(const Time&);Time& operator-=(const Time&);
【Input】
-
There are two line, each line is the time of a clock
-
Input format:hour minute second。
【Output】
-
There are two lines.
-
The first line is the output of time1 += time2 ;
-
The second line is the output of time1 -= time2 ;
-
Output format:hour:minute:second;
-
Please read the
【Input example】
21 10 35 10 15 25【Output example】
07:26:00 21:10:34THE INCOMPLETE CODE.
NOTE: Do not change the main function
#include <iostream>
using namespace std;
class Time
{
};
int main()
{
Time time1,time2;
cin>>time1>>time2;
time1 += time2;
cout<<time1<<endl;
time1 -= time2;
cout<<time1<<endl;
return 0;
}
Step by step
Solved in 2 steps