This another project and it is called Complex Class.

Create a class called Complex for performing arithmetic with complex numbers.

Y=Use double variables to represent the private data of the class. Provide a constructor that enables an object if 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 that perform the following task:

a) Adding two complex numbers. The real parts are added together and the imaginary parts added together.
b)Subtracting 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.

This code has still errors...please do correct it...hehe

``````#include <iostream>
using namespace std;

class Complex{
public:
Complex(double real, double imaginary, double r, double i){
setReal1(real);
setImaginary1(imaginary);
setReal2(r);
setImaginary2(i);
}
void setReal1(double real);{
real1=real;
}
void set Imaginary1(double imaginary){
imaginary1=imaginary;
}
void set Real2(double r){
real2=real;
}
void setImaginary2(double i){
imaginary2=i;
}
double getReal1(){
return real1;
}
double getReal2(){
return real2;
}
double getImaginary1(){
imaginary1=imaginary1*sqrt-1;
return imaginary1;
}
double getImaginary2(){
imaginary2-imaginary2*sqrt-1;
return imaginary2;
}
double getsum1(){
double sum1;
sum1=real1+real2'
return sum1;
}
double getsum2(){
double sum2;
sum2=imaginary1+imaginary2;
return sum2;
}
double getdiff1(){
double diff1;
diff1=real1-real2;
return diff1;
}
double getdiff2(){
double diff2;
diff2=imaginary1-imaginary2;
return diff2;
}
void dispalymessage(){
cout << "real sum:" << sum1;
cout << "imaginary sum:" << sum2;
cout << "real difference:" << diff1;
cout << "imaginary difference:" << diff2;
}

private:
double real1, real2, imaginary1, imaginary2;
};

int main(){
Complex x(12,10,11,5);
cout << x.getReal1 << " " << x.getImaginary1 << " " << x.getReal2 << " " << x.getImaginary2 << " " << endl;
print();
return 0;
}``````

A class should contain only one complex number, not two!
You didn't put default constructor in code.
...
The code is full of errors

Create a class which holds a single complex number and with an ostream& operator << ( std::ostream &s, const Complex &c). Then implement friend operator +() and friend operator -() for two Complex objects.

[search]c++ complex numbers[/search]

here you are

ok..thanks..i'm just a beginner so i don't know much...hehe...hmnn...

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.