Comments

Saturday, November 24, 2012

OOP Postfix and Prefix in Operator

Posted by 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:


No comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Popular Posts

Labels

© Codepirate is powered by Blogger - Template designed by Stramaxon - Best SEO Template