954,504 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Structures and Classes: Performing Basic Operations on Complex Numbers

please help me i m having problem for making this program

First Part: (Using Structures)
Create a structure called Complex for performing arithmetic with complex numbers.
Complex numbers have the form

realPart + imaginaryPart * i
where i = √(-1)
Use floating point data to represent members of structure (i.e. realPart and imaginaryPart).
Make appropriate functions to perform following operations on structure Complex type variables (which will be consisted of realPart and imaginaryPart members of structures):-
Initialize structure Complex variable.
Input Complex numbers from user.
Addition of two Complex numbers.
Subtraction of two Complex numbers.
Printing Complex numbers in the form (a,b) where a is the real part and b is imaginary part.

Make appropriate main function in which variables of Complex types are created and then all the above mentioned operations are performed on those variables.

As a hint consider following main function for your program

//function declarations
void initializeComplexNumber ( Complex &cmp ) ;
void setComplexNumber ( Complex &cmp , double x , double y ) ;  
Complex addComplexNumber ( const Complex cmp1 , const Complex cmp2 ) ;
Complex subtractComplexNumber (Complex cmp1 , Complex cmp2 ) ;

int main ( )
{
   //local declarations
   Complex c1 , c2 , c3 ;
   double x , y ;
   
   //initializing complex numbers
   initializeComplexNumber ( c1 ) ;
   initializeComplexNumber ( c2 ) ;
   initializeComplexNumber ( c3 ) ;

   //input two complex numbers c1 and c2 from user
   cout << “Input first complex number\n”  ;
   cout << “Input real part :  ” ;
   cin >> x ;
   cout << “Input imaginary part” ;
   cin >> y ;
   setComplexNumber ( c1 , x , y ) ;  
   
   cout << “Input second complex number\n”  ;
   …
   …
   …

   c3 = addComplexNumber ( c1 , c2 ) ;
   cout << “\nSum of two complex numbers is : (” << c3.realPart << “ , “ << c3.imaginaryPart
           << “ )” ;

}//end of main function


Second Part: ( Using classes)
Create a class called Complex for performing arithmetic with complex numbers. Write a driver program to test your class.

Complex numbers have the form
realPart + imaginaryPart * i
where i is √(-1)

Use double variables to represent the private data of the class. Provide a constructor function that enables an object of this class to be initialized when it is declared. The constructor should contain default values in case no initializers are provided. Provide public member functions for each of the following:
a) Addition of two Complex numbers: The real parts are added together and the imaginary parts are added together.
b) Subtraction of two Complex numbers: The real part of the right operand is subtracted from the real part of the left operand and the imaginary part of the right operand is subtracted from the imaginary part of the left operand.
c) Printing Complex numbers in the form (a, b) where a is the real part and b is the imaginary part.
d) set and get methods for private fields.

Rizi004
Newbie Poster
10 posts since Jun 2011
Reputation Points: 10
Solved Threads: 0
 

And the problem you're having is what, exactly?

Narue
Bad Cop
Administrator
15,460 posts since Sep 2004
Reputation Points: 6,464
Solved Threads: 1,401
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: