Hello,
when i try to compile this program (it has three parts) I receive an error message that confuses me. Below are the code and error message.
Code:
#include <iostream>
using std::cout;
using std::endl;
#include "Complex.h"
int main()
{
Complex x(2, 3), y(4, 5), z;
x.printComplex();
cout << " + ";
y.printComplex();
cout << " = ";
x.add(y);
x.printComplex();
cout << '\n';
x.setComplexNumber(10, 1); //reset Real
y.setComplexNumber(11, 5); //reset Imaginery
x.printComplex();
cout << " - ";
y.printComplex();
cout << " = ";
x.subtract(y);
x.printComplex();
cout << '\n';
x.equal(y);
cout << endl;
return 0;
}
Code:
#ifndef Complex.h
#define Complex.h
class Complex {
public:
Complex(double = 0.0, double = 0.0); //default constructor
Complex Complex::add(Complex &);
Complex Complex::subtract(Complex &);
void printComplex(void);
void setComplexNumber(double, double);
Complex Complex::equal(Complex &x);
private:
double realPart;
double imagineryPart;
}
#endif
Code:
#include <iostream>
using std::cout;
#include <Complex.h>
Complex::Complex(double real, double imaginery)
{ setComplexNumber(real, imaginery); }
void Complex::add(Complex &)
{
realPart += a.realPart;
imagineryPart =+ a.imagineryPart;
}
void Complex::subtract(Complex &)
{
realPart -= s.realPart;
imagineryPart -= s.realPart;
}
void Complex::printComplex(void)
{ cout << '(' << realPart << ", " << imagineryPart << ')'; }
void setComplexNumber(double rp, dounle ip)
{
realPart = rp;
imagineryPart = ip;
}
bool Complex::equal(Complex &x) {
return ((realPart == x.realPart) &&
(imagineryPart == x.imagineryPart));
}
The error msg says:
complex classes\complex.h(4) : warning C4067: unexpected tokens following preprocessor directive - expected a newline
complex classes\complex.h(5) : error C2008: '.' : unexpected in macro definition
Complex Classes\ComplexClient.cpp(11) : error C2628: 'h' followed by 'int' is illegal (did you forget a ';'?)
I do not understand what those mean. Can anyone help me? Thanks so much, I really appreciate it a lot.