ALGORITHAM:
• Start the process
• Invoke the class counter
• Crate two objects c1 and c2
• Assign values to c1 an c2
o Call c1.get_count()
o Call c2.get_count()
• Increment the values
o C1++
o C2++
o ++c2
• Print c1 and c2
• Stop the process
PROGRAM
#include<iostream.h> #include<conio.h> class counter { int count; public: counter() { count=0; } int get_count() { return count; } void operator++() { count++; } }; void main() { counter c1,c2; cout<<"\nC1 ="<<c1.get_count(); cout<<"\nC2 ="<<c2.get_count(); c1++; //Using overloaded ++ operator. c2++; ++c2; cout<<"\nC1 ="<<c1.get_count(); cout<<"\nC2 ="<<c2.get_count(); getch(); } |
OUT PUT:
C1=0 C2=O
C1=1 C2=2
Description :
This is the one stop educational site for all Electronic and Computer students. If you want to learn something new then we are here to help. We work on Microcontroller projects, Basic Electronics, Digital electronics, Computer projects and also in basic c/c++ programs.
#Home #Sitemap #Resources #Terms of Use
Copyright©2012 electrofriends.com All Rights Reserved
Contact:info@electrofriends.com
thanx 4 the gud work ur doing