Hi;
i am trying to write complex.cpp and it gives error message
can somebody look and write me back what is wrong
here is the program[ three parts] and the error message

#include<iostream>
#include<cctype>
#include<cstdio>
#include"complex.h"
using namespace std;

void main(void)
{
	CComplex a;
	CComplex b(5.5,2.2);
	CComplex c(b);

	cout<<"a = "<< a <<endl;
	cout<<"b = "<< b <<endl;
	cout<<"c = "<< c <<endl;

	if (b == c)
		cout<<"b and c are same.\n";
	else
		cout<<"b and c are different.\n";

	CComplex d = -c;
	cout<<"d = "<< d<<endl;

	if (b == d)
		cout<<"b and d are same.\n";
	else
		cout<<"b and d are different.\n";

	cout<<"Get input for complex a."<<endl;
	cin>> a;
	cout<< "a = " << a << endl;
	cout<< "a + b = " << a + b << endl;
	cout<< "a - b = " << a - b << endl;
	cout<< "a * b = " << a * b << endl;
	cout<< "a / b = " << a / b << endl;
	cout<< "b + d = " << b + d << endl;
	cout<< "b - c = " << b - c << endl;
	CComplex e;
	e.setReal (0.5);
	e.setImagination (-2.5);
	cout<< "e = " << e << endl;
	cout << "The real part of e: " << e.getReal() << endl;
	cout << "The Imagination part of e: " << e.getImagination() << endl;
	e.MultiplyTo (10.0);
	cout<< "e * 10.0 = " << e << endl;
	e.DivideBy (10.0);
	cout<< "e / 10.0 = " << e << endl;
	cout<< endl << endl;
}//end of main
#include<iostream>
#include "Complex.h"


using namespace std;
CComplex::CComplex()
{
	real = 0.0;
	imagination = 0.0;
}
CComplex::CComplex ( const double r, const double i)
{
	real = r;
	imagination = i;
}
CComplex::CComplex ( const CComplex& c)
{
	return c;
}
double CComplex::getReal() const
{
	return real;
}
double CComplex::getImagination() const
{
	return Imagination;
}
void CComplex ::setReal(double new_real)
{
	real = new_real;
}

void CComplex ::setImagination(double new_real)
{
	imagination = new_imagination;
}


CComplex operator + (const CComplex& c1, const CComplex& c2)
{
  CComplex r = c1;
  return r  = r+ c2;
}

CComplex operator - (const CComplex& c1, const CComplex& c2)
{
  CComplex r = c1;
  return r = r - c2;
}

CComplex operator * (const CComplex& c1, const CComplex& c2)
{
  CComplex r = c1;
  return (r = r* c2);
}

CComplex operator / (const CComplex& c1, const CComplex& c2)
{
  CComplex r = c1;
  return (r = r / c2);
}

//unary plus.
CComplex operator + (const CComplex& c)
{
  return c;
}

// unary minus
CComplex operator - (const CComplex& c)
{
  return ( c * -1);
}
void CComplex::MultiplyTo (const double& c)
{
	real = real * c.real;
	imagination = imagination * c.imagination;
	
}
void CComplex::DivideBy (const double& c)
{
	real = real / c.real;
	imagination = imagination / c.imagination;
	
}
/code] 

[code]

#ifndef COMPLEX_NUMBER
#define COMPLEX_NUMBER
#include<iostream>
#include<cmath>
using namespace std;
//class declaration
class CComplex
{
	public:

	//friend functiopn prototype
	friend CComplex operator - (const CComplex& pComplexNum);
	friend CComplex operator + (const CComplex& pComplexNum);
	friend CComplex operator + (const CComplex& pLeftComplex , const CComplex& pRightComplex);
	friend CComplex operator - (const CComplex& pLeftComplex , const CComplex& pRightComplex);
	friend CComplex operator * (const CComplex& pLeftComplex , const CComplex& pRightComplex);
	friend CComplex operator / (const CComplex& pLeftComplex , const CComplex& pRightComplex);
	friend CComplex operator == (const CComplex& pLeftComplex , const CComplex& pRightComplex);
	friend istream& operator >>(istream& instream, CComplex& pComplexNum);
	friend ostream& operator <<(ostream& outstream, CComplex& pComplexNum);
	
	//constructors
	CComplex (void);
	CComplex ( double , double);
	CComplex ( const CComplex& c);
	//accessor function
	double getReal (void) const;
	double getImagination (void) const;
    void setReal (double);
	void setImagination (double);
	//other member function
	void MultiplyTo (const double& pNum);
	void DivideBy (const double& pNum);

private:
	//data members
	double real;
	double imagination;
};
#endif //COMPLEX_NUMBER
#ifndef COMPLEX_NUMBER
#define COMPLEX_NUMBER
#include<iostream>
#include<cmath>
using namespace std;
//class declaration
class CComplex
{
	public:

	//friend functiopn prototype
	friend CComplex operator - (const CComplex& pComplexNum);
	friend CComplex operator + (const CComplex& pComplexNum);
	friend CComplex operator + (const CComplex& pLeftComplex , const CComplex& pRightComplex);
	friend CComplex operator - (const CComplex& pLeftComplex , const CComplex& pRightComplex);
	friend CComplex operator * (const CComplex& pLeftComplex , const CComplex& pRightComplex);
	friend CComplex operator / (const CComplex& pLeftComplex , const CComplex& pRightComplex);
	friend CComplex operator == (const CComplex& pLeftComplex , const CComplex& pRightComplex);
	friend istream& operator >>(istream& instream, CComplex& pComplexNum);
	friend ostream& operator <<(ostream& outstream, CComplex& pComplexNum);
	
	//constructors
	CComplex (void);
	CComplex ( double , double);
	CComplex ( const CComplex& c);
	//accessor function
	double getReal (void) const;
	double getImagination (void) const;
    void setReal (double);
	void setImagination (double);
	//other member function
	void MultiplyTo (const double& pNum);
	void DivideBy (const double& pNum);

private:
	//data members
	double real;
	double imagination;
};
#endif //COMPLEX_NUMBER

[edit]Code tags fixed. Please use them correctly next time. -Narue[/edit]

thanks guys

the error message is

--------------------Configuration: main - Win32 Debug--------------------
Compiling...
main.cpp
C:\cworkSUMMER\COMPLEX\main.cpp(18) : error C2451: conditional expression of type 'class CComplex' is illegal
No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called
C:\cworkSUMMER\COMPLEX\main.cpp(26) : error C2451: conditional expression of type 'class CComplex' is illegal
No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called
Error executing cl.exe.

main.obj - 2 error(s), 0 warning(s)

ok i try this,
main.cpp

#include<iostream>
#include<cctype>
#include<cstdio>
#include"CComplex.h"
using namespace std;

void main(void)
{
	CComplex a;
	CComplex b(5.5,2.2);
	CComplex c(b);

	cout<<"a = "<< a <<endl;
	cout<<"b = "<< b <<endl;
	cout<<"c = "<< c <<endl;

	if (b == c)
		cout<<"b and c are same.\n";
	else
		cout<<"b and c are different.\n";

	CComplex d = -c;
	cout<<"d = "<< d<<endl;

	if (b == d)
		cout<<"b and d are same.\n";
	else
		cout<<"b and d are different.\n";

	cout<<"Get input for complex a."<<endl;
	cin>> a;
	cout<< "a = " << a << endl;
	cout<< "a + b = " << a + b << endl;
	cout<< "a - b = " << a - b << endl;
	cout<< "a * b = " << a * b << endl;
	cout<< "a / b = " << a / b << endl;
	cout<< "b + d = " << b + d << endl;
	cout<< "b - c = " << b - c << endl;
	CComplex e;
	e.setReal (0.5);
	e.setImagination (-2.5);
	cout<< "e = " << e << endl;
	cout << "The real part of e: " << e.getReal() << endl;
	cout << "The Imagination part of e: " << e.getImagination() << endl;
	e.MultiplyTo (10.0);
	cout<< "e * 10.0 = " << e << endl;
	e.DivideBy (10.0);
	cout<< "e / 10.0 = " << e << endl;
	cout<< endl << endl;
}//end of main

CComplex.cpp

//------------------------- Complex.cpp --------------------------------------
#include<iostream>
#include<cmath>
#include"CComplex.h"
using namespace std;
//class declaration
class CComplex
{
	

	//friend functiopn prototype
	friend CComplex operator - (const CComplex& pComplexNum);
	friend CComplex operator + (const CComplex& pComplexNum);
	friend CComplex operator + (const CComplex& pLeftComplex , const CComplex& pRightComplex);
	friend CComplex operator - (const CComplex& pLeftComplex , const CComplex& pRightComplex);
	friend CComplex operator * (const CComplex& pLeftComplex , const CComplex& pRightComplex);
	friend CComplex operator / (const CComplex& pLeftComplex , const CComplex& pRightComplex);
	friend bool operator == (const CComplex& pLeftComplex , const CComplex& pRightComplex);
	friend istream& operator >>(istream& instream, CComplex& pComplexNum);
	friend ostream& operator <<(ostream& outstream, CComplex& pComplexNum);
	public:
	//constructors
	CComplex (void);
	CComplex ( double , double);
	CComplex ( const CComplex& c);
	//accessor function
	double getReal (void) const;
	double getImagination (void) const;
    void setReal (double);
	void setImagination (double);
	//other member function
	CComplex MultiplyTo (const double& pNum);
	CComplex DivideBy (const double& pNum);

private:
	//data members
	double real;
	double imagination;
};



using namespace std;
CComplex::CComplex()
{
	real = 0.0;
	imagination = 0.0;
}
CComplex::CComplex ( const double r, const double i)
{
	real = r;
	imagination = i;
}
CComplex::CComplex ( const CComplex& c)
{
	real =  c.real;
	imagination = c.imagination;
}
double CComplex::getReal() const
{
	 return real;
}
double CComplex::getImagination() const
{
	 return imagination ;
}
void CComplex::setReal(double new_real)
{
	real = new_real;
}

void CComplex::setImagination(double new_imagination)
{
	imagination = new_imagination;
}


CComplex operator + (const CComplex& c1, const CComplex& c2)
{
	
  CComplex r = c1;
  return r  = r+ c2;
}

CComplex operator - (const CComplex& c1, const CComplex& c2)
{

  CComplex r = c1;
  return r = r - c2;
}

CComplex operator * (const CComplex& c1, const CComplex& c2)
{
	
  CComplex r = c1;
  return (r = r* c2);
}

CComplex operator / (const CComplex& c1, const CComplex& c2)
{
	
  CComplex r = c1;
  return (r = r / c2);
}

//unary plus.
CComplex operator + (const CComplex& c)
{
  return c;
}

// unary minus
CComplex operator - (const CComplex& c)
{
  return  c * -1;
}
CComplex CComplex::MultiplyTo (const double& c)
{
	return ((real*c.real)&&(imagination*c.imagination));
	
}
CComplex CComplex::DivideBy (const double& c)
{
	return ((real / c.real)&&(imagination / c.imagination));
	
}

istream& operator >>(istream& ins, CComplex& pComplexNum)
{
  ins >> pComplexNum.real >> pComplexNum.imagination;
  return ins;
}
//  Output stream operator as an ordinary non-member function

ostream& operator <<(ostream& outs, CComplex& pComplexNum)
{
	
  outs << pComplexNum.real << " +  " << pComplexNum.imagination << " * i" << endl;

   return outs;

}
 bool operator == (const CComplex& c1 , const CComplex& c2)
{
	return ((c1.real == c2.real) && 
		   (c1.imagination == c2.imagination) ); 
}

CComplex.h

#ifndef COMPLEX_NUMBER
#define COMPLEX_NUMBER
#include<iostream>
#include<cmath>
using namespace std;
//class declaration
class CComplex
{
	public:

	//friend functiopn prototype
	friend CComplex operator - (const CComplex& pComplexNum);
	friend CComplex operator + (const CComplex& pComplexNum);
	friend CComplex operator + (const CComplex& pLeftComplex , const CComplex& pRightComplex);
	friend CComplex operator - (const CComplex& pLeftComplex , const CComplex& pRightComplex);
	friend CComplex operator * (const CComplex& pLeftComplex , const CComplex& pRightComplex);
	friend CComplex operator / (const CComplex& pLeftComplex , const CComplex& pRightComplex);
	friend bool operator == (const CComplex& pLeftComplex , const CComplex& pRightComplex);
	friend istream& operator >>(istream& instream, CComplex& pComplexNum);
	friend ostream& operator <<(ostream& outstream, CComplex& pComplexNum);
	
	//constructors
	CComplex (void);
	CComplex ( double , double);
	CComplex ( const CComplex& c);
	//accessor function
	double getReal (void) const;
	double getImagination (void) const;
    void setReal (double);
	void setImagination (double);
	//other member function
	CComplex MultiplyTo (const double& pNum);
	CComplex DivideBy (const double& pNum);

private:
	//data members
	double real;
	double imagination;
};
#endif //COMPLEX_NUMBER

the ERROR message is

--------------------Configuration: main - Win32 Debug--------------------
Compiling...
CComplex.cpp
C:\cworkSUMMER\COMPLEX\CComplex.cpp(8) : error C2011: 'CComplex' : 'class' type redefinition
C:\cworkSUMMER\COMPLEX\CComplex.cpp(115) : error C2679: binary '*' : no operator defined which takes a right-hand operand of type 'const int' (or there is no acceptable conversion)
C:\cworkSUMMER\COMPLEX\CComplex.cpp(119) : error C2228: left of '.real' must have class/struct/union type
C:\cworkSUMMER\COMPLEX\CComplex.cpp(119) : error C2228: left of '.imagination' must have class/struct/union type
C:\cworkSUMMER\COMPLEX\CComplex.cpp(124) : error C2228: left of '.real' must have class/struct/union type
C:\cworkSUMMER\COMPLEX\CComplex.cpp(124) : error C2228: left of '.imagination' must have class/struct/union type
Error executing cl.exe.

main.exe - 6 error(s), 0 warning(s)

guys please help
thx

the ERROR message is

--------------------Configuration: main - Win32 Debug--------------------
Compiling...
CComplex.cpp
C:\cworkSUMMER\COMPLEX\CComplex.cpp(8) : error C2011: 'CComplex' : 'class' type redefinition

You gave the class definition already in CComplex.h, which got #included into the file. You don't need to define it again.

C:\cworkSUMMER\COMPLEX\CComplex.cpp(115) : error C2679: binary '*' : no operator defined which takes a right-hand operand of type 'const int' (or there is no acceptable conversion)

You overloaded the '*' operator for Complex types, but not for 'const int' types.

C:\cworkSUMMER\COMPLEX\CComplex.cpp(119) : error C2228: left of '.real' must have class/struct/union type

doubles don't have data members.

This article has been dead for over six months. Start a new discussion instead.