Professional Documents
Culture Documents
Write A Program To Demonstrate Type Conversation and Constructor With Operator Overloading
Write A Program To Demonstrate Type Conversation and Constructor With Operator Overloading
Write A Program To Demonstrate Type Conversation and Constructor With Operator Overloading
{ ime t; t.h=(m1/60)+t1.h; t.m=(m1%60)+t1.m; return(t); } time::operatorint() { return(h*60 + m); } int main() { clrscr(); cout<<"POWERED BY PSTECHNOSYSTEMS.ORG\n\n"; time t1(260),t2(2,30),t3; cout<<"\n Initial Times "; cout<<"\n t1 = "; t1.showtime(); cout<<"\n t2 = "; t2.showtime(); cout<<"\n\n :: Example of Operator Oveloading Using Member Function :: "; cout<<"\n t3 = t1 + t2" ; t3 = t1 + t2; cout<<"\n t1 = "; t1.showtime(); cout<<"\n t2 = "; t2.showtime(); cout<<"\n t3 = "; t3.showtime(); cout<<"\n\n :: Example of Operator Oveloading using Friend Function :: "; cout<<"\n t3 = Minutes + t1"; cout<<"\n Enter Minutes to add to time object t1 = "; int min; cin>>min; t3 = min + t1; cout<<" t1 = "; t1.showtime(); cout<<"\n t3 = "; t3.showtime();
cout<<"\n\n :: Example of Type Conversion Basic(Integer) to Class(time) :: Achieved with Single agument constructor :: "; cout<<"\n\n t3 = Minutes"; cout<<"\n Enter Minutes to convert to time object :: "; cin>>min; t3 = min; cout<<" New t3 after type conversion ::"; t3.showtime(); cout<<"\n\n Type Conversion Class(time) to Basic(Integer) ::\n Using operator int() method :: "; cout<<"\n\n Minutes = t3"; t3.settime(); cout<<" t3 = "; min = t3; t3.showtime(); cout<<" = "<<min; cout<<" minutes\n"; return 0;
} OUTPUT