Skip to content

Instantly share code, notes, and snippets.

@omkarnathsingh
Last active August 29, 2015 14:22

Revisions

  1. omkarnathsingh revised this gist Jun 5, 2015. 1 changed file with 2 additions and 1 deletion.
    3 changes: 2 additions & 1 deletion Operator++
    Original file line number Diff line number Diff line change
    @@ -26,7 +26,8 @@ public:


    void display() {
    cout<<"\nReal Part: "<<a<<"\tImaginary Part: "<<b<<" i";
    cout<<"\nReal Part: "<<a;
    cout<<"\tImaginary Part: "<<b<<" i";
    }

    //Prototypes
  2. omkarnathsingh revised this gist Jun 5, 2015. 1 changed file with 9 additions and 3 deletions.
    12 changes: 9 additions & 3 deletions Operator++
    Original file line number Diff line number Diff line change
    @@ -4,6 +4,8 @@
    * Created on: 03-Jun-2015
    * Author: omkarnathsingh
    */


    #include<iostream>
    using namespace std;

    @@ -28,9 +30,13 @@ public:
    }

    //Prototypes
    Complex operator=(Complex op2); //to pass operand as reference parameter
    friend Complex operator++(Complex &op); //prefix version
    friend Complex operator++(Complex &op,int x); //postfix version
    //to pass operand as reference parameter
    Complex operator=(Complex op2);
    //prefix version
    friend Complex operator++(Complex &op);
    //postfix version
    friend Complex operator++(Complex &op,int x);

    };

    Complex Complex::operator=(Complex op2) {
  3. omkarnathsingh created this gist Jun 3, 2015.
    65 changes: 65 additions & 0 deletions Operator++
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,65 @@
    /*
    * Source.cpp
    *
    * Created on: 03-Jun-2015
    * Author: omkarnathsingh
    */
    #include<iostream>
    using namespace std;

    class Complex
    {
    int a,b;

    public:
    //Constructors
    Complex() {
    a=0; b=0;
    }

    Complex(int m,int n) {
    a=m;
    b=n;
    }


    void display() {
    cout<<"\nReal Part: "<<a<<"\tImaginary Part: "<<b<<" i";
    }

    //Prototypes
    Complex operator=(Complex op2); //to pass operand as reference parameter
    friend Complex operator++(Complex &op); //prefix version
    friend Complex operator++(Complex &op,int x); //postfix version
    };

    Complex Complex::operator=(Complex op2) {
    a=op2.a;
    b=op2.b;
    return *this;
    }

    Complex operator++(Complex &op) {
    op.a++;
    op.b++;
    return op;
    }

    Complex operator++(Complex &op,int x) {
    op.a++;
    op.b++;
    return op;
    }

    int main()
    {
    Complex ob1;
    ob1.display();
    ++ob1;
    ob1.display();
    ob1++;
    ob1.display();
    return 0;
    }