Write the class timi which can be used in the following program. void main(){ ti
ID: 3656721 • Letter: W
Question
Write the class timi which can be used in the following program. void main(){ timi t1(16,20,0); // New instance of the class cout << t1 << endl; // Here the time 16:20:00, is displayed t1=timi(0,0,14655); cout << t1 << endl; t1+=timi(0,120,0); // += operator is used cout << t1 << endl; t1 = t1-timi(0,0,15); // - operator used cout << t1 << endl; t1 = timi(6,0,0)Explanation / Answer
#include using namespace std; void normalize(int& klst, int& min, int& sek); class timi{ int hour,minute, second; void minimize();//private fxn public: timi(int); timi(int,int,int); friend ostream& operator=60){ second-=60; minute++; } while(minute>=60){ minute-=60; hour++; } hour%=24; } timi::timi(int t){//takes t as second hour=0; minute=0; second=t; normalize(hour,minute,second); minimize(); } timi::timi(int hr,int min,int sec){ normalize( hr, min, sec); hour=hr; minute=min; second=sec; minimize(); } ostream& operatorRelated Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.