Thursday, 7 March 2019

CPP-EX7


Write a C++ program to create a class Integer. Write necessary member  functions to overload the operator unary pre and post increment '++' for an integer number. */

#include<iostream.h>
#include<conio.h>
class Integer
{
int a;
public:
void accept();
void show();
void operator++();
};

void Integer::accept()
{
cout<<"\nEnter a Number:";
cin>>a;
}

void Integer::show()
{
cout<<"\nEntered number is:"<<a;
}

void Integer::operator++()
{
int temp;
temp=a;
cout<<"\nPre increment of the given number is:"<<++temp;
cout<<"\nPost increment of the given number is:"<<a++;
}
int main()
{
clrscr();
Integer i;
i.accept();
i.show();
i.operator++();
getch();
return 0;
}