Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //++ and -- Operator overloading
- #include <iostream.h>
- #include <process.h>
- class clock
- {
- int hours, min;
- public:
- clock(int th, int tm)
- {
- hours=th;
- min=tm;
- }
- void display()
- {
- cout<<"\nThe time is "<<hours<<":"<<min;
- }
- void operator ++() //prefix ovrldng
- {
- hours++;
- }
- void operator ++(int temp) //postfix
- {
- min++;
- }
- void operator --() //prefix
- {
- hours--;
- }
- void operator --(int temp)//postfix
- {
- min--;
- }
- };
- int main()
- {
- clock c(12,0);
- int ch;
- menu:
- c.display();
- cout<<"\nMenu:\n1. Advance time by 1 hour\n2. Advance time by 1 minute\n3. Reduce time by 1 hour\n4. Reduce time by 1 minute\n5. Exit\nEnter choice...";
- cin>>ch;
- switch(ch)
- {
- case 1:
- ++c;
- break;
- case 2:
- c++;
- break;
- case 3:
- --c;
- break;
- case 4:
- c++;
- break;
- case 5:
- exit(0);
- default:
- cout<<"\nInvalid Choice!";
- goto menu;
- }
- goto menu;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement