0

Write a c++ program

Overload -- and ++ operator for the coord class. Create both its prefix and postfix form.

16th Jan 2017, 5:05 PM
Mohammad Touhidul Islam
Mohammad Touhidul Islam - avatar
1 Odpowiedź
+ 2
#include <iostream> using namespace std; class time{ private: int hours; int minutes; public: time() { hours=0; minutes=0; } time(int h,int m){ hours=h; minutes=m; } void displaytime(){ cout<<hours<<":"<<minutes<<endl; } time operator++ () { ++minutes; // increment this object if(minutes >= 60) { ++hours; minutes -= 60; } return time(hours, minutes); } }; int main() { time T1(11, 59); ++T1; // increment T1 T1.displaytime(); // display T1 ++T1; // increment T1 again T1.displaytime(); // display T1 return 0; } didn't get your question properly but this is one of the examples for ++ operator overloading copy paste on your compiler and compile you will understand
16th Jan 2017, 5:09 PM
Anvesh
Anvesh - avatar