Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- struct complex {
- public:
- complex(float r, float i): re(r), im(i) {}
- complex() {}
- float getRe() const { return re; };
- float getIm() const { return im; };
- complex operator+(const complex& z) {
- return complex( re + z.getRe(), im + z.getIm());
- }
- friend std::ostream& operator<<(std::ostream& os, const complex& z) {
- os << z.getRe() << " + i*" << z.getIm();
- return os;
- }
- private:
- float re, im;
- };
- complex operator-(const complex& a, const complex& b) {
- return complex( a.getRe() - b.getRe(), a.getIm() - b.getIm());
- }
- std::istream& operator>>(std::istream& is, complex& z){
- // aici am realizat ca designul meu nu prea permite citirea directa
- float x, y; is >> x >> y;
- z = complex( x, y);
- return is;
- }
- int main() {
- complex a, b;
- std::cin >> a >> b;
- std::cout << ( a + b) << "\n"
- << ( a - b) << "\n";
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement