Posted by MindBreaker at 11:21 PM
Read our previous post
Object:
Program to give output using operator in prefix and postfix which is user define.
Source Code:
#include <iostream>
using namespace std;
class counter
{
int count;
public:
counter()
{
count=1;
}
int operator++()
{
count++;
return count;
}
};
void main()
{
counter cnt;
int post,pre,rnt;
char ch;
cout<<"1 for Postfix"<<endl;
cout<<"2 for Prefix"<<endl;
cin>>ch;
switch(ch)
{
case '1':
//////////////////////////////////////// postfix in operator
{
cout<<"Postfix : "<<cnt++;
break;
}
case '2':
//////////////////////////////////////// prefix in operator
{
++cnt;
cout<<"Prefix : "<<++cnt;
break;
}
}
Output:
Program to give output using operator in prefix and postfix which is user define.
Source Code:
#include <iostream>
using namespace std;
class counter
{
int count;
public:
counter()
{
count=1;
}
int operator++()
{
count++;
return count;
}
};
void main()
{
counter cnt;
int post,pre,rnt;
char ch;
cout<<"1 for Postfix"<<endl;
cout<<"2 for Prefix"<<endl;
cin>>ch;
switch(ch)
{
case '1':
//////////////////////////////////////// postfix in operator
{
cout<<"Postfix : "<<cnt++;
break;
}
case '2':
//////////////////////////////////////// prefix in operator
{
++cnt;
cout<<"Prefix : "<<++cnt;
break;
}
}
Output:
No comments:
Post a Comment
Note: Only a member of this blog may post a comment.