Advertisement
Guest User

Untitled

a guest
Jan 23rd, 2018
52
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.18 KB | None | 0 0
  1. #include "stdafx.h"
  2. #include <iostream>
  3. using namespace std;
  4.  
  5. class Complex {
  6. private:
  7. int Re_;
  8. int Im_;
  9. public:
  10. Complex(int, int);
  11. int getRe();
  12. int getIm();
  13. void setRe(int);
  14. Complex();
  15. void setIm(int);
  16. Complex operator+(const Complex& right){
  17. Complex result;
  18. result.Re_ = this->Re_ + right.Re_;
  19. result.Im_ = this->Im_ + right.Im_;
  20. return result;
  21. }
  22. friend Complex operator-(const Complex&);
  23. friend ostream &operator<<(ostream &, const Complex &);
  24.  
  25. };
  26.  
  27. Complex::Complex( ) {
  28. Re_ = 0;
  29. Im_ = 0;
  30. }
  31.  
  32. Complex::Complex(int re , int im){
  33. this->Im_ = im;
  34. this->Re_ = re;
  35. }
  36.  
  37. int Complex::getRe() { return Re_; }
  38. int Complex::getIm() { return Im_; }
  39. void Complex::setRe(int Re) { Re_ = Re; }
  40. void Complex::setIm(int Im) { Im_ = Im; }
  41.  
  42. /*
  43. Complex operator-(const Complex &right) {
  44. Complex result;
  45. result.Re_ = this->Re_ - right.Re_;
  46. result.Im_ = this->Im_ - right.Im_;
  47. return result;
  48. }
  49. */
  50. ostream &operator<<(ostream &out, const Complex &right) {
  51. out << "(" << right.Re_ << "," << right.Im_ << ")" << endl;
  52. return out;
  53. }
  54.  
  55. int main() {
  56. Complex a(7, 10);
  57. Complex b(3, 2);
  58. Complex c = a.operator+(b);
  59. cout << c;
  60. system("pause");
  61. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement