Thursday, September 25, 2014

WAP defining a class named complex with two data members real and imaginary. Use necessary member functions for input/output and define a member function that adds the two complex objects and return object. Also display the result using a member function display ().

#include
#include
#include
#include

class complex
{
            long float real,img,c1,c2,c3;
            public:
            complex add(complex c1,complex c2);
            void input()
            {
                        cout<<"Enter Real number:";
                        cin>>real;
                        cout<<"Enter Imaginary Number:";
                        cin>>img;
            }
            void output(complex c3)
            {
                        cout<<"The sum is:"<
            }
};

            complex complex:: add(complex c1,complex c2)
            {
                        complex c3;
                        c3.real=c1.real+c2.real;
                        c3.img=c1.img+c2.img;
                        return c3;
            }
void main()
{
            clrscr();
            complex c1,c2,c3;
            c1.input();
            c2.input();
            c3=c3.add(c1,c2);
            c3.output(c3);
            getch();

}

No comments:

Post a Comment