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