Monday, July 27, 2009

How to write a program in Java with imaginary numbers, I have no idea where to start.?

the problem, Create a class called Complex for performing arithmetic with complex numbers complex number have the form


realPart + imaginaryPart 8 i


where i is the square root of -1.


write a program to test your class. Use floating point variables to represent the private data of the class. Provide a constructor the enables an object of this class to be initialized when it is declared.


Provide a no argument constructor with default values in case no initalizers are provided. Provide public methods that perform the following operations:


a)add two complex numbers


b)Subtract two complex numbers


c) print complex numbers in the form (a,b) where (a) is the real part and (b) is the imaginary part.





Any help is GREATLY appreciated.

How to write a program in Java with imaginary numbers, I have no idea where to start.?
Fairly straight forward. The code below is the skeletal C++ code (since I am not familiar with Java).





class Complex {


public:


Complex () {a = 0; b = 0;}


Complex (float x, float y) { a = x; b = y;}


float real () {return a;}


float imaginary () {return b;}


void Add (Complex c, Complex d) { a = c.real() + d.real();


b = c.imaginary() + d.imaginary();}


void Subtract (Complex c, Complex d) {....}


void Print() { cout %26lt;%26lt; a %26lt;%26lt; "+ i" %26lt;%26lt; b; }


private:


float a;


float b;


};
Reply:do a search for java script calculators


No comments:

Post a Comment