Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "stdafx.h"
- #include <iostream>
- using namespace std;
- class Complex {
- private:
- int Re_;
- int Im_;
- public:
- Complex(int, int);
- int getRe();
- int getIm();
- void setRe(int);
- Complex();
- void setIm(int);
- Complex operator+(const Complex& right){
- Complex result;
- result.Re_ = this->Re_ + right.Re_;
- result.Im_ = this->Im_ + right.Im_;
- return result;
- }
- friend Complex operator-(const Complex&);
- friend ostream &operator<<(ostream &, const Complex &);
- };
- Complex::Complex( ) {
- Re_ = 0;
- Im_ = 0;
- }
- Complex::Complex(int re , int im){
- this->Im_ = im;
- this->Re_ = re;
- }
- int Complex::getRe() { return Re_; }
- int Complex::getIm() { return Im_; }
- void Complex::setRe(int Re) { Re_ = Re; }
- void Complex::setIm(int Im) { Im_ = Im; }
- /*
- Complex operator-(const Complex &right) {
- Complex result;
- result.Re_ = this->Re_ - right.Re_;
- result.Im_ = this->Im_ - right.Im_;
- return result;
- }
- */
- ostream &operator<<(ostream &out, const Complex &right) {
- out << "(" << right.Re_ << "," << right.Im_ << ")" << endl;
- return out;
- }
- int main() {
- Complex a(7, 10);
- Complex b(3, 2);
- Complex c = a.operator+(b);
- cout << c;
- system("pause");
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement