Code Competitions

Coding competition

Saturday, 15 June 2013

program to overload - operator, parametrised constructor to perform complex number subtraction

#include<iostream.h>
#include<conio.h>
#include<process.h>
class uniary
{
    private:
    int a,b;
    public:
    uniary()
    {
        //a=0;b=1;
        //cout<<"enter the value of n ;
    }
    uniary(int a1,int b1)
    {
        a=a1;b=b1;
    }
    uniary operator-(uniary);
    void display()
    {
        cout<<"\ncomplex number is "<<a<<'+'<<b<<'i';
    }
};
uniary uniary::operator-(uniary u2)
{
    uniary u;
    u.a=a-u2.a;
    u.b=b-u2.b;
    return(u);
}
void main()
{
    clrscr();
    int a;
    uniary u1(4,6),u2(2,3),u3;
    //++u2;
    u3=u1.operator-(u2);
    u3.display();
    getch();
}

No comments:

Post a Comment