Plz I need the solution, I know I'm not supposed to be getting the solution with no effort but the due date of the assignment is tomorrow and i need help, and I am not that good.
1) Create a class Complex defining a complex number with different operations as follows:
A complex number is defined of a real number, an imaginary number a name and an
ID.
The class should provide methods for the following operations:
adding a complex number to itself
subtracting a complex number from itself
dividing itself with a complex number
multiplying a complex number to itself
printing out the complex number in the form of “Name(ID)=Real + iImaginary”
The attributes of the class should not be accessible outside the class except for the name which
should be available to everyone. The name of the object cannot be changed once initialized. As
for the rest of the data members, we should be able to read them and change their values. The ID
is unique, so 2 complex numbers cannot have the same id, it is an incremented number as shown
in the example below.
At all times during the main program, we should maintain a count of the number of objects
created.
Ex: Complex c1; //id=1
Complex c2; //id=2
Complex c3; //id=3
The name is a character
The mathematical operations should be defined as cascaded functions
All the getter functions should be constants
The printout member function should be defined outside the class
A complex number by default should be “name=1+I”
There should be only one constructor
When an object is destroyed, a message should be printed out
The number of instances created should be held within a private static variable which can
be read through a static getter member functionvariable which can
be read through a static getter member function
class Complex
{
private: // members // The attributes of the class should not be accessible outside the class
double real; // Real number
double imag; // Imaginary number
int id; // id
staticint created = 0; // At all times during the main program, we should maintain a count o the number of objects
public:
constchar name; // except for the name which should be available to everyone
public: // Constructors
Complex(char Name) : name(Name) // the name is constant
{
id = ++created; // it is an incremented number as shown in the example below
}
~Complex()
{
std::cout << "Complex destroyed";
}
public: // getters/setters // for the rest of the data members
constdouble GetReal() { return real; } // we should be able to read them and change their values
constdouble GetImag() { return imag; } //
constdouble GetID() { return id; }
void SetReal (double r) { real = r; }
void SetImag (double i) { imag = i; }
void SetID (int ID) { id = ID; }
public: // methods
voidoperator+=(const Complex& c) // adding a complex number to itself
{
real+=c.real;
imag+=c.imag;
}
voidoperator-=(const Complex& c) // subtracting a complex number from itself
{
real-=c.real;
imag-=c.imag;
}
voidoperator/=(const Complex& c) // dividing itself with a complex number
{
real/=c.real;
imag/=c.imag;
}
voidoperator*=(const Complex& c) // multiplying a complex number to itself
{
real*=c.real;
imag*=c.imag;
}
friend std::ostream& operator<< (std::ostream& o, const Complex& c);
};
std::ostream& operator<< (std::ostream& o, const Complex& c) // the printout function shall be declared outside of the class
{// printing out the complex number in the form of “Name(ID)=Real + iImaginary”
return o<< name << '(' << id << ")="<<real<<" + i"<<imag;
}
There were some ill-defined requirements here by the way.