Class c++

Hello guys :)
I hope you are having a great sunday!! :)
I have a c++ homework for tommorrow that i have been working on all day :/

Create a class called Complex for performing arithmetic with complex numbers. Complex numbers have the form: realPart + imaginaryPart * i
So, This class has two data members: realPart, imaginaryPart (your data members should be of type double)
Provide also the following member functions:
 A constructor with no arguments that initializes realPart and imaginaryPart to zero.
 An overloaded constructor with arguments.
 The “Norm” function that computes and returns the norm of a complex number:
The norm of realPart + imaginaryPart * i is
sqrt(realPart2 + imaginaryPart2)
 A “Print” function that prints on the screen a complex number as follows:
If realPart=2 and imaginaryPart=3 it should print: (2 + 3i )
 An “add” function that adds two complex numbers: the real parts are added together and the imaginary parts are added together. It will be used as follows:
Complex c(3,6);
Complex d(1,3);
Complex e;
e.add(c,d); // e should become (4,9) after this statement
Write a client program (main function) which creates objects of class Complex and test all your member functions.

here is my work:
but it is keeping giving errors!! :/ anyone can help me please? due date is tomorrow..

using namespace std;

class Complex {
double realPart ;
double imaginaryPart ;

Complex(){ realPart= imaginaryPart=0;

Complex(double realPart,double imaginaryPart) ;
double norm()
{ return sqrt(pow(realPart,2) + pow(imaginaryPart,2)); }
void Print()
{ cout<<realPart<<" + "<<imaginaryPart<<"i" ;}

void add(Complex c ,Complex d)
{ Complex e;
e.realPart=c.realPart +d.realPart ;
e.imaginaryPart=c.imaginaryPart + d.imaginaryPart ;
cout<< "e("<<e.realPart<<","<<e.imaginaryPart<<")"<<endl ; }

int main () {
Complex c(3,6);
Complex d(1,3);
Complex e ;
ThAnK You!! :D
Last edited on
One of the rules is don't post homework. If you have a specific question that prevents you from doing that homework, lets say syntax of something, then you can ask only that specific question. Not your entire assignment.

Also placing your code in [code] tags will be nice.
Topic archived. No new replies allowed.