Introduction - If you have any usage issues, please Google them yourself
1, [] define a copy constructor complex class CComplex
class CComplex {
private:
float real // real part
float imag // imaginary part
public:
CComplex (float x = 0.0, float y = 0.0): real (x), imag (y) {}
CComplex (CComplex & c)
CComplex operator+ (CComplex & c)
CComplex operator-(CComplex & c)
void print () const {cout << real << "+" << imag << "i" << endl
}
void main () {
CComplex c1 (3, 5), c2 (4, 7)
CComplex c3 = c1+ c2
CComplex c4 = c2- c1
c4.print ()
c3.print ()
}
Please improve the copy constructor CComplex of operator overloading+ and- to complete the assigned functions.
2, [inheritance] square is a special case of a rectangle, define a square class (CSquare) and rectangular class (CRectangle), defined as the square class derived class rectangle class.
(1) having a rectangular perimeter calculation, the area of member functions
(2) as a sub-class also has