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{
     Complex(double real, double imaginary, double r, double i){
void setReal1(double real);{
void set Imaginary1(double imaginary){
void set Real2(double r){
void setImaginary2(double i){
double getReal1(){
     return real1;
double getReal2(){
     return real2;
double getImaginary1(){
     return imaginary1;
double getImaginary2(){
     return imaginary2;
double getsum1(){
     double sum1;
     return sum1;
double getsum2(){
     double sum2;
     return sum2;
double getdiff1(){
     double diff1;
     return diff1;
double getdiff2(){
     double diff2;
     return diff2;
void dispalymessage(){
     cout << "real sum:" << sum1;
     cout << "imaginary sum:" << sum2;
     cout << "real difference:" << diff1;
     cout << "imaginary difference:" << diff2;

     double real1, real2, imaginary1, imaginary2;

int main(){
     Complex x(12,10,11,5);
     cout << x.getReal1 << " " << x.getImaginary1 << " " << x.getReal2 << " " << x.getImaginary2 << " " << endl;
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

Member Avatar for jencas

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.

Member Avatar for iamthwee

[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.