101
{ USER }
posts: 55
last: 09-Apr-2008
TITLE: Complex nos Algorithm
DESCRIPTION: Complex nos
Submitted: 09-Apr-2008 09:55:02 ( 38w 5d 23h ago ) Language: C++ (*.cpp *.h)
Views: 98 Lines of Code: 80 LINES
Rating:
rate: star1
star2
star3
star4
star5
dstar1
dstar2
dstar3
dstar4
dstar5  ( rated! )
  { 0.00 / 5 }
Difficulty: Advanced
Bookmark
/* Author: 101
   Date: 09-04-2008
   Filename: 
   Description: Complex nos
   History: 
*/


#include<iostream.h>
#include<conio.h>
class complex
{
	private:
		float real,img;
	public:
		void assign(float x,float y)
		{
			real=x;
			img=y;
		}
		void print()
		{  if(img>=0)
			cout<<real<<"+"<<img<<"i";
			else
				cout<<real<<img<<"i";
		getch();
		}
};
void add( float a,float b,float c, float d)
	{

		float e,f;complex g;
		e=a+c;
		f=b+d;
		g.assign(e,f);
	   g.print();
	}
void sub( float a,float b,float c, float d)
	{

		float e,f;complex g;
		e=a-c;
		f=b-d;
		g.assign(e,f);
	   g.print();
	}
void mul( float a,float b,float c, float d)
	{

		float e,f; complex g;
		e=a*c-b*d;
		f=b*c+a*d;
		g.assign(e,f);
	   g.print();
	}
void main()
{
	float a,b,c,d;
	complex x,y,z;
	clrscr();
	cout<<" for complex 1:";
	cout<<"real part:";
	cin>>a;
	cout<<"imaginary part:";
	cin>>b;
	cout<<" for complex 2:";
	cout<<"real part:";
	cin>>c;
	cout<<"imaginary part:";
	cin>>d;
	x.assign(a,b);
	y.assign(c,d);
	cout<<"**************original data:************\n";
	cout<<"Complex 1:\n";x.print();
	cout<<"\n Complex 2:\n";y.print();
	cout<<"\n************=================**********\n";
	cout<<"\n Addition:\n";add(a,b,c,d);
	cout<<"\n Subtraction:\n";sub(a,b,c,d);
	cout<<"\n Multipication:\n";mul(a,b,c,d);
  }