52 lines
967 B
C++
52 lines
967 B
C++
#include <iostream>
|
|
|
|
class Complex {
|
|
protected:
|
|
int real, im;
|
|
|
|
public:
|
|
Complex();
|
|
Complex(int real, int im);
|
|
Complex(Complex &other);
|
|
|
|
void operator=(Complex &other);
|
|
Complex& operator+(Complex &other);
|
|
void display() {
|
|
std::cout << this->real << "+" << this->im << "i" << std::endl;
|
|
}
|
|
};
|
|
|
|
Complex::Complex() {
|
|
this->real = 0;
|
|
this->im = 0;
|
|
}
|
|
|
|
Complex::Complex(int newReal, int newIm) {
|
|
this->real = newReal;
|
|
this->im = newIm;
|
|
}
|
|
|
|
Complex::Complex(Complex &other) {
|
|
this->real = other.real;
|
|
this->im = other.im;
|
|
}
|
|
|
|
void Complex::operator=(Complex &other) {
|
|
this->real = other.real;
|
|
this->im = other.im;
|
|
}
|
|
|
|
Complex& Complex::operator+(Complex &other) {
|
|
Complex tmp(this->real + other.real, this->im + other.im);
|
|
return tmp;
|
|
}
|
|
|
|
int main() {
|
|
Complex i1(1,2);
|
|
Complex i2;
|
|
int a[3][5] = {0};
|
|
int (*ptr)[5] = (int(*)[5]) a[3];
|
|
i2 = i1 + i1;
|
|
i2.display();
|
|
return 0;
|
|
} |