I beg you guys please.....................

This is a discussion on I beg you guys please..................... within the C++ Programming forums, part of the General Programming Boards category; Hi , I have a big problem with operator overloading.. The question is Design a class to represent complex numbers ...

  1. #1
    Its not rocket science vasanth's Avatar
    Join Date
    Jan 2002
    Posts
    1,683

    Unhappy I beg you guys please.....................

    Hi ,
    I have a big problem with operator overloading.. The question is

    Design a class to represent complex numbers with operator overloading redifining +,-,* and == to perform revelant function on the complex numbers.. I have done a bit but i dont knoe further Please help me.......



    # include <iostream.h>
    # include <conio.h>


    class complex {

    private:
    int r,i;
    public:
    accept()
    {
    cin>>r>>i;



    }
    complex operator +()
    {
    int sumr,sumi;
    sumr=a.r+b.r;
    sumi=a.i+b.i;
    cout<<" The addes result is ";
    cout<<sumr<<" "<<sumi<<"i";

    }


    };

    void main()
    {
    clrscr();
    complex a,b;
    a.accept();
    b.accept();
    a+b;


    }

    This one is for only + but still doesent work.....
    Dont say that i am asking you guys to do my home work.. I tried my level best but couldnt.. I have to submit it tommorow...



    ....

  2. #2
    S­énior Member
    Join Date
    Jan 2002
    Posts
    982
    >Dont say that i am asking you guys to do my home work..

    Well, you are aren't you .

    This should get you started -

    Code:
    class complex { 
    
    private: 
    	int r,i; 
    public: 
    
    	complex(int _r=0,int _i=0):r(_r),i(_i){}
    	complex operator +(const complex& rhs) 
    	{ 
    		return complex(r+rhs.r,i+rhs.i);
    	} 
    }; 
    
    int  main() 
    { 
    
    	complex a(1,2),b(1,2); 
    	complex c = a+b; 
    	return 0;
    
    }

  3. #3
    Its not rocket science vasanth's Avatar
    Join Date
    Jan 2002
    Posts
    1,683

    thanks

    Thank u pal.. It woks....... Off i am saved.. I promise to concentrate in C++ clases from now on

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 3
    Last Post: 08-25-2008, 12:39 PM
  2. Hey guys, I'm new!
    By MrDoomMaster in forum C++ Programming
    Replies: 15
    Last Post: 10-31-2003, 04:47 PM
  3. How long have you guys been working with C/C++??
    By Lurker in forum A Brief History of Cprogramming.com
    Replies: 24
    Last Post: 08-01-2003, 03:41 PM
  4. simulate Grep command in Unix using C
    By laxmi in forum C Programming
    Replies: 6
    Last Post: 05-10-2002, 04:10 PM
  5. Tic Tac Toe -- Can you guys rate this please?
    By Estauns in forum Game Programming
    Replies: 2
    Last Post: 09-15-2001, 10:22 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21