Thursday, July 30, 2009

C++ problem with complex numbers?

How do you define a class for complex numbers, a and b are numbers of type double, and i is a number that represents the quantity sqrt -1. Represent a complex number as two values of type double. Name the member variables real and imaginary. (The variable for the number that is multiplied by i is the one called imaginary.) Call the class complex.





I am trying to learn C++ at my house and am stuck on what to do on this question. Any help is greatly appreciated.

C++ problem with complex numbers?
I am a beginner in C++...for my knowledge and logic it can be like this :





======================================...


class complex


{ double real,imaginary ;


public:void get()


{cout%26lt;%26lt;"Enter real part \t : \t ";cin%26gt;%26gt;real;


cout%26lt;%26lt;"Enter imaginary part \t:\t";cin%26gt;%26gt;imaginary;


}


void put()


{ if(imaginary%26lt;0)


cout%26lt;%26lt;real%26lt;%26lt;" - i"%26lt;%26lt;imaginary*-1;


else


cout%26lt;%26lt;real%26lt;%26lt;" + i"%26lt;%26lt;imaginary;}


};


No comments:

Post a Comment